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.
DetachedTransaction
s 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.
DetachedTransaction
s cannot be committed or rolled-back; they just persist in memory until
no longer needed. Transaction.Callback
s may be registered, but they will never be invoked.
DetachedTransaction
s 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 TypeMethodDescriptionvoid
addCallback
(Transaction.Callback callback) Register a transaction callback to be invoked when this transaction completes.void
close()
Close this instance and release any resources associated with it.void
commit()
Commit this transaction.Get the underlyingKVStore
that holds this detached transaction's state.boolean
Determine whether this instance is aDetachedTransaction
.boolean
isOpen()
Determine whether this transaction is still open.void
reset()
Delete all objects contained in this detached transaction.void
rollback()
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:Transaction
Determine whether this instance is aDetachedTransaction
.- Overrides:
isDetached
in classTransaction
- Returns:
- true if this instance is a
DetachedTransaction
, otherwise false
-
getKVStore
Get the underlyingKVStore
that 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.DetachedTransaction
s do not support this method and will always throwUnsupportedOperationException
.- Overrides:
commit
in classTransaction
- Throws:
UnsupportedOperationException
- always
-
rollback
public void rollback()Roll back this transaction.DetachedTransaction
s do not support this method and will always throwUnsupportedOperationException
.- Overrides:
rollback
in classTransaction
- Throws:
UnsupportedOperationException
- always
-
addCallback
Register a transaction callback to be invoked when this transaction completes.Transaction.Callback
s registered with aDetachedTransaction
will by definition never be invoked. Therefore, this method simply discardscallback
.- Overrides:
addCallback
in classTransaction
- Parameters:
callback
- callback to invoke
-
isOpen
public boolean isOpen()Determine whether this transaction is still open.DetachedTransaction
s are always open.- Overrides:
isOpen
in classTransaction
- Returns:
- true always
-
close
public void close()Close this instance and release any resources associated with it.The implementation in
DetachedTransaction
closes the underlyingKVStore
if it is aCloseableKVStore
, otherwise it does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-