Class DetachedTransaction
- All Implemented Interfaces:
Closeable,AutoCloseable
Transaction that is not actually connected to a persistent database, but instead exists
just to hold objects in memory.
DetachedTransactions are typically used to hold a "snapshot" some portion of a normal Transaction
for later use. As with all transactions, each DetachedTransaction contains its own object data.
DetachedTransactions cannot be committed or rolled-back; they just persist in memory until
no longer needed. Transaction.Callbacks may be registered, but they will never be invoked.
DetachedTransactions can be based on an arbitrary KVStore;
see Database.createDetachedTransaction().
Lifecycle Management
Instances of this class should be close()'d when no longer needed to release any associated resources.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.permazen.core.Transaction
Transaction.Callback, Transaction.CallbackAdapter, Transaction.ListenerSet -
Field Summary
Fields inherited from class io.permazen.core.Transaction
log -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCallback(Transaction.Callback callback) Register a transaction callback to be invoked when this transaction completes.voidclose()Close this instance and release any resources associated with it.voidcommit()Commit this transaction.Get the underlyingKVStorethat holds this detached transaction's state.booleanDetermine whether this instance is aDetachedTransaction.booleanisOpen()Determine whether this transaction is still open.voidreset()Delete all objects contained in this detached transaction.voidrollback()Roll back this transaction.Methods inherited from class io.permazen.core.Transaction
addCreateListener, addDeleteListener, addFieldChangeListener, addListFieldChangeListener, addMapFieldChangeListener, addSchema, addSchemaChangeListener, addSetFieldChangeListener, addSimpleFieldChangeListener, adjustCounterField, copy, create, create, create, create, createDetachedTransaction, createSnapshotTransaction, delete, exists, followReferencePath, generateId, getAll, getAll, getDatabase, getFieldDescription, getKey, getKVTransaction, getObjDescription, getObjType, getSchema, getSchemaBundle, getTypeDescription, getTypeName, getUserObject, invertReferencePath, isReadOnly, isRollbackOnly, migrateSchema, queryCompositeIndex2, queryCompositeIndex3, queryCompositeIndex4, queryIndex, queryListElementIndex, queryMapValueIndex, querySchemaIndex, querySimpleIndex, readCounterField, readListField, readMapField, readSetField, readSimpleField, removeCreateListener, removeDeleteListener, removeFieldChangeListener, removeListFieldChangeListener, removeMapFieldChangeListener, removeSchema, removeSchemaChangeListener, removeSetFieldChangeListener, removeSimpleFieldChangeListener, setListeners, setReadOnly, setRollbackOnly, setTimeout, setUserObject, snapshotListeners, withWeakConsistency, writeCounterField, writeSimpleField
-
Method Details
-
isDetached
public boolean isDetached()Description copied from class:TransactionDetermine whether this instance is aDetachedTransaction.- Overrides:
isDetachedin classTransaction- Returns:
- true if this instance is a
DetachedTransaction, otherwise false
-
getKVStore
Get the underlyingKVStorethat holds this detached transaction's state.- Returns:
- underlying
KVStore
-
reset
public void reset()Delete all objects contained in this detached transaction.Upon return, the underlying key/value store will still contain meta-data, but no objects.
-
commit
public void commit()Commit this transaction.DetachedTransactions do not support this method and will always throwUnsupportedOperationException.- Overrides:
commitin classTransaction- Throws:
UnsupportedOperationException- always
-
rollback
public void rollback()Roll back this transaction.DetachedTransactions do not support this method and will always throwUnsupportedOperationException.- Overrides:
rollbackin classTransaction- Throws:
UnsupportedOperationException- always
-
addCallback
Register a transaction callback to be invoked when this transaction completes.Transaction.Callbacks registered with aDetachedTransactionwill by definition never be invoked. Therefore, this method simply discardscallback.- Overrides:
addCallbackin classTransaction- Parameters:
callback- callback to invoke
-
isOpen
public boolean isOpen()Determine whether this transaction is still open.DetachedTransactions are always open.- Overrides:
isOpenin classTransaction- Returns:
- true always
-
close
public void close()Close this instance and release any resources associated with it.The implementation in
DetachedTransactioncloses the underlyingKVStoreif it is aCloseableKVStore, otherwise it does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-