Class PermazenTransaction
- Direct Known Subclasses:
DetachedPermazenTransaction
Permazen
instance.
Commonly used methods in this class can be divided into the following categories:
Transaction Meta-Data
getPermazen()
- Get the associatedPermazen
instancegetTransaction()
- Get the core APITransaction
underlying this instance
Transaction Lifecycle
commit()
- Commit transactionrollback()
- Roll back transactiongetCurrent()
- Get thePermazenTransaction
instance associated with the current threadsetCurrent()
- Set thePermazenTransaction
instance associated with the current threadisOpen()
- Test whether transaction is still openperformAction()
- Perform action with this instance as the current transaction
Object Access
get()
- Get the Java model object in this transaction corresponding to a specific database object IDgetSingleton()
- Get a singleton instance in this transaction, creating it on demand if neededgetAll()
- Get all Java model objects in this transaction that are instances of a given Java typecreate()
- Create a new Java model object in this transactioncascade()
- Find all objects reachable through a reference cascade
Copying Objects
copyTo()
- Copy aStream
of objects into another transactionImportContext
- Import plain (POJO) model objectsExportContext
- Export plain (POJO) model objects
Validation
validate()
- Validate objects in the validation queueresetValidationQueue()
- Clear the validation queue
Index Queries
querySimpleIndex()
- Access the index associated with a simple fieldqueryListElementIndex()
- Access the composite index associated with a list field that includes corresponding list indicesqueryMapValueIndex()
- Access the composite index associated with a map value field that includes corresponding map keysqueryCompositeIndex()
- Access a composite index defined on two fieldsqueryCompositeIndex()
- Access a composite index defined on three fieldsqueryCompositeIndex()
- Access a composite index defined on four fieldsquerySchemaIndex()
- Get database objects grouped by schema
Reference Paths
followReferencePath()
- Find all objects reachable by traversing aReferencePath
invertReferencePath()
- Find all objects reachable by traversing aReferencePath
in the reverse direction
Detached Transactions
getDetachedTransaction()
- Get the default in-memory detached transaction associated with this regular transactioncreateDetachedTransaction()
- Create a new in-memory detached transactioncreateSnapshotTransaction()
- Create a new in-memory detached transaction pre-populated with a snapshot of this transactionisDetached()
- Determine whether this transaction is a detached transaction
Lower Layer Access
getKey()
- Get theKVDatabase
key prefix for an objectPermazenField.getKey()
- Get theKVDatabase
key for one field in an objectwithWeakConsistency()
- Perform an operation with weaker transaction consistency
The remaining methods in this class are normally only used by generated Java model object subclasses.
Instead of using these methods directly, using the appropriately annotated Java model object method
or PermazenObject
interface method is recommended.
Java Model Object Methods
readSimpleField()
- Read the value of a simple fieldwriteSimpleField()
- Write the value of a simple fieldreadCounterField()
- Access aCounter
fieldreadSetField()
- Access a set fieldreadListField()
- Access a list fieldreadMapField()
- Access a map fieldregisterPermazenObject()
- Ensure aPermazenObject
is registered in the internal object cache
PermazenObject
Methods
delete()
- Delete an object from this transactionexists()
- Test whether an object exists in this transactionrecreate()
- Recreate an object in this transactionrevalidate()
- Manually add an object to the validation queuemigrateSchema()
- Migrate an object's schema to match this transaction's data model
-
Method Summary
Modifier and TypeMethodDescriptionFind all objects reachable through the specified reference cascades.void
commit()
Commit this transaction.void
copyTo
(PermazenTransaction dest, CopyState copyState, ObjIdSet ids) Copy the specified objects into the specified destination transaction.void
copyTo
(PermazenTransaction dest, CopyState copyState, Stream<? extends PermazenObject> pobjs) Copy the specified objects into the specified destination transaction.<T> T
create
(PermazenClass<T> pclass) Create a new instance of the given type in this transaction.<T> T
Create a new instance of the given model class in this transaction.createDetachedTransaction
(ValidationMode validationMode) Create a new, empty detached transaction.createSnapshotTransaction
(ValidationMode validationMode) Create a new detached transaction pre-populated with a snapshot of this transaction.boolean
delete
(PermazenObject pobj) Delete the object with the given object ID in this transaction.boolean
Determine whether the object with the given object ID exists in this transaction.followReferencePath
(ReferencePath path, Stream<? extends PermazenObject> startObjects) Find all target objects that are reachable from the given starting object set through the specifiedReferencePath
.Get the Java model object that is associated with this transaction and has the given ID.<T> T
Get the Java model object that is associated with this transaction and has the given ID, cast to the given type.<T extends PermazenObject>
Tget
(T pobj) Get the Java model object with the same object ID as the givenPermazenObject
and whose state derives from this transaction.<T> NavigableSet<T>
Get all instances of the given type.static PermazenTransaction
Get thePermazenTransaction
associated with the current thread, if any, otherwise throw an exception.Get the defaultDetachedPermazenTransaction
associated with this instance.byte[]
getKey
(PermazenObject pobj) Get thebyte[]
key in the underlying key/value store corresponding to the specified object.Get thePermazen
associated with this instance.<T> T
getSingleton
(Class<T> type) Get the singleton instance of the given type, creating it on demand if needed.Get theTransaction
associated with this instance.Get theValidationMode
configured for this instance.static boolean
Determine if there is aPermazenTransaction
associated with the current thread.invertReferencePath
(ReferencePath path, Stream<? extends PermazenObject> targetObjects) Find all starting objects that refer to any object in the given target set through the specifiedReferencePath
.boolean
Determine whether this instance is aDetachedPermazenTransaction
.boolean
isOpen()
Determine whether this transaction is still usable.boolean
migrateSchema
(PermazenObject pobj) Update the schema of the specified object, if necessary, so that it matches the schema associated with this instance'sPermazen
.void
performAction
(Runnable action) Invoke the givenRunnable
with this instance as the current transaction.<T> T
performAction
(Supplier<T> action) Invoke the givenSupplier
with this instance as the current transaction.<V1,
V2, T> Index2<V1, V2, T> queryCompositeIndex
(Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type) Access a composite index on two fields.<V1,
V2, V3, T>
Index3<V1,V2, V3, T> queryCompositeIndex
(Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type, Class<V3> value3Type) Access a composite index on three fields.<V1,
V2, V3, V4, T>
Index4<V1,V2, V3, V4, T> queryCompositeIndex
(Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type, Class<V3> value3Type, Class<V4> value4Type) Access a composite index on four fields.Index<?>
queryIndex
(int storageId) Query an index by storage ID.queryListElementIndex
(Class<T> targetType, String fieldName, Class<V> valueType) Get the composite index on a list field that includes list indices.<V,
T, K> Index2<V, T, K> queryMapValueIndex
(Class<T> targetType, String fieldName, Class<V> valueType, Class<K> keyType) Get the composite index on a map value field that includes map keys.<T> NavigableMap<SchemaId,
NavigableSet<T>> querySchemaIndex
(Class<T> type) Get all instances of the given type, grouped according to schema index.<V,
T> Index1<V, T> querySimpleIndex
(Class<T> targetType, String fieldName, Class<V> valueType) Get the index on a simple field.readCounterField
(ObjId id, String fieldName, boolean migrateSchema) Read a counter field.List<?>
readListField
(ObjId id, String fieldName, boolean migrateSchema) Read a list field.NavigableMap<?,
?> readMapField
(ObjId id, String fieldName, boolean migrateSchema) Read a map field.NavigableSet<?>
readSetField
(ObjId id, String fieldName, boolean migrateSchema) Read a set field.readSimpleField
(ObjId id, String fieldName, boolean migrateSchema) Read a simple field.boolean
recreate
(PermazenObject pobj) Recreate the given instance in this transaction.static void
Ensure the givenPermazenObject
is registered in its associated transaction's object cache.void
Clear the validation queue associated with this transaction.void
revalidate
(ObjId id, Class<?>... groups) Add the given instance to the validation queue for validation, which will occur either atcommit()
time or at the next invocation ofvalidate()
, whichever occurs first.void
rollback()
Roll back this transaction.static void
Set thePermazenTransaction
associated with the current thread.void
validate()
Perform validation checks on all objects currently in the validation queue.void
withWeakConsistency
(Runnable action) Apply weaker transaction consistency while performing the given action, if supported.void
writeSimpleField
(PermazenObject pobj, String fieldName, Object value, boolean migrateSchema) Write a simple field.
-
Method Details
-
getCurrent
Get thePermazenTransaction
associated with the current thread, if any, otherwise throw an exception.- Returns:
- instance previously associated with the current thread via
setCurrent()
- Throws:
IllegalStateException
- if there is no such instance
-
setCurrent
Set thePermazenTransaction
associated with the current thread.- Parameters:
ptx
- transaction to associate with the current thread
-
hasCurrent
public static boolean hasCurrent()Determine if there is aPermazenTransaction
associated with the current thread.- Returns:
- true if there is a current
PermazenTransaction
, otherwise false
-
getPermazen
Get thePermazen
associated with this instance.- Returns:
- the associated database
-
getTransaction
Get theTransaction
associated with this instance.- Returns:
- the associated core API transaction
-
getValidationMode
Get theValidationMode
configured for this instance.- Returns:
- the configured validation mode
-
getAll
Get all instances of the given type.The returned set includes objects from all schemas. Use
querySchemaIndex()
to find objects with a specific schema.The returned set is mutable, with the exception that
add()
is not supported. Deleting an element results in deleting the corresponding object.- Type Parameters:
T
- containing Java type- Parameters:
type
- any Java type; useObject.class
to return all database objects- Returns:
- a live view of all instances of
type
- Throws:
IllegalArgumentException
- iftype
is nullStaleTransactionException
- if this transaction is no longer usable
-
getSingleton
Get the singleton instance of the given type, creating it on demand if needed.This is a convenience method for accessing the singleton instances of any type annotated with
@PermazenType
(singleton = true)
. Iftype
is not a singleton type, an exception is thrown.If no instance exists yet, one is created. So this method is essentially shorthand for:
try { return this.getAll(type).first(); } catch (NoSuchElementException e) { return this.create(type); }
- Type Parameters:
T
- singleton type- Parameters:
type
- singleton model class- Returns:
- the singleton instance of type
type
- Throws:
IllegalArgumentException
- iftype
is not a singleton typeIllegalArgumentException
- iftype
is nullStaleTransactionException
- if this transaction is no longer usable- See Also:
-
querySchemaIndex
Get all instances of the given type, grouped according to schema index.- Type Parameters:
T
- containing Java type- Parameters:
type
- any Java type; useObject.class
to return all database objects- Returns:
- live, read-only mapping from
SchemaId
to objects having that schema - Throws:
IllegalArgumentException
- iftype
is nullStaleTransactionException
- if this transaction is no longer usable
-
getKey
Get thebyte[]
key in the underlying key/value store corresponding to the specified object.Notes:
- Objects utilize multiple keys; the return value is the common prefix of all such keys.
- The
KVDatabase
should not be modified directly, otherwise behavior is undefined
- Parameters:
pobj
- Java model object- Returns:
- the
KVDatabase
key corresponding topobj
- Throws:
IllegalArgumentException
- ifpobj
is null- See Also:
-
isDetached
public boolean isDetached()Determine whether this instance is aDetachedPermazenTransaction
.- Returns:
- true if this instance is a
DetachedPermazenTransaction
, otherwise false
-
getDetachedTransaction
Get the defaultDetachedPermazenTransaction
associated with this instance.The default
DetachedPermazenTransaction
usesValidationMode.MANUAL
.This instance must not itself be a
DetachedPermazenTransaction
; usecreateDetachedTransaction()
to create additional detached transactions.- Returns:
- the associated detached transaction
- Throws:
IllegalArgumentException
- if this instance is itself aDetachedPermazenTransaction
- See Also:
-
createDetachedTransaction
Create a new, empty detached transaction.The returned transaction will have the same schema meta-data as this instance. It will be a mutable transaction, but being detached, changes can't be committed.
The returned
DetachedPermazenTransaction
does not supportcommit()
orrollback()
. It can be used indefinitely after this transaction closes, but it must beclose()
'd when no longer needed to release any associated resources.- Parameters:
validationMode
- theValidationMode
to use for the new transaction- Returns:
- newly created detached transaction
- Throws:
IllegalArgumentException
- ifvalidationMode
is nullStaleTransactionException
- if this instance is no longer usable
-
createSnapshotTransaction
Create a new detached transaction pre-populated with a snapshot of this transaction.The returned transaction will have the same schema meta-data and object content as this instance. It will be a mutable transaction, but being detached, changes can't be committed.
The returned
DetachedPermazenTransaction
does not supportcommit()
orrollback()
. It can be used indefinitely after this transaction closes, but it must beclose()
'd when no longer needed to release any associated resources.This method requires the underlying key/value transaction to support
KVTransaction.readOnlySnapshot()
. As with any other information extracted from this transaction, the returned content is not guaranteed to be valid until this transaction has been successfully committed.- Parameters:
validationMode
- theValidationMode
to use for the new transaction- Returns:
- newly created detached transaction
- Throws:
IllegalArgumentException
- ifvalidationMode
is nullUnsupportedOperationException
- if they underlying key/value transaction doesn't supportKVTransaction.readOnlySnapshot()
StaleTransactionException
- if this instance is no longer usable
-
copyTo
Copy the specified objects into the specified destination transaction.This is a convenience method; equivalent to
copyTo(PermazenTransaction, CopyState, Stream)
} but with the objects specified by object ID.- Parameters:
dest
- destination transactioncopyState
- tracks which objects have already been copied and whether to remap object ID'sids
- the object ID's of the objects to copy- Throws:
DeletedObjectException
- if any object to be copied does not actually existDeletedObjectException
- if any copied object ends up with a reference to an object that does not exist indest
through a reference field configured to disallow deleted assignmentSchemaMismatchException
- if the schema corresponding to any copied object is not identical in both this instance anddest
StaleTransactionException
- if this transaction ordest
is no longer usableIllegalArgumentException
- if any parameter is null
-
copyTo
public void copyTo(PermazenTransaction dest, CopyState copyState, Stream<? extends PermazenObject> pobjs) Copy the specified objects into the specified destination transaction.If a target object does not exist, it will be created, otherwise its schema will be migrated to match the source object if necessary (with resulting
@OnSchemaChange
notifications). IfCopyState.isSuppressNotifications()
returns false,@OnCreate
and@OnChange
notifications will also be delivered.The
copyState
tracks which objects have already been copied. For a "fresh" copy operation, pass a newly createdCopyState
; for a copy operation that is a continuation of a previous copy, reuse the previousCopyState
. TheCopyState
may also be configured to remap object ID's.This instance and
dest
must be compatible in that for any schemas encountered, those schemas must be identical in both transactions.If
dest
is not aDetachedPermazenTransaction
and any copied objects contain reference fields configured withPermazenField.allowDeleted()
= false
, then any objects referenced by those fields must also be copied, or else must already exist indest
. Otherwise, aDeletedObjectException
is thrown and it is indeterminate which objects were copied.Note: if two threads attempt to copy objects between the same two transactions at the same time but in opposite directions, deadlock could result.
- Parameters:
dest
- destination transactionpobjs
- the objects to copy; null values are ignoredcopyState
- tracks which objects have already been copied and whether to remap object ID's- Throws:
DeletedObjectException
- if any object to be copied does not actually existDeletedObjectException
- if any copied object ends up with a reference to an object that does not exist indest
through a reference field configured to disallow deleted assignmentUnknownTypeException
- if any source object's type does not exist indest
SchemaMismatchException
- if the schema corresponding to any copied object is not identical in both this instance anddest
StaleTransactionException
- if this transaction ordest
is no longer usableIllegalArgumentException
- if any parameter is null
-
cascade
Find all objects reachable through the specified reference cascades.This method finds all objects reachable from the given starting object through forward and inverse reference field cascades with the specified names. In other words, a reference field is traversed in the forward or inverse direction if any of the given
cascades
are found in the field's @PermazenField.forwardCascades() or @PermazenField.inverseCascades() annotation property, respectively.The
visited
set contains the ID's of objects already visited (or is empty if none); these objects will not be traversed. In particular, ifid
is invisited
, then this method does nothing. Upon return,visited
will have had all of the new objects found added.All new objects found will be migrated to the this transaction's schema if necessary.
The
maxDistance
parameter can be used to limit the maximum distance of any reachable object, measured in the number of reference field hops from the starting object. If a value other than -1 is given, objects will be visited in breadth-first manner (i.e., ordered by distance) and the search is truncated atmaxDistance
hops. If -1 is given, there is no limit and also no implied ordering of the objects in the iteration.- Parameters:
id
- starting object IDmaxDistance
- the maximum number of reference fields to hop through, or -1 for no limitvisited
- on entry objects already visited, on return all objects reachedcascades
- zero or more reference cascade names- Returns:
- iteration of reachable objects
- Throws:
DeletedObjectException
- if any object containing a traversed reference field does not actually existIllegalArgumentException
- ifmaxDistance
is less than -1IllegalArgumentException
- if any parameter is null- See Also:
-
get
Get the Java model object that is associated with this transaction and has the given ID.This method guarantees that for any particular
id
, the same Java instance will always be returned by this transaction.A non-null object is always returned, but the corresponding object may not actually exist in this transaction. If not, attempts to access its fields will throw
DeletedObjectException
. UsePermazenObject.exists()
to check.Also, it's possible that
id
corresponds to an object type that no longer exists in the schema version associated with this transaction. In that case, anUntypedPermazenObject
is returned.- Parameters:
id
- object ID- Returns:
- Java model object
- Throws:
IllegalArgumentException
- ifid
is null- See Also:
-
get
Get the Java model object that is associated with this transaction and has the given ID, cast to the given type.This method guarantees that for any particular
id
, the same Java instance will always be returned by this transaction.A non-null object is always returned, but the corresponding object may not actually exist in this transaction. If not, attempts to access its fields will throw
DeletedObjectException
. UsePermazenObject.exists()
to check.This method just invokes
get(ObjId)
and then casts the result.- Type Parameters:
T
- expected Java model type- Parameters:
id
- object IDtype
- expected type- Returns:
- Java model object
- Throws:
ClassCastException
- if the Java model object does not have typetype
IllegalArgumentException
- if either parameter is null- See Also:
-
get
Get the Java model object with the same object ID as the givenPermazenObject
and whose state derives from this transaction.This method can be thought of as a "refresh" operation for objects being imported from other transactions into this one.
A non-null object is always returned, but the corresponding object may not actually exist in this transaction. If not, attempts to access its fields will throw
DeletedObjectException
. UsePermazenObject.exists()
to check.This method is equivalent to
get(pobj.getObjId())
followed by an appropriate cast to typeT
.- Type Parameters:
T
- expected Java type- Parameters:
pobj
- Java model object- Returns:
- Java model object in this transaction with the same object ID (possibly
pobj
itself) - Throws:
IllegalArgumentException
- ifpobj
is null, or not aPermazen
database objectClassCastException
- if the Java model object in this transaction somehow does not have the same type aspobj
- See Also:
-
create
Create a new instance of the given model class in this transaction.- Type Parameters:
T
- Java model type- Parameters:
type
- Java object model type- Returns:
- newly created instance
- Throws:
IllegalArgumentException
- iftype
is not a known Java object model typeStaleTransactionException
- if this transaction is no longer usable
-
create
Create a new instance of the given type in this transaction.- Type Parameters:
T
- Java model type- Parameters:
pclass
- object type- Returns:
- newly created instance
- Throws:
IllegalArgumentException
- ifpclass
is null or not valid for this instanceStaleTransactionException
- if this transaction is no longer usable
-
delete
Delete the object with the given object ID in this transaction.This method is typically only used by generated classes; normally,
PermazenObject.delete()
would be used instead.- Parameters:
pobj
- the object to delete- Returns:
- true if object was found and deleted, false if object was not found
- Throws:
ReferencedObjectException
- if the object is referenced by some other object through a reference field configured forDeleteAction.EXCEPTION
StaleTransactionException
- if this transaction is no longer usableIllegalArgumentException
- ifpobj
is null
-
exists
Determine whether the object with the given object ID exists in this transaction.This method is typically only used by generated classes; normally,
PermazenObject.exists()
would be used instead.- Parameters:
id
- ID of the object to test for existence- Returns:
- true if object was found, false if object was not found
- Throws:
StaleTransactionException
- if this transaction is no longer usableIllegalArgumentException
- ifid
is null
-
recreate
Recreate the given instance in this transaction.This method is typically only used by generated classes; normally,
PermazenObject.recreate()
would be used instead.- Parameters:
pobj
- the object to recreate- Returns:
- true if the object was recreated, false if the object already existed
- Throws:
StaleTransactionException
- if this transaction is no longer usableIllegalArgumentException
- ifpobj
is null
-
revalidate
Add the given instance to the validation queue for validation, which will occur either atcommit()
time or at the next invocation ofvalidate()
, whichever occurs first.This method is typically only used by generated classes; normally,
PermazenObject.revalidate(java.lang.Class<?>...)
would be used instead.- Parameters:
id
- ID of the object to revalidategroups
- validation group(s) to use for validation; if empty,Default
is assumed- Throws:
StaleTransactionException
- if this transaction is no longer usableIllegalStateException
- if transaction commit is already in progressDeletedObjectException
- if the object does not exist in this transactionIllegalArgumentException
- if either parameter is nullIllegalArgumentException
- if any group ingroups
is null
-
resetValidationQueue
public void resetValidationQueue()Clear the validation queue associated with this transaction. Any previously enqueued objects that have not yet been validated will no longer receive validation.- Throws:
StaleTransactionException
- if this transaction is no longer usableIllegalStateException
- if transaction commit is already in progress
-
migrateSchema
Update the schema of the specified object, if necessary, so that it matches the schema associated with this instance'sPermazen
.If a schema change occurs,
@OnSchemaChange
methods will be invoked prior to this method returning.This method is typically only used by generated classes; normally,
PermazenObject.migrateSchema()
would be used instead.- Parameters:
pobj
- object to update- Returns:
- true if the object's schema was migrated, false if it was already updated
- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- ifpobj
does not exist in this transactionTypeNotInSchemaException
- if the current schema does not contain the object's typeIllegalArgumentException
- ifpobj
is null
-
registerPermazenObject
Ensure the givenPermazenObject
is registered in its associated transaction's object cache.This method is used internally, to handle mutations in model class superclass constructors, which will occur before the newly created
PermazenObject
is fully constructed and associated with itsPermazenTransaction
.- Parameters:
pobj
- object to register- Throws:
IllegalArgumentException
- ifpobj
is null
-
readSimpleField
Read a simple field.This returns the value returned by
Transaction.readSimpleField()
withObjId
s converted intoPermazenObject
s, etc.This method is used by generated
@PermazenField
getter override methods and not normally invoked directly by user code.- Parameters:
id
- ID of the object containing the fieldfieldName
- the name of thePermazenSimpleField
migrateSchema
- true to automatically migrate the object's schema, false to not change it- Returns:
- the value of the field in the object
- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- if the object does not exist in this transactionUnknownFieldException
- if noPermazenSimpleField
corresponding tofieldName
inid
existsTypeNotInSchemaException
- ifmigrateSchema
is true but the object has a type that does not exist in this instance's schemaIllegalArgumentException
- ifid
orfieldName
is null
-
writeSimpleField
public void writeSimpleField(PermazenObject pobj, String fieldName, Object value, boolean migrateSchema) Write a simple field.This writes the value via
Transaction.writeSimpleField()
after convertingPermazenObject
s intoObjId
s, etc.This method is used by generated
@PermazenField
setter override methods and not normally invoked directly by user code.- Parameters:
pobj
- object containing the fieldfieldName
- the name of thePermazenSimpleField
value
- new value for the fieldmigrateSchema
- true to automatically migrate the object's schema, false to not change it- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- ifpobj
does not exist in this transactionUnknownFieldException
- if noPermazenSimpleField
corresponding tofieldName
existsTypeNotInSchemaException
- ifmigrateSchema
is true butpobj
has a type that does not exist in this instance's schemaIllegalArgumentException
- ifvalue
is not an appropriate value for the fieldIllegalArgumentException
- ifpobj
orfieldName
is null
-
readCounterField
Read a counter field.This method is used by generated
@PermazenField
getter override methods and not normally invoked directly by user code.- Parameters:
id
- ID of the object containing the fieldfieldName
- the name of thePermazenCounterField
migrateSchema
- true to automatically migrate the object's schema, false to not change it- Returns:
- the value of the field in the object
- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- if the object does not exist in this transactionUnknownFieldException
- if noPermazenCounterField
corresponding tofieldName
existsTypeNotInSchemaException
- ifmigrateSchema
is true but the object has a type that does not exist in this instance's schemaIllegalArgumentException
- ifid
orfieldName
is null
-
readSetField
Read a set field.This returns the set returned by
Transaction.readSetField()
withObjId
s converted intoPermazenObject
s, etc.This method is used by generated
@PermazenSetField
getter override methods and not normally invoked directly by user code.- Parameters:
id
- ID of the object containing the fieldfieldName
- the name of thePermazenSetField
migrateSchema
- true to automatically migrate the object's schema, false to not change it- Returns:
- the value of the field in the object
- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- if the object does not exist in this transactionUnknownFieldException
- if noPermazenSetField
corresponding tofieldName
existsTypeNotInSchemaException
- ifmigrateSchema
is true but the object has a type that does not exist in this instance's schemaIllegalArgumentException
- ifid
orfieldName
is null
-
readListField
Read a list field.This returns the list returned by
Transaction.readListField()
withObjId
s converted intoPermazenObject
s, etc.This method is used by generated
@PermazenListField
getter override methods and not normally invoked directly by user code.- Parameters:
id
- ID of the object containing the fieldfieldName
- the name of thePermazenListField
migrateSchema
- true to automatically migrate the object's schema, false to not change it- Returns:
- the value of the field in the object
- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- if the object does not exist in this transactionUnknownFieldException
- if noPermazenListField
corresponding tofieldName
existsTypeNotInSchemaException
- ifmigrateSchema
is true but the object has a type that does not exist in this instance's schemaIllegalArgumentException
- ifid
orfieldName
is null
-
readMapField
Read a map field.This returns the map returned by
Transaction.readMapField()
withObjId
s converted intoPermazenObject
s, etc.This method is used by generated
@PermazenMapField
getter override methods and not normally invoked directly by user code.- Parameters:
id
- ID of the object containing the fieldfieldName
- the name of thePermazenMapField
migrateSchema
- true to automatically migrate the object's schema, false to not change it- Returns:
- the value of the field in the object
- Throws:
StaleTransactionException
- if this transaction is no longer usableDeletedObjectException
- if the object does not exist in this transactionUnknownFieldException
- if noPermazenMapField
corresponding tofieldName
existsTypeNotInSchemaException
- ifmigrateSchema
is true but the object has a type that does not exist in this instance's schemaIllegalArgumentException
- ifid
orfieldName
is null
-
followReferencePath
public NavigableSet<PermazenObject> followReferencePath(ReferencePath path, Stream<? extends PermazenObject> startObjects) Find all target objects that are reachable from the given starting object set through the specifiedReferencePath
.- Parameters:
path
- reference pathstartObjects
- starting objects- Returns:
- read-only set of objects reachable from
startObjects
viapath
- Throws:
UnknownFieldException
- ifpath
contains an unknown fieldIllegalArgumentException
- if either parameter is null- See Also:
-
invertReferencePath
public NavigableSet<PermazenObject> invertReferencePath(ReferencePath path, Stream<? extends PermazenObject> targetObjects) Find all starting objects that refer to any object in the given target set through the specifiedReferencePath
.- Parameters:
path
- reference pathtargetObjects
- target objects- Returns:
- read-only set of objects that refer to any of the
targetObjects
viapath
- Throws:
UnknownFieldException
- ifpath
contains an unknown fieldIllegalArgumentException
- if either parameter is null- See Also:
-
querySimpleIndex
public <V,T> Index1<V,T> querySimpleIndex(Class<T> targetType, String fieldName, Class<V> valueType) Get the index on a simple field. The simple field may be a sub-field of a complex field.- Type Parameters:
T
- Java type containing the fieldV
- Java type corresponding to the indexed field- Parameters:
targetType
- Java type containing the indexed field; may also be any super-type (e.g., an interface type), as long asfieldName
is not ambiguous among all sub-typesfieldName
- name of the indexed field; for complex fields, must include the sub-field name (e.g.,"mylist.element"
,"mymap.key"
) unless there is only one sub-field (i.e., sets and lists but not maps)valueType
- the Java type corresponding to the field value- Returns:
- read-only, real-time view of field values mapped to sets of objects having that value in the field
- Throws:
IllegalArgumentException
- if any parameter is null, or invalidStaleTransactionException
- if this transaction is no longer usable
-
queryListElementIndex
public <V,T> Index2<V,T, queryListElementIndexInteger> (Class<T> targetType, String fieldName, Class<V> valueType) Get the composite index on a list field that includes list indices.- Type Parameters:
T
- Java type containing the fieldV
- Java type corresponding to the indexed list's element field- Parameters:
targetType
- type containing the indexed field; may also be any super-type (e.g., an interface type), as long asfieldName
is not ambiguous among all sub-typesfieldName
- name of the indexed field; must include"element"
sub-field name (e.g.,"mylist.element"
)valueType
- the Java type corresponding to list elements- Returns:
- read-only, real-time view of field values, objects having that value in the field, and corresponding list indices
- Throws:
IllegalArgumentException
- if any parameter is null, or invalidStaleTransactionException
- if this transaction is no longer usable
-
queryMapValueIndex
public <V,T, Index2<V,K> T, queryMapValueIndexK> (Class<T> targetType, String fieldName, Class<V> valueType, Class<K> keyType) Get the composite index on a map value field that includes map keys.- Type Parameters:
T
- Java type containing the fieldV
- Java type corresponding to the indexed map's value fieldK
- Java type corresponding to the indexed map's key field- Parameters:
targetType
- type containing the indexed field; may also be any super-type (e.g., an interface type), as long asfieldName
is not ambiguous among all sub-typesfieldName
- name of the indexed field; must include"value"
sub-field name (e.g.,"mymap.value"
)valueType
- the Java type corresponding to map valueskeyType
- the Java type corresponding to map keys- Returns:
- read-only, real-time view of map values, objects having that value in the map field, and corresponding map keys
- Throws:
IllegalArgumentException
- if any parameter is null, or invalidStaleTransactionException
- if this transaction is no longer usable
-
queryCompositeIndex
public <V1,V2, Index2<V1,T> V2, queryCompositeIndexT> (Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type) Access a composite index on two fields.- Type Parameters:
T
- Java type containing the fieldV1
- Java type corresponding to the first indexed fieldV2
- Java type corresponding to the second indexed field- Parameters:
targetType
- type containing the indexed fields; may also be any super-type (e.g., an interface type)indexName
- the name of the composite indexvalue1Type
- the Java type corresponding to the first field valuevalue2Type
- the Java type corresponding to the second field value- Returns:
- read-only, real-time view of the fields' values and the objects having those values in the fields
- Throws:
IllegalArgumentException
- if any parameter is null, or invalidStaleTransactionException
- if this transaction is no longer usable
-
queryCompositeIndex
public <V1,V2, Index3<V1,V3, T> V2, queryCompositeIndexV3, T> (Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type, Class<V3> value3Type) Access a composite index on three fields.- Type Parameters:
T
- Java type containing the fieldV1
- Java type corresponding to the first indexed fieldV2
- Java type corresponding to the second indexed fieldV3
- Java type corresponding to the third indexed field- Parameters:
targetType
- type containing the indexed fields; may also be any super-type (e.g., an interface type)indexName
- the name of the composite indexvalue1Type
- the Java type corresponding to the first field valuevalue2Type
- the Java type corresponding to the second field valuevalue3Type
- the Java type corresponding to the third field value- Returns:
- read-only, real-time view of the fields' values and the objects having those values in the fields
- Throws:
IllegalArgumentException
- if any parameter is null, or invalidStaleTransactionException
- if this transaction is no longer usable
-
queryCompositeIndex
public <V1,V2, Index4<V1,V3, V4, T> V2, queryCompositeIndexV3, V4, T> (Class<T> targetType, String indexName, Class<V1> value1Type, Class<V2> value2Type, Class<V3> value3Type, Class<V4> value4Type) Access a composite index on four fields.- Type Parameters:
T
- Java type containing the fieldV1
- Java type corresponding to the first indexed fieldV2
- Java type corresponding to the second indexed fieldV3
- Java type corresponding to the third indexed fieldV4
- Java type corresponding to the fourth indexed field- Parameters:
targetType
- type containing the indexed fields; may also be any super-type (e.g., an interface type)indexName
- the name of the composite indexvalue1Type
- the Java type corresponding to the first field valuevalue2Type
- the Java type corresponding to the second field valuevalue3Type
- the Java type corresponding to the third field valuevalue4Type
- the Java type corresponding to the fourth field value- Returns:
- read-only, real-time view of the fields' values and the objects having those values in the fields
- Throws:
IllegalArgumentException
- if any parameter is null, or invalidStaleTransactionException
- if this transaction is no longer usable
-
queryIndex
Query an index by storage ID. For storage ID's corresponding to simple fields, this method returns anIndex
, except for list element and map value fields, for which anIndex2
is returned. For storage ID's corresponding to composite indexes, this method returns anIndex2
,Index3
, etc. as appropriate.This method exists mainly for the convenience of programmatic tools, etc.
- Parameters:
storageId
- indexedPermazenSimpleField
's storage ID- Returns:
- read-only, real-time view of the fields' values and the objects having those values in the fields
- Throws:
IllegalArgumentException
- ifstorageId
does not correspond to an indexed field or composite indexStaleTransactionException
- if this transaction is no longer usable
-
commit
public void commit()Commit this transaction.Prior to actual commit, if this transaction was created with a validation mode other than
ValidationMode.DISABLED
, validation of outstanding objects in the validation queue is performed.If a
ValidationException
is thrown, the transaction is no longer usable. To perform validation and leave the transaction open, invokevalidate()
prior to commit.- Throws:
StaleTransactionException
- if this transaction is no longer usableRetryKVTransactionException
- fromKVTransaction.commit()
ValidationException
- if a validation error is detectedIllegalStateException
- if this method is invoked re-entrantly from within a validation check
-
rollback
public void rollback()Roll back this transaction.This method may be invoked at any time, even after a previous invocation of
commit()
orrollback()
, in which case the invocation will be ignored. -
isOpen
public boolean isOpen()Determine whether this transaction is still usable.- Returns:
- true if this transaction is still valid
- See Also:
-
validate
public void validate()Perform validation checks on all objects currently in the validation queue. This method may be called at any time prior tocommit()
to process and clear the queue of validatable objects.If validation fails, validation stops, all remaining unvalidated objects are left on the validation queue, and a
ValidationException
is thrown. The transaction will remain usable.Note: if the this transaction was created with
ValidationMode.DISABLED
, then this method does nothing.- Throws:
RetryKVTransactionException
- fromKVTransaction.commit()
ValidationException
- if a validation error is detectedIllegalStateException
- if transaction commit is already in progressStaleTransactionException
- if this transaction is no longer usable- See Also:
-
performAction
Invoke the givenRunnable
with this instance as the current transaction.If another instance is currently associated with the current thread, it is set aside for the duration of
action
's execution, and then restored whenaction
is finished (regardless of outcome).- Parameters:
action
- action to perform- Throws:
IllegalArgumentException
- ifaction
is null
-
performAction
Invoke the givenSupplier
with this instance as the current transaction.If another instance is currently associated with the current thread, it is set aside for the duration of
action
's execution, and then restored whenaction
is finished (regardless of outcome).- Parameters:
action
- action to perform- Returns:
- result from action
- Throws:
IllegalArgumentException
- ifaction
is null
-
withWeakConsistency
Apply weaker transaction consistency while performing the given action, if supported.Some key/value implementations support reads with weaker consistency guarantees. These reads generate fewer transaction conflicts but return possibly out-of-date information. Depending on the implementation, when operating in this mode writes may not be supported and may generate a
IllegalStateException
or just be ignored.The weaker consistency is only applied for the current thread, and it ends when this method returns.
This method is for experts only; inappropriate use can result in a corrupted database. You should not make any changes to the database after this method returns based on any information read by the
action
.- Parameters:
action
- the action to perform- Throws:
IllegalArgumentException
- ifaction
is null
-