Class DetachedPermazenTransaction
- All Implemented Interfaces:
Closeable
,AutoCloseable
PermazenTransaction
that is not actually connected to a Permazen
database instance, but instead exists
just to hold objects in memory.
DetachedPermazenTransaction
s are typically used to "snapshot" some portion of a normal PermazenTransaction
for later use. As with all transactions, each DetachedPermazenTransaction
contains its own object data.
For convenience, each PermazenTransaction
has a default, initially empty DetachedPermazenTransaction
instance
associated with it;
PermazenObject.copyOut()
copies objects there.
Because DetachedPermazenTransaction
s live indefinitely, their objects can be used just like normal Java objects,
outside of any regular transaction, yet all of the usual Permazen
features such as indexing, listeners,
validation, etc., continue to function normally.
Because they typically contain only a portion of the database's objects and therefore may have dangling references,
the referential integrity function of @PermazenField.allowDeleted()
is disabled in
DetachedPermazenTransaction
s.
Other Uses
More general usage beyond copies of regular transactions is possible: an empty DetachedPermazenTransaction
can be created
on the fly via PermazenTransaction.createDetachedTransaction()
and then
used as simple in-memory transaction workspace. The resulting key/value pairs could then be (de)serialized and sent over the
network; see for example PermazenObjectHttpMessageConverter
.
For KVDatabase
's that support it, using the key/value store snapshot returned by KVTransaction.readOnlySnapshot()
allows an efficient "copy" of the entire database into a DetachedPermazenTransaction
; see
Permazen.createSnapshotTransaction()
.
Lifecycle Management
Instances of this class should be close()
'd when no longer needed to release any associated resources.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this instance and release any resources associated with it.void
commit()
Commit this transaction.Get theDetachedTransaction
associated with this instance.final boolean
Determine whether this instance is aDetachedPermazenTransaction
.boolean
isOpen()
Determine whether this transaction is still valid.void
reset()
Delete all objects contained in this detached transaction and reset it back to its initial state.void
rollback()
Roll back this transaction.Methods inherited from class io.permazen.PermazenTransaction
cascade, copyTo, copyTo, create, create, createDetachedTransaction, createSnapshotTransaction, delete, exists, followReferencePath, get, get, get, getAll, getCurrent, getDetachedTransaction, getKey, getPermazen, getSingleton, getValidationMode, hasCurrent, invertReferencePath, migrateSchema, performAction, performAction, queryCompositeIndex, queryCompositeIndex, queryCompositeIndex, queryIndex, queryListElementIndex, queryMapValueIndex, querySchemaIndex, querySimpleIndex, readCounterField, readListField, readMapField, readSetField, readSimpleField, recreate, registerPermazenObject, resetValidationQueue, revalidate, setCurrent, validate, withWeakConsistency, writeSimpleField
-
Method Details
-
isDetached
public final boolean isDetached()Description copied from class:PermazenTransaction
Determine whether this instance is aDetachedPermazenTransaction
.- Overrides:
isDetached
in classPermazenTransaction
- Returns:
- true if this instance is a
DetachedPermazenTransaction
, otherwise false
-
getTransaction
Get theDetachedTransaction
associated with this instance.- Overrides:
getTransaction
in classPermazenTransaction
- Returns:
- the associated core API detached transaction
-
reset
public void reset()Delete all objects contained in this detached transaction and reset it back to its initial state.It will contain schema meta-data but no objects.
-
commit
public void commit()Commit this transaction.DetachedPermazenTransaction
s do not support this method and will always throwUnsupportedOperationException
.- Overrides:
commit
in classPermazenTransaction
- Throws:
UnsupportedOperationException
- always
-
rollback
public void rollback()Roll back this transaction.DetachedPermazenTransaction
s do not support this method and will always throwUnsupportedOperationException
.- Overrides:
rollback
in classPermazenTransaction
- Throws:
UnsupportedOperationException
- always
-
isOpen
public boolean isOpen()Determine whether this transaction is still valid.DetachedPermazenTransaction
s are always valid.- Overrides:
isOpen
in classPermazenTransaction
- Returns:
- true always
- See Also:
-
close
public void close()Close this instance and release any resources associated with it.The implementation in
DetachedPermazenTransaction
s closes the underlyingDetachedTransaction
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
-