public interface StoreTransaction
StoreTransaction is a transaction started against EntityStore using
EntityStore.beginTransaction() or EntityStore.beginReadonlyTransaction() methods.
It's being implicitly created in PersistentEntityStore.executeInTransaction(StoreTransactionalExecutable),
PersistentEntityStore.executeInReadonlyTransaction(StoreTransactionalExecutable),
PersistentEntityStore.computeInTransaction(StoreTransactionalComputable) and
PersistentEntityStore.computeInReadonlyTransaction(StoreTransactionalComputable) methods, and it's
being passed as a parameter to StoreTransactionalExecutable and StoreTransactionalComputable
functions.
StoreTransaction is used to create new entities and query entity iterables.
EntityStore.beginTransaction(),
EntityStore.beginReadonlyTransaction(),
StoreTransactionalExecutable,
StoreTransactionalComputable,
PersistentEntityStore.executeInTransaction(StoreTransactionalExecutable),
PersistentEntityStore.executeInReadonlyTransaction(StoreTransactionalExecutable),
PersistentEntityStore.computeInTransaction(StoreTransactionalComputable),
PersistentEntityStore.computeInReadonlyTransaction(StoreTransactionalComputable),
Entity,
EntityIterable| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Ignores all changes and finishes the
StoreTransaction. |
boolean |
commit()
Tries to commits all changes and finish the
StoreTransaction. |
@NotNull EntityIterable |
find(@NotNull java.lang.String entityType,
@NotNull java.lang.String propertyName,
@NotNull java.lang.Comparable value)
Returns EntityIterable with entities of specified type with specified property equal to specified value.
|
@NotNull EntityIterable |
find(@NotNull java.lang.String entityType,
@NotNull java.lang.String propertyName,
@NotNull java.lang.Comparable minValue,
@NotNull java.lang.Comparable maxValue)
Returns EntityIterable with entities of specified type with specified property equal to a value in
specified range
[minValue, maxValue]. |
@NotNull EntityIterable |
findIds(@NotNull java.lang.String entityType,
long minValue,
long maxValue)
Returns EntityIterable with entities of specified type with ids having their
local ids in specified range [minValue, maxValue].
|
@NotNull EntityIterable |
findLinks(@NotNull java.lang.String entityType,
@NotNull EntityIterable entities,
@NotNull java.lang.String linkName)
Returns EntityIterable with entities of specified type which are linked to an entity in the
specified entity set by specified link.
|
@NotNull EntityIterable |
findLinks(@NotNull java.lang.String entityType,
@NotNull Entity entity,
@NotNull java.lang.String linkName)
Returns EntityIterable with entities of specified type which are linked to specified entity by
specified link.
|
@NotNull EntityIterable |
findStartingWith(@NotNull java.lang.String entityType,
@NotNull java.lang.String propertyName,
@NotNull java.lang.String value)
Returns EntityIterable with entities of specified type which have String values of
specified property starting with specified
value. |
@NotNull EntityIterable |
findWithBlob(@NotNull java.lang.String entityType,
@NotNull java.lang.String blobName)
Returns EntityIterable with entities of specified type which have not-null blob values with
specified name.
|
@NotNull EntityIterable |
findWithLinks(@NotNull java.lang.String entityType,
@NotNull java.lang.String linkName)
Returns EntityIterable with entities of specified type which have links with specified name.
|
@NotNull EntityIterable |
findWithLinks(@NotNull java.lang.String entityType,
@NotNull java.lang.String linkName,
@NotNull java.lang.String oppositeEntityType,
@NotNull java.lang.String oppositeLinkName)
Returns the same EntityIterable as findWithLinks(String, String) does, but faster
if extra indices are available in the database.
|
@NotNull EntityIterable |
findWithProp(@NotNull java.lang.String entityType,
@NotNull java.lang.String propertyName)
Returns EntityIterable with entities of specified type which have not-null property values with
specified name.
|
boolean |
flush()
Tries to flush all changes without finishing the
StoreTransaction. |
@NotNull EntityIterable |
getAll(@NotNull java.lang.String entityType)
Gets all entities of specified type.
|
@NotNull Entity |
getEntity(@NotNull EntityId id)
Loads up-to-date version of entity by its EntityId if it exists in the database.
|
@NotNull java.util.List<java.lang.String> |
getEntityTypes()
Returns all entity types available in the EntityStore.
|
@Nullable QueryCancellingPolicy |
getQueryCancellingPolicy() |
@NotNull Sequence |
getSequence(@NotNull java.lang.String sequenceName)
Returns existing or creates the new named Sequence.
|
@NotNull EntityIterable |
getSingletonIterable(@NotNull Entity entity)
Returns singleton EntityIterable with the single specified Entity.
|
StoreTransaction |
getSnapshot()
Gets read-only
StoreTransaction that holds snapshot of this StoreTransaction. |
@NotNull EntityStore |
getStore()
Returns the EntityStore instance which the
StoreTransaction is started against. |
boolean |
isFinished() |
boolean |
isIdempotent()
Idempotent transaction changes nothing in database.
|
boolean |
isReadonly() |
@NotNull EntityIterable |
mergeSorted(@NotNull java.util.List<EntityIterable> sorted,
@NotNull java.util.Comparator<Entity> comparator)
Deprecated.
|
@NotNull Entity |
newEntity(@NotNull java.lang.String entityType)
Creates new Entity of specified type.
|
void |
revert()
Reverts all changes without finishing the
StoreTransaction. |
void |
saveEntity(@NotNull Entity entity)
Saves new Entity which earlier was created by newEntity(String) but
StoreTransaction failed to flush() or commit(). |
void |
setQueryCancellingPolicy(QueryCancellingPolicy policy)
Sets a query cancelling policy for the
StoreTransaction. |
@NotNull EntityIterable |
sort(@NotNull java.lang.String entityType,
@NotNull java.lang.String propertyName,
boolean ascending)
Returns EntityIterable with entities of specified type sorted by values of specified property.
|
@NotNull EntityIterable |
sort(@NotNull java.lang.String entityType,
@NotNull java.lang.String propertyName,
@NotNull EntityIterable rightOrder,
boolean ascending)
Returns EntityIterable with entities of specified type from
rightOrder sorted by
values of specified property. |
@NotNull EntityIterable |
sortLinks(@NotNull java.lang.String entityType,
@NotNull EntityIterable sortedLinks,
boolean isMultiple,
@NotNull java.lang.String linkName,
@NotNull EntityIterable rightOrder)
Returns EntityIterable with entities of specified type from
rightOrder sorted by links with
specified name. |
@NotNull EntityIterable |
sortLinks(@NotNull java.lang.String entityType,
@NotNull EntityIterable sortedLinks,
boolean isMultiple,
@NotNull java.lang.String linkName,
@NotNull EntityIterable rightOrder,
@NotNull java.lang.String oppositeEntityType,
@NotNull java.lang.String oppositeLinkName)
Returns the same EntityIterable as sortLinks(String, EntityIterable, boolean, String, EntityIterable)
does, but faster if extra indices are available in the database.
|
@NotNull EntityId |
toEntityId(@NotNull java.lang.String representation)
Parses string representation of an entity id and returns corresponding EntityId instance.
|
@NotNull @NotNull EntityStore getStore()
StoreTransaction is started against. For
out-of-the-box implementations of StoreTransaction, it always returns the
PersistentEntityStore instance.boolean isIdempotent()
true. Each newly created
transaction is idempotent.boolean isReadonly()
true if the transaction is read-onlyboolean isFinished()
boolean commit()
StoreTransaction. If the method succeed, it returns
true. Use abort() method to finish transaction ignoring changes.
Typical pattern for committing changes can look like this:
final StoreTransaction transaction = entityStore.beginTransaction();
while(true) {
try {
// do your changes here
} catch(Throwable t) {
transaction.abort();
throw ExodusException.toRuntime(t);
}
if (transaction.commit()) {
break;
}
}
void abort()
StoreTransaction.
Typical pattern for committing changes (abort() is called in catch block) can look like this:
final StoreTransaction transaction = entityStore.beginTransaction();
while(true) {
try {
// do your changes here
} catch(Throwable t) {
transaction.abort();
throw ExodusException.toRuntime(t);
}
if (transaction.commit()) {
break;
}
}
boolean flush()
StoreTransaction. If the method succeed, it returns
true. After successful flush, the StoreTransaction moves to the latest database snapshot.
Typical pattern for flushing changes can look like this:
final StoreTransaction transaction = entityStore.beginTransaction();
while(true) {
try {
// do your changes here
} catch(Throwable t) {
transaction.abort();
throw ExodusException.toRuntime(t);
}
if (transaction.flush()) {
break;
}
}
// here continue working with transaction
void revert()
StoreTransaction. After revert, the StoreTransaction
moves to the latest database snapshot.StoreTransaction getSnapshot()
StoreTransaction that holds snapshot of this StoreTransaction.@NotNull @NotNull Entity newEntity(@NotNull @NotNull java.lang.String entityType)
entityType - entity typesaveEntity(Entity),
Entity,
EntityIdvoid saveEntity(@NotNull
@NotNull Entity entity)
StoreTransaction failed to flush() or commit().
final Entity user = txn.newEntity("User"|;
if (!txn.flush()) {
// if flush didn't succeed you don't need to create one more new entity since user has already got its
// unique id, and it is enough to save it against the new database snapshot
txn.saveEntity(user);
// ...
}
entity - entity earlier returned by newEntity(String)newEntity(String),
Entity,
EntityId@NotNull @NotNull Entity getEntity(@NotNull @NotNull EntityId id)
id - unique EntityIdEntityRemovedInDatabaseException - if no entity exists with specified unique idEntityId@NotNull @NotNull java.util.List<java.lang.String> getEntityTypes()
EntityStore@NotNull @NotNull EntityIterable getAll(@NotNull @NotNull java.lang.String entityType)
entityType - entity typeEntityIterable@NotNull @NotNull EntityIterable getSingletonIterable(@NotNull @NotNull Entity entity)
entity - entityEntityIterable,
Entity@NotNull @NotNull EntityIterable find(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String propertyName, @NotNull @NotNull java.lang.Comparable value)
entityType - entity typepropertyName - name of the property to search forvalue - value of the property to search forEntityIterable@NotNull @NotNull EntityIterable find(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String propertyName, @NotNull @NotNull java.lang.Comparable minValue, @NotNull @NotNull java.lang.Comparable maxValue)
[minValue, maxValue].entityType - entity typepropertyName - name of the property to search forminValue - minimum value of the property (inclusively, >=).maxValue - maximum value of the property (inclusively <=).EntityIterable@NotNull @NotNull EntityIterable findStartingWith(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String propertyName, @NotNull @NotNull java.lang.String value)
value.entityType - entity typepropertyName - name of the property to search forvalue - String value which searched properties are starting withEntityIterable@NotNull @NotNull EntityIterable findIds(@NotNull @NotNull java.lang.String entityType, long minValue, long maxValue)
entityType - entity typeminValue - minimum value of EntityId.getLocalId() amongst all returned entitiesmaxValue - maximum value of EntityId.getLocalId() amongst all returned entitiesEntityIterable,
EntityId@NotNull @NotNull EntityIterable findWithProp(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String propertyName)
entityType - entity typepropertyName - property nameEntityIterable@NotNull @NotNull EntityIterable findWithBlob(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String blobName)
entityType - entity typeblobName - blob nameEntityIterable@NotNull @NotNull EntityIterable findLinks(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull Entity entity, @NotNull @NotNull java.lang.String linkName)
entityType - entity typeentity - entity which resulting entities are linked tolinkName - link name to search forEntityIterable@NotNull @NotNull EntityIterable findLinks(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull EntityIterable entities, @NotNull @NotNull java.lang.String linkName)
entityType - entity typeentities - entity set which entities from resulting EntityIterable are linked to (each
resulting entity is linked to at least to one entity from the set)linkName - link name to search forEntityIterable@NotNull @NotNull EntityIterable findWithLinks(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String linkName)
entityType - entity typelinkName - link nameEntityIterable@NotNull @NotNull EntityIterable findWithLinks(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String linkName, @NotNull @NotNull java.lang.String oppositeEntityType, @NotNull @NotNull java.lang.String oppositeLinkName)
This method can be used in the following case. Let t1 be an Entity of the "T1"
type and t2 - an Entity of the "T2" type.
If they are mutually linked so that t1.getLink("linkName") == t2 and
t2.getLink("oppositeLinkName") == t1, then it worth to use this method.
entityType - entity type ("T1")linkName - link nameoppositeEntityType - opposite entity type ("T@")oppositeLinkName - opposite link nameEntityIterable@NotNull @NotNull EntityIterable sort(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String propertyName, boolean ascending)
entityType - entity typepropertyName - property nameascending - true is sorting order is ascendingsort(String, String, EntityIterable, boolean),
sortLinks(String, EntityIterable, boolean, String, EntityIterable),
sortLinks(String, EntityIterable, boolean, String, EntityIterable, String, String),
mergeSorted(List, Comparator),
EntityIterable,
EntityIterable.isSortResult(),
EntityIterable.asSortResult()@NotNull @NotNull EntityIterable sort(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull java.lang.String propertyName, @NotNull @NotNull EntityIterable rightOrder, boolean ascending)
rightOrder sorted by
values of specified property. Stable sort is used if rightOrder is
is sort result.entityType - entity typepropertyName - property namerightOrder - EntityIterable to sort byascending - true is sorting order is ascendingsort(String, String, boolean),
sortLinks(String, EntityIterable, boolean, String, EntityIterable),
sortLinks(String, EntityIterable, boolean, String, EntityIterable, String, String),
mergeSorted(List, Comparator),
EntityIterable,
EntityIterable.isSortResult(),
EntityIterable.asSortResult()@NotNull @NotNull EntityIterable sortLinks(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull EntityIterable sortedLinks, boolean isMultiple, @NotNull @NotNull java.lang.String linkName, @NotNull @NotNull EntityIterable rightOrder)
rightOrder sorted by links with
specified name. Order of links is defined by the sortedLinks iterable.
// creation of user
final Entity user = txn.newEntity("User"); // entityType is "User"
user.setProperty("login", ...);
user.setProperty("password", ...);
user.setProperty("fullName", ...);
final Entity emailAccount = txn.newEntity("EmailAccount");
emailAccount.setProperty("email", ...);
user.addLink("emailAccount", emailAccount); // linkName is "emailAccount"
// and so on
// ...
// given we have some EntityIterable users, sorting users by e-mail looks like this:
final EntityIterable linkedEmails = users.selectManyDistinct("emailAccount");
// linked email accounts sorted by email:
final EntityIterable sortedLinks = txn.sort("EmailAccount", "email", linkedEmails, true);
// and finally, given users sorted by email:
final EntityIterable result = txn.sortLinks("User",
sortedLinks,
true, // link "emailAccount" is multiple since user can have more than one account
"emailAccount",
users);
entityType - entity typesortedLinks - some custom order of linksisMultiple - true if the link is multiplelinkName - link namerightOrder - EntityIterable to sort bysort(String, String, boolean),
sort(String, String, EntityIterable, boolean),
sortLinks(String, EntityIterable, boolean, String, EntityIterable, String, String),
mergeSorted(List, Comparator),
EntityIterable,
EntityIterable.isSortResult(),
EntityIterable.asSortResult()@NotNull @NotNull EntityIterable sortLinks(@NotNull @NotNull java.lang.String entityType, @NotNull @NotNull EntityIterable sortedLinks, boolean isMultiple, @NotNull @NotNull java.lang.String linkName, @NotNull @NotNull EntityIterable rightOrder, @NotNull @NotNull java.lang.String oppositeEntityType, @NotNull @NotNull java.lang.String oppositeLinkName)
// creation of user
final Entity user = txn.newEntity("User"); // entityType is "User"
user.setProperty("login", ...);
user.setProperty("password", ...);
user.setProperty("fullName", ...);
final Entity emailAccount = txn.newEntity("EmailAccount"); // oppositeEntityType is "EmailAccount"
emailAccount.setProperty("email", ...);
user.addLink("emailAccount", emailAccount); // linkName is "emailAccount"
emailAccount.setLink("user", user); // oppositeLinkName is "user"
// and so on
// ...
// given we have some EntityIterable users, sorting users by e-mail looks like this:
final EntityIterable linkedEmails = users.selectManyDistinct("emailAccount");
// linked email accounts sorted by email:
final EntityIterable sortedLinks = txn.sort("EmailAccount", "email", linkedEmails, true);
// and finally, given users sorted by email:
final EntityIterable result = txn.sortLinks("User",
sortedLinks,
true, // link "emailAccount" is multiple since user can have more than one account
"emailAccount",
users,
"EmailAccount",
"user");
entityType - entity typesortedLinks - some custom order of linksisMultiple - true if the link is multiplelinkName - link namerightOrder - EntityIterable to sort byoppositeEntityType - oppositeEntityTypeoppositeLinkName - oppositeLinkNamesort(String, String, boolean),
sort(String, String, EntityIterable, boolean),
sortLinks(String, EntityIterable, boolean, String, EntityIterable, String, String),
mergeSorted(List, Comparator),
EntityIterable,
EntityIterable.isSortResult(),
EntityIterable.asSortResult()@Deprecated @NotNull @NotNull EntityIterable mergeSorted(@NotNull @NotNull java.util.List<EntityIterable> sorted, @NotNull @NotNull java.util.Comparator<Entity> comparator)
EntityIterables for each entity type should be prepared, then this method merges the list.sorted - list of sorted EntityIterablescomparator - comparator that defines order of entitiessort(String, String, boolean),
sort(String, String, EntityIterable, boolean),
sortLinks(String, EntityIterable, boolean, String, EntityIterable),
sortLinks(String, EntityIterable, boolean, String, EntityIterable, String, String),
EntityIterable,
EntityIterable.isSortResult(),
EntityIterable.asSortResult()@NotNull @NotNull EntityId toEntityId(@NotNull @NotNull java.lang.String representation)
@NotNull @NotNull Sequence getSequence(@NotNull @NotNull java.lang.String sequenceName)
sequenceName - name of sequence, unique in the EntityStoreSequencevoid setQueryCancellingPolicy(QueryCancellingPolicy policy)
StoreTransaction.policy - query cancelling policygetQueryCancellingPolicy(),
QueryCancellingPolicy@Nullable @Nullable QueryCancellingPolicy getQueryCancellingPolicy()
nullsetQueryCancellingPolicy(QueryCancellingPolicy),
QueryCancellingPolicy