Search in sources :

Example 1 with EntityIterator

use of jetbrains.exodus.entitystore.EntityIterator in project xodus by JetBrains.

the class UpdatableEntityIdSortedSetCachedInstanceIterable method toSet.

@NotNull
@Override
public EntityIdSet toSet(@NotNull final PersistentStoreTransaction txn) {
    if (idSet == null) {
        final boolean isImmutable = mutableLocalIds == null;
        if (isImmutable) {
            final EntityIdCollection idCollection = getOrCreateIdCollection();
            if (idCollection instanceof EntityIdSet) {
                final EntityIdSet result = (EntityIdSet) idCollection;
                idSet = result;
                return result;
            }
        }
        final EntityIterator it = getIteratorImpl(txn);
        EntityIdSet result = EntityIdSetFactory.newSet();
        while (it.hasNext()) {
            result = result.add(it.nextId());
        }
        if (!isImmutable) {
            return result;
        }
        idSet = result;
        return result;
    }
    return idSet;
}
Also used : EntityIterator(jetbrains.exodus.entitystore.EntityIterator) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with EntityIterator

use of jetbrains.exodus.entitystore.EntityIterator 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)

Aggregations

EntityIterator (jetbrains.exodus.entitystore.EntityIterator)2 Entity (jetbrains.exodus.entitystore.Entity)1 EntityIterable (jetbrains.exodus.entitystore.EntityIterable)1 EntityStoreException (jetbrains.exodus.entitystore.EntityStoreException)1 EntityIterableBase (jetbrains.exodus.entitystore.iterate.EntityIterableBase)1 NotNull (org.jetbrains.annotations.NotNull)1