Package io.permazen

Class DetachedPermazenTransaction

java.lang.Object
io.permazen.PermazenTransaction
io.permazen.DetachedPermazenTransaction
All Implemented Interfaces:
Closeable, AutoCloseable

public class DetachedPermazenTransaction extends PermazenTransaction implements Closeable
A PermazenTransaction that is not actually connected to a Permazen database instance, but instead exists just to hold objects in memory.

DetachedPermazenTransactions 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 DetachedPermazenTransactions 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 DetachedPermazenTransactions.

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.

See Also: