public interface EntityIterable extends java.lang.Iterable<Entity>
EntityIterable allows to lazily iterate over entities. It's a result of all
StoreTransaction methods that query, sort and filter entities.
EntityIterable is valid only against particular database snapshot, so finishing transaction
(commit() or abort) or moving it to
the newest snapshot (flush() or revert())
breaks iteration.
StoreTransaction,
EntityIterator,
Entity| Modifier and Type | Method and Description |
|---|---|
@NotNull EntityIterable |
asSortResult()
Marks this
EntityIterable as sort result, so built-in sort engine can recognize custom sorting for stable sorting. |
@NotNull EntityIterable |
concat(@NotNull EntityIterable right)
Returns concatenation of this
EntityIterable and the right EntityIterable. |
boolean |
contains(@NotNull Entity entity)
Returns
true if the EntityIterable contains specified entity. |
long |
count()
Returns the number of entities in the
EntityIterable, or -1 if it cannot be calculated
immediately. |
@NotNull EntityIterable |
distinct() |
@Nullable Entity |
getFirst() |
@Nullable Entity |
getLast() |
long |
getRoughCount()
Returns rough number of entities in the
EntityIterable, or -1 if the size of the
EntityIterable was never calculated. |
long |
getRoughSize()
|
@NotNull StoreTransaction |
getTransaction() |
int |
indexOf(@NotNull Entity entity)
Returns index of specified entity in the
EntityIterable, or -1 if there is no such entity. |
@NotNull EntityIterable |
intersect(@NotNull EntityIterable right)
Returns intersection of this
EntityIterable and the right EntityIterable. |
@NotNull EntityIterable |
intersectSavingOrder(@NotNull EntityIterable right)
Returns same result as intersect(EntityIterable), but also guarantees that the order in the
result corresponds to the order of the right
EntityIterable. |
boolean |
isEmpty() |
boolean |
isSortResult()
Custom sorting algorithms can mark their results as sort results.
|
EntityIterator |
iterator()
Creates new instance of EntityIterator.
|
@NotNull EntityIterable |
minus(@NotNull EntityIterable right)
Returns relative complement of the right
EntityIterable in this EntityIterable, i.e. |
@NotNull EntityIterable |
reverse() |
@NotNull EntityIterable |
selectDistinct(@NotNull java.lang.String linkName)
Returns entities which the source entities (this
EntityIterable) are linked with by the link with
specified name. |
@NotNull EntityIterable |
selectManyDistinct(@NotNull java.lang.String linkName)
Returns entities which the source entities (this
EntityIterable) are linked with by the link with
specified name. |
long |
size()
Returns the number of entities in the
EntityIterable. |
@NotNull EntityIterable |
skip(int number)
Returns
EntityIterable that skips specified number of entities from the beginning of this EntityIterable. |
@NotNull EntityIterable |
take(int number)
Returns
EntityIterable that returns specified number of entities from this EntityIterable. |
@NotNull EntityIterable |
union(@NotNull EntityIterable right)
Returns union of this
EntityIterable and the right EntityIterable. |
EntityIterator iterator()
iterator in interface java.lang.Iterable<Entity>EntityIterator@NotNull @NotNull StoreTransaction getTransaction()
EntityIterable was createdStoreTransactionboolean isEmpty()
true if the EntityIterable has no elementssize(),
count(),
getRoughCount(),
getRoughSize()long size()
EntityIterable. This method can be slow.EntityIterableisEmpty(),
count(),
getRoughCount(),
getRoughSize()long count()
EntityIterable, or -1 if it cannot be calculated
immediately. If it returns -1, it starts background calculation of size(), so deferred
call to this method should eventually return a value different from -1 and equal to size().EntityIterable, or -1 if it cannot be calculated immediatelyisEmpty(),
size(),
getRoughCount(),
getRoughSize()long getRoughCount()
EntityIterable, or -1 if the size of the
EntityIterable was never calculated. In other words, it returns the same value as size()
if it can be calculated immediately, or last known size, or -1 in the worst case. This method is
eventually consistent, i.e. its result (different form -1) can differ from result of
size() and count().EntityIterableisEmpty(),
size(),
count(),
getRoughSize()long getRoughSize()
-1. So it never returns -1, but it is still eventually consistent as its
result can differ from the result of size().EntityIterableisEmpty(),
size(),
count(),
getRoughCount()int indexOf(@NotNull
@NotNull Entity entity)
EntityIterable, or -1 if there is no such entity.
The index can be defined as follows: if int i = indexOf(entity) and i is not equal to -1
then the value of skip(i).getFirst() should be not-null and equal to entity.entity - entity to search forEntityIterable, or -1 if there is no such entitycontains(Entity)boolean contains(@NotNull
@NotNull Entity entity)
true if the EntityIterable contains specified entity. In short, it just returns
value of indexOf(entity) != -1.entity - entity whose presence in the EntityIterable is to be testedtrue if the EntityIterable contains specified entityindexOf(Entity)@NotNull @NotNull EntityIterable intersect(@NotNull @NotNull EntityIterable right)
EntityIterable and the right EntityIterable.right - EntityIterable that should be intersected with this EntityIterableEntityIterableunion(EntityIterable),
minus(EntityIterable),
concat(EntityIterable)@NotNull @NotNull EntityIterable intersectSavingOrder(@NotNull @NotNull EntityIterable right)
EntityIterable.right - EntityIterable which order is preserved in the resultEntityIterableintersect(EntityIterable)@NotNull @NotNull EntityIterable union(@NotNull @NotNull EntityIterable right)
EntityIterable and the right EntityIterable.right - EntityIterable that should be joined with this EntityIterableEntityIterableintersect(EntityIterable),
minus(EntityIterable),
concat(EntityIterable)@NotNull @NotNull EntityIterable minus(@NotNull @NotNull EntityIterable right)
EntityIterable in this EntityIterable, i.e.
set-theoretic difference of this EntityIterable and the right EntityIterable.right - EntityIterable which entities will excluded (subtracted) from this EntityIterableEntityIterable in this EntityIterableintersect(EntityIterable),
union(EntityIterable),
concat(EntityIterable)@NotNull @NotNull EntityIterable concat(@NotNull @NotNull EntityIterable right)
EntityIterable and the right EntityIterable. Unlike other binary
operations, result can have duplicate entities.right - EntityIterable that should be concatenated to this EntityIterableEntityIterableintersect(EntityIterable),
union(EntityIterable),
minus(EntityIterable)@NotNull @NotNull EntityIterable skip(int number)
EntityIterable that skips specified number of entities from the beginning of this EntityIterable.number - entities to skipEntityIterable with the number of skipped entitiestake(int)@NotNull @NotNull EntityIterable take(int number)
EntityIterable that returns specified number of entities from this EntityIterable.number - number of entitiesEntityIterable with the number of entitiesskip(int)@NotNull @NotNull EntityIterable distinct()
EntityIterable@NotNull @NotNull EntityIterable selectDistinct(@NotNull @NotNull java.lang.String linkName)
EntityIterable) are linked with by the link with
specified name. In order words, if target = source.getLink(linkName) for each source from
this EntityIterable, then target is a part of the result. It is implied that the link should be
single, i.e. targets should be set using method Entity.setLink(String, Entity), so only
one target for each source can be. Order of linked entities is undefined.linkName - name of the linkEntity.getLink(String),
Entity.setLink(String, Entity)@NotNull @NotNull EntityIterable selectManyDistinct(@NotNull @NotNull java.lang.String linkName)
EntityIterable) are linked with by the link with
specified name. In order words, if targets = source.getLinks(linkName) for each source from
this EntityIterable, then each target amongst targets is a part of the result.
It is implied that the link can me multiple, i.e. targets can be set using any method updating links,
Entity.setLink(String, Entity)or Entity.addLink(String, Entity), so there can be
arbitrary number of targets for each source. Order of linked entities is undefined.linkName - name of the linkEntity.getLink(String),
Entity.addLink(String, Entity)@Nullable @Nullable Entity getFirst()
EntityIterable, or null is it is empty@Nullable @Nullable Entity getLast()
EntityIterable, or null is it is empty@NotNull @NotNull EntityIterable reverse()
EntityIterable returns, but in reverse orderboolean isSortResult()
true if this EntityIterable is a result of sortingasSortResult(),
StoreTransaction.sort(String, String, EntityIterable, boolean),
StoreTransaction.sortLinks(String, EntityIterable, boolean, String, EntityIterable),
StoreTransaction.mergeSorted(List, Comparator)@NotNull @NotNull EntityIterable asSortResult()
EntityIterable as sort result, so built-in sort engine can recognize custom sorting for stable sorting.
E.g., in the following sample custom sorting will be lost:
final EntityIterable customSorting = myCustomSorting();
return txn.sort("User", "loginTime", customSorting, true);
To fix it, just mark custom sorting result as sort result:
final EntityIterable customSorting = myCustomSorting();
return txn.sort("User", "loginTime", customSorting.asSortResult(), true);
EntityIterable marked as sort resultisSortResult(),
StoreTransaction.sort(String, String, EntityIterable, boolean),
StoreTransaction.sortLinks(String, EntityIterable, boolean, String, EntityIterable),
StoreTransaction.mergeSorted(List, Comparator)