use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class BinaryOperatorsTests method testIntersectUnsorted.
public void testIntersectUnsorted() {
final StoreTransaction txn = getStoreTransaction();
for (int i = 0; i < 100; ++i) {
final Entity issue = Objects.requireNonNull(txn).newEntity("Issue");
issue.setProperty("name", "Test issue #" + (i % 10));
}
txn.flush();
EntityIterableBase found = (EntityIterableBase) txn.find("Issue", "name", "Test issue #1", "Test issue #2 ");
Assert.assertEquals(20, (int) found.size());
assertFalse(found.isSortedById());
Assert.assertEquals(20, (int) txn.getAll("Issue").intersect(txn.find("Issue", "name", "Test issue #1", "Test issue #2 ")).size());
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class And method instantiateCustom.
private static Iterable<Entity> instantiateCustom(@NotNull final String entityType, @NotNull final QueryEngine queryEngine, @NotNull final ModelMetaData metaData, @NotNull final NodeBase self, @NotNull final LinksEqualDecorator decorator, @NotNull final Instantiatable directClosure) {
final Iterable<Entity> selfInstance = self.instantiate(entityType, queryEngine, metaData);
if (selfInstance instanceof EntityIterableBase) {
final EntityIterable result = ((EntityIterableBase) selfInstance).findLinks(((EntityIterableBase) decorator.instantiateDecorated(decorator.getLinkEntityType(), queryEngine, metaData)).getSource(), decorator.getLinkName());
if (traceFindLinks) {
final Iterator<Entity> directIt = directClosure.instantiate().iterator();
final EntityIterator it = result.iterator();
while (true) {
final boolean directHasNext = directIt.hasNext();
final boolean hasNext = it.hasNext();
if (directHasNext != hasNext) {
throw new EntityStoreException("Invalid custom findLinks() result: different sizes");
}
if (!hasNext) {
break;
}
if (!directIt.next().getId().equals(it.nextId())) {
throw new EntityStoreException("Invalid custom findLinks() result");
}
}
}
return result;
}
return directClosure.instantiate();
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class QueryEngine method selectManyDistinct.
public Iterable<Entity> selectManyDistinct(Iterable<Entity> it, final String linkName) {
if (it == null) {
return EntityIterableBase.EMPTY;
}
if (mmd != null) {
if (it instanceof StaticTypedEntityIterable) {
final StaticTypedEntityIterable tree = (StaticTypedEntityIterable) it;
it = toEntityIterable(it);
if (isPersistentIterable(it)) {
final String entityType = tree.getEntityType();
final EntityMetaData emd = mmd.getEntityMetaData(entityType);
if (emd != null) {
final AssociationEndMetaData aemd = emd.getAssociationEndMetaData(linkName);
if (aemd != null) {
final String resultType = aemd.getOppositeEntityMetaData().getType();
return new StaticTypedIterableDecorator(resultType, selectManyDistinctImpl((EntityIterableBase) it, linkName), this);
}
}
}
} else if (isPersistentIterable(it)) {
return selectManyDistinctImpl((EntityIterableBase) it, linkName);
}
}
return inMemorySelectManyDistinct(it, linkName);
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class QueryEngine method selectDistinct.
public Iterable<Entity> selectDistinct(Iterable<Entity> it, final String linkName) {
if (it == null) {
return EntityIterableBase.EMPTY;
}
if (mmd != null) {
if (it instanceof StaticTypedEntityIterable) {
final StaticTypedEntityIterable ktei = (StaticTypedEntityIterable) it;
it = toEntityIterable(it);
if (isPersistentIterable(it)) {
final String entityType = ktei.getEntityType();
final EntityMetaData emd = mmd.getEntityMetaData(entityType);
if (emd != null) {
final AssociationEndMetaData aemd = emd.getAssociationEndMetaData(linkName);
if (aemd != null) {
final String resultType = aemd.getOppositeEntityMetaData().getType();
return new StaticTypedIterableDecorator(resultType, selectDistinctImpl((EntityIterableBase) it, linkName), this);
}
}
}
} else if (isPersistentIterable(it)) {
return selectDistinctImpl((EntityIterableBase) it, linkName);
}
}
return inMemorySelectDistinct(it, linkName);
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class And method instantiateCustom.
private static Iterable<Entity> instantiateCustom(@NotNull final String entityType, @NotNull final QueryEngine queryEngine, @NotNull final ModelMetaData metaData, @NotNull final InstantiateContext context, @NotNull final NodeBase self, @NotNull final LinksEqualDecorator decorator, @NotNull final Instantiatable directClosure) {
final Iterable<Entity> selfInstance = self.instantiate(entityType, queryEngine, metaData, context);
if (selfInstance instanceof EntityIterableBase) {
final EntityIterable result = ((EntityIterableBase) selfInstance).findLinks(((EntityIterableBase) decorator.instantiateDecorated(decorator.getLinkEntityType(), queryEngine, metaData, context)).getSource(), decorator.getLinkName());
if (traceFindLinks) {
final Iterator<Entity> directIt = directClosure.instantiate().iterator();
final EntityIterator it = result.iterator();
while (true) {
final boolean directHasNext = directIt.hasNext();
final boolean hasNext = it.hasNext();
if (directHasNext != hasNext) {
throw new EntityStoreException("Invalid custom findLinks() result: different sizes");
}
if (!hasNext) {
break;
}
if (!directIt.next().getId().equals(it.nextId())) {
throw new EntityStoreException("Invalid custom findLinks() result");
}
}
}
return result;
}
return directClosure.instantiate();
}
Aggregations