Search in sources :

Example 6 with EntityIterableBase

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());
}
Also used : EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase)

Example 7 with EntityIterableBase

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();
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) EntityIterator(jetbrains.exodus.entitystore.EntityIterator) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) EntityStoreException(jetbrains.exodus.entitystore.EntityStoreException)

Example 8 with EntityIterableBase

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);
}
Also used : AssociationEndMetaData(jetbrains.exodus.query.metadata.AssociationEndMetaData) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) EntityMetaData(jetbrains.exodus.query.metadata.EntityMetaData)

Example 9 with EntityIterableBase

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);
}
Also used : AssociationEndMetaData(jetbrains.exodus.query.metadata.AssociationEndMetaData) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) EntityMetaData(jetbrains.exodus.query.metadata.EntityMetaData)

Example 10 with EntityIterableBase

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();
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) EntityIterator(jetbrains.exodus.entitystore.EntityIterator) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) EntityStoreException(jetbrains.exodus.entitystore.EntityStoreException)

Aggregations

EntityIterableBase (jetbrains.exodus.entitystore.iterate.EntityIterableBase)14 Entity (jetbrains.exodus.entitystore.Entity)8 EntityIterable (jetbrains.exodus.entitystore.EntityIterable)4 Iterator (java.util.Iterator)2 NoSuchElementException (java.util.NoSuchElementException)2 ComparableGetter (jetbrains.exodus.entitystore.ComparableGetter)2 EntityIterator (jetbrains.exodus.entitystore.EntityIterator)2 EntityStoreException (jetbrains.exodus.entitystore.EntityStoreException)2 AssociationEndMetaData (jetbrains.exodus.query.metadata.AssociationEndMetaData)2 EntityMetaData (jetbrains.exodus.query.metadata.EntityMetaData)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 TestFor (jetbrains.exodus.TestFor)1 Explainer (jetbrains.exodus.entitystore.Explainer)1 PersistentEntityStoreImpl (jetbrains.exodus.entitystore.PersistentEntityStoreImpl)1 ExcludeNullIterableDecorator (jetbrains.exodus.entitystore.iterate.ExcludeNullIterableDecorator)1 AddNullDecoratorIterable (jetbrains.exodus.entitystore.iterate.binop.AddNullDecoratorIterable)1