Search in sources :

Example 11 with EntityIterableBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.

the class ExcludeNullStaticTypedEntityIterable method instantiate.

@Override
public Iterable<Entity> instantiate() {
    Iterable<Entity> instantiatedDecorated = decorated.instantiate();
    if (queryEngine.isPersistentIterable(instantiatedDecorated)) {
        EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
        if (entityIterableBaseDecorated == EntityIterableBase.EMPTY) {
            return EntityIterableBase.EMPTY;
        }
        return queryEngine.wrap(new ExcludeNullIterableDecorator(entityIterableBaseDecorated.getTransaction(), entityIterableBaseDecorated));
    }
    return () -> new Iterator<Entity>() {

        private Iterator<Entity> iterator = null;

        private Entity next = null;

        @Override
        public boolean hasNext() {
            if (next != null) {
                return true;
            }
            if (iterator == null) {
                iterator = decorated.iterator();
            }
            while (iterator.hasNext() && next == null) {
                next = iterator.next();
            }
            return next != null;
        }

        @Override
        public Entity next() {
            if (hasNext()) {
                Entity result = next;
                next = null;
                return result;
            }
            throw new NoSuchElementException();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) ExcludeNullIterableDecorator(jetbrains.exodus.entitystore.iterate.ExcludeNullIterableDecorator) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Example 12 with EntityIterableBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.

the class AddNullStaticTypedEntityIterable method instantiate.

@Override
public Iterable<Entity> instantiate() {
    Iterable<Entity> instantiatedDecorated = decorated.instantiate();
    Iterable<Entity> instantiatedNullContainer = nullContainer.instantiate();
    if (queryEngine.isPersistentIterable(instantiatedDecorated) && queryEngine.isPersistentIterable(instantiatedNullContainer)) {
        EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
        EntityIterableBase entityIterableBaseNullContainer = ((EntityIterableBase) instantiatedNullContainer).getSource();
        return queryEngine.wrap(new AddNullDecoratorIterable(queryEngine.getPersistentStore().getAndCheckCurrentTransaction(), entityIterableBaseDecorated, entityIterableBaseNullContainer));
    }
    return () -> new Iterator<Entity>() {

        private Iterator<Entity> iterator = null;

        private Boolean hasNull = null;

        @Override
        public boolean hasNext() {
            if (iterator == null) {
                iterator = decorated.iterator();
            }
            if (iterator.hasNext()) {
                return true;
            }
            if (hasNull == null) {
                hasNull = false;
                for (Entity entity : nullContainer) {
                    if (entity == null) {
                        hasNull = true;
                        break;
                    }
                }
            }
            return hasNull;
        }

        @Override
        public Entity next() {
            if (hasNext()) {
                if (hasNull == null) {
                    Entity result = iterator.next();
                    if (result == null) {
                        hasNull = false;
                    }
                    return result;
                } else {
                    hasNull = false;
                    return null;
                }
            }
            throw new NoSuchElementException();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) AddNullDecoratorIterable(jetbrains.exodus.entitystore.iterate.binop.AddNullDecoratorIterable) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Example 13 with EntityIterableBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.

the class TreeKeepingEntityIterable method instantiate.

@SuppressWarnings("UnusedDeclaration")
@Override
public Iterable<Entity> instantiate() {
    optimize();
    Iterable<Entity> result;
    if (instance == null) {
        result = instantiateForWholeHierarchy();
    } else if (optimizedTree instanceof GetAll) {
        result = instance;
    } else {
        // clone
        TreeKeepingEntityIterable tkei = new TreeKeepingEntityIterable(null, entityType, optimizedTree.getClone(), queryEngine);
        tkei.optimizedTree = optimizedTree;
        result = queryEngine.toEntityIterable(queryEngine.intersect(instance, tkei));
    }
    if (sorts != null) {
        result = sorts.apply(entityType, result, queryEngine);
    }
    if (result == null) {
        result = instantiateForWholeHierarchy();
    }
    if (isExplainOn) {
        Iterable<Entity> explained = result;
        while (explained instanceof SortEngine.InMemorySortIterable) {
            explained = ((SortEngine.InMemorySortIterable) explained).getSrc();
        }
        if (explained instanceof EntityIterableBase) {
            final EntityIterableBase entityIterable = ((EntityIterableBase) explained).getSource();
            if (entityIterable != EntityIterableBase.EMPTY) {
                final PersistentEntityStoreImpl store = queryEngine.getPersistentStore();
                final Explainer explainer = store.getExplainer();
                final boolean explainForcedForThread = Explainer.isExplainForcedForThread();
                if (!explainForcedForThread) {
                    explainer.start(origin);
                }
                entityIterable.setOrigin(origin);
                explainer.explain(origin, Explainer.INITIAL_TREE, annotatedTree);
                explainer.explain(origin, Explainer.OPTIMIZED_TREE, optimizedTree);
                if (!explainForcedForThread) {
                    for (Entity entity : result) {
                        explainer.explain(origin, Explainer.ITERABLE_ADVANCES);
                    }
                    explainer.log(origin);
                }
            }
        }
    }
    return result;
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) PersistentEntityStoreImpl(jetbrains.exodus.entitystore.PersistentEntityStoreImpl) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Explainer(jetbrains.exodus.entitystore.Explainer)

Example 14 with EntityIterableBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.

the class ReplayTest method testPerformance.

public void testPerformance() {
    final PersistentStoreTransaction txn = getStoreTransaction();
    assertNotNull(txn);
    for (int i = 0; i < CACHE_SIZE; ++i) {
        final Entity entity = txn.newEntity("Issue");
        // entity.setProperty("description", "Test issue #" + i);
        entity.setProperty("size", i);
    }
    txn.flush();
    for (int i = 0; i < CACHE_SIZE; ++i) {
        final EntityIterableBase issues = findSome(txn, i);
        // fill cache
        issues.getOrCreateCachedInstance(txn);
    }
    final Entity[] change = new Entity[CHANGES_SIZE];
    for (int i = 0; i < CHANGES_SIZE; i++) {
        Entity issue = findSome(txn, 239 + i).getFirst();
        assertNotNull(issue);
        change[i] = issue;
    }
    System.out.println(System.currentTimeMillis());
    changeStuff(change);
    System.out.println(System.currentTimeMillis());
    System.out.println("----------");
    System.out.println(System.currentTimeMillis());
    replay(txn, change);
    System.out.println(System.currentTimeMillis());
}
Also used : EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase)

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