All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jsimpledb.kv.raft.fallback.OverwriteMergeStrategy Maven / Gradle / Ivy

Go to download

JSimpleDB distributed, linearizable ACID compliant key/value store implementation based on the Raft consensus algorithm.

There is a newer version: 3.6.1
Show newest version

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package org.jsimpledb.kv.raft.fallback;

import java.util.Date;
import java.util.Iterator;

import org.jsimpledb.kv.KVPair;
import org.jsimpledb.kv.KVTransaction;

/**
 * {@link MergeStrategy} that completely overwrites the destination database with the content of the source database.
 */
public class OverwriteMergeStrategy implements MergeStrategy {

    @Override
    public void merge(KVTransaction src, KVTransaction dst, Date lastActiveTime) {
        dst.removeRange(null, null);
        final Iterator i = src.getRange(null, null, false);
        while (i.hasNext()) {
            final KVPair pair = i.next();
            dst.put(pair.getKey(), pair.getValue());
        }
        try {
            ((AutoCloseable)i).close();
        } catch (Exception e) {
            // ignore
        }
    }

    @Override
    public String toString() {
        return "Overwrite";
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy