Skip to content
Permalink
Browse files

Make SnapshotJTransaction and SnapshotTransaction implement Closeable.

  • Loading branch information
archiecobbs committed Nov 19, 2019
1 parent 0c9b33a commit 333e046caea448693ec08227847a10be7ddce014
@@ -1,5 +1,6 @@
Version Next

- SnapshotJTransaction and SnapshotTransaction now implement Closeable
- Added new key/value implementation based on MVStore (issue #34)
- Added method NavigableSetPager.getPageNumber()
- Added convenience method NavigableSetPager.reverseViewOrdering()
@@ -322,6 +322,10 @@ public Transaction createTransaction(KVTransaction kvt, SchemaModel schemaModel,
* {@link SnapshotTransaction#rollback rollback()}, or {@link SnapshotTransaction#addCallback addCallback()},
* and can be used indefinitely.
*
* <p>
* If {@code kvstore} is a {@link io.permazen.kv.CloseableKVStore}, then it will be
* {@link io.permazen.kv.CloseableKVStore#close close()}'d if/when the returned {@link SnapshotTransaction} is.
*
* @param kvstore key/value store, empty or having content compatible with this transaction's {@link Database}
* @param schemaModel schema to use with the new transaction, or null to use the schema already recorded in the database
* @param version the schema version number corresponding to {@code schemaModel},
@@ -5,8 +5,11 @@

package io.permazen.core;

import io.permazen.kv.CloseableKVStore;
import io.permazen.kv.KVStore;

import java.io.Closeable;

/**
* A "snapshot" {@link Transaction} that persists indefinitely.
*
@@ -26,7 +29,7 @@
* @see Database#createSnapshotTransaction Database.createSnapshotTransaction()
* @see io.permazen.SnapshotJTransaction
*/
public class SnapshotTransaction extends Transaction {
public class SnapshotTransaction extends Transaction implements Closeable {

// Constructors

@@ -119,5 +122,20 @@ public void addCallback(Callback callback) {
public boolean isValid() {
return super.isValid();
}
}

// Closeable

/**
* Close this instance and release any resources associated with it.
*
* <p>
* The implementation in {@link SnapshotTransaction} closes the underlying {@link KVStore} if it is
* a {@link CloseableKVStore}, otherwise it does nothing.
*/
@Override
public void close() {
final KVStore kvstore = this.getKVStore();
if (kvstore instanceof CloseableKVStore)
((CloseableKVStore)kvstore).close();
}
}
@@ -694,6 +694,10 @@ public SnapshotJTransaction createSnapshotTransaction(ValidationMode validationM
* The returned {@link SnapshotJTransaction} does not support {@link SnapshotJTransaction#commit commit()} or
* {@link SnapshotJTransaction#rollback rollback()}, and can be used indefinitely.
*
* <p>
* If {@code kvstore} is a {@link io.permazen.kv.CloseableKVStore}, then it will be
* {@link io.permazen.kv.CloseableKVStore#close close()}'d if/when the returned {@link SnapshotJTransaction} is.
*
* @param kvstore key/value store, empty or having content compatible with this transaction's {@link Permazen}
* @param allowNewSchema whether creating a new schema version in {@code kvstore} is allowed
* @param validationMode the {@link ValidationMode} to use for the snapshot transaction
@@ -7,6 +7,8 @@

import io.permazen.core.SnapshotTransaction;

import java.io.Closeable;

/**
* A "snapshot" {@link JTransaction} that persists indefinitely.
*
@@ -31,7 +33,7 @@
* @see Permazen#createSnapshotTransaction Permazen.createSnapshotTransaction()
* @see io.permazen.core.SnapshotTransaction
*/
public class SnapshotJTransaction extends JTransaction {
public class SnapshotJTransaction extends JTransaction implements Closeable {

SnapshotJTransaction(Permazen jdb, SnapshotTransaction tx, ValidationMode validationMode) {
super(jdb, tx, validationMode);
@@ -101,5 +103,19 @@ public void rollback() {
public boolean isValid() {
return true;
}
}

// Closeable

/**
* Close this instance and release any resources associated with it.
*
* <p>
* The implementation in {@link SnapshotJTransaction}s closes the underlying {@link SnapshotTransaction}.
*
* @see SnapshotTransaction#close
*/
@Override
public void close() {
((SnapshotTransaction)this.tx).close();
}
}

0 comments on commit 333e046

Please sign in to comment.
You can’t perform that action at this time.