/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  See the NOTICE file distributed with this work for additional
 *  information regarding copyright ownership.
 */

package org.seaborne.delta.server.local.patchstores.mem;

import java.util.Collections;
import java.util.List;

import org.seaborne.delta.DataSourceDescription;
import org.seaborne.delta.server.local.LocalServerConfig;
import org.seaborne.delta.server.local.PatchLog;
import org.seaborne.delta.server.local.PatchStore;
import org.seaborne.delta.server.local.PatchStoreProvider;
import org.seaborne.delta.server.local.patchstores.PatchLogBase;
import org.seaborne.delta.server.local.patchstores.PatchLogIndex;
import org.seaborne.delta.server.local.patchstores.PatchStorage;

/**
 * In-memory, ephemeral {@link PatchStore}.
 * All the work is done in
 * {@link PatchLogIndexMem} and {@link PatchStorageMem}.
 */
public class PatchStoreMem extends PatchStore {

    public PatchStoreMem(PatchStoreProvider provider) {
        super(provider);
    }

    @Override
    protected void delete(PatchLog patchLog) {}

    @Override
    public List<DataSourceDescription> initialDataSources() {
        return Collections.emptyList();
    }

    @Override
    protected void initialize(LocalServerConfig config) {}

    @Override
    protected PatchLog newPatchLog(DataSourceDescription dsd) {
        return newPatchLogFromIndexAndStorage(dsd);
    }

    @Override
    public PatchLogIndex newPatchLogIndex(DataSourceDescription dsd, PatchStore patchStore, LocalServerConfig configuration) {
        return new PatchLogIndexMem();
    }

    @Override
    public PatchStorage newPatchStorage(DataSourceDescription dsd, PatchStore patchStore, LocalServerConfig configuration) {
        return new PatchStorageMem();
    }

    @Override
    protected void shutdownSub() {}

    @Override
    protected PatchLog renamePatchLog(PatchLog patchLog, String oldName, String newName) {
        // No need to copy. Retain id and URI.
        DataSourceDescription dsd0 = patchLog.getDescription();
        DataSourceDescription dsd = new DataSourceDescription(dsd0.getId(), newName, dsd0.getUri());
        PatchLogBase plb = (PatchLogBase)patchLog;
        return new PatchLogBase(dsd, plb.getPatchLogIndex(), plb.getPatchLogStorage(), plb.getPatchStore());
    }
}

@@ -842,16 +842,46 @@
 iption;%0A
+import org.seaborne.delta.Id;%0A
 import o
@@ -2374,24 +2374,26 @@
 wnSub() %7B%7D%0A%0A
+%0A%0A
     @Overrid
@@ -2497,111 +2497,306 @@
     
-// No need to copy. Retain id and URI.%0A        DataSourceDescription dsd0 = patchLog.getDescription
+DataSourceDescription dsd1 = patchLog.getDescription();%0A        Id dsRef2;%0A%0A        if ( false )%0A            // No need to copy. Retain id and URI.%0A            dsRef2 = dsd1.getId();%0A        else%0A            // Simulate other store that do rename as copy-delete.%0A            dsRef2 = Id.create
 ();%0A
+%0A
     
@@ -2824,16 +2824,17 @@
 tion dsd
+2
  = new D
@@ -2860,18 +2860,12 @@
 n(ds
-d0.getId()
+Ref2
 , ne
@@ -2874,17 +2874,17 @@
 ame, dsd
-0
+1
 .getUri(
@@ -2938,16 +2938,16 @@
 tchLog;%0A
-
         
@@ -2973,16 +2973,17 @@
 Base(dsd
+2
 , plb.ge

Allow same or new id