public class SnapshotJTransaction extends JTransaction implements Closeable
JTransaction
that persists indefinitely.
The purpose of SnapshotJTransaction
s is to hold a "snapshot" some portion of the state of a parent JTransaction
for later use after the parent transaction closes. Each SnapshotJTransaction
contains its own set of "snapshot"
JObject
s that are (usually) copies of the corresponding "real" database JObject
s. A SnapshotJTransaction
has the same schema as its parent JTransaction
.
For convenience, each JTransaction
has a default SnapshotJTransaction
instance
associated with it; JObject.copyOut()
copies objects there.
Because SnapshotJTransaction
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.
Other Uses
More general usage beyond snapshots of regular transactions is possible: an empty SnapshotJTransaction
can be created
on the fly via JTransaction.createSnapshotTransaction()
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 JObjectHttpMessageConverter
.
For KVDatabase
's that support it, using the key/value store snapshot returned by
KVTransaction.mutableSnapshot()
allows an efficient "copy" of the entire database into a
SnapshotJTransaction
using
Permazen.createSnapshotTransaction()
.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this instance and release any resources associated with it.
|
void |
commit()
Commit this transaction.
|
SnapshotTransaction |
getTransaction()
Get the
SnapshotTransaction associated with this instance. |
boolean |
isSnapshot()
Determine whether this instance is a
SnapshotJTransaction . |
boolean |
isValid()
Determine whether this transaction is still valid.
|
void |
reset()
Delete all objects contained in this snapshot transaction and reset it back to its initial state.
|
void |
rollback()
Roll back this transaction.
|
cascadeFindAll, cascadeFindAll, copyTo, copyTo, copyTo, copyTo, create, create, createClones, createSnapshotTransaction, delete, exists, followReferencePath, get, get, get, getAll, getCurrent, getKey, getKey, getPermazen, getSchemaVersion, getSnapshotTransaction, getValidationMode, invertReferencePath, performAction, queryCompositeIndex, queryCompositeIndex, queryCompositeIndex, queryIndex, queryIndex, queryListElementIndex, queryMapValueIndex, queryVersion, readCounterField, readListField, readMapField, readSetField, readSimpleField, recreate, registerJObject, resetValidationQueue, revalidate, setCurrent, updateSchemaVersion, validate, weakConsistency, writeSimpleField
public boolean isSnapshot()
JTransaction
SnapshotJTransaction
.isSnapshot
in class JTransaction
SnapshotJTransaction
, otherwise falsepublic SnapshotTransaction getTransaction()
SnapshotTransaction
associated with this instance.getTransaction
in class JTransaction
public void reset()
It will contain schema meta-data but no objects.
public void commit()
SnapshotJTransaction
s do not support this method and will always throw UnsupportedOperationException
.
commit
in class JTransaction
UnsupportedOperationException
- alwayspublic void rollback()
SnapshotJTransaction
s do not support this method and will always throw UnsupportedOperationException
.
rollback
in class JTransaction
UnsupportedOperationException
- alwayspublic boolean isValid()
SnapshotJTransaction
s are always valid.
isValid
in class JTransaction
Transaction.isValid()
public void close()
The implementation in SnapshotJTransaction
s closes the underlying SnapshotTransaction
.
close
in interface Closeable
close
in interface AutoCloseable
SnapshotTransaction.close()
Copyright © 2022. All rights reserved.