Search in sources :

Example 1 with PersistentEntityStoreImpl

use of jetbrains.exodus.entitystore.PersistentEntityStoreImpl 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).source;
        }
        if (explained instanceof EntityIterableBase) {
            EntityIterable entityIterable = ((EntityIterableBase) explained).getSource();
            if (entityIterable instanceof EntityIterableBase && entityIterable != EntityIterableBase.EMPTY) {
                EntityIterableBase entityIterableBase = ((EntityIterableBase) entityIterable);
                final PersistentEntityStoreImpl store = queryEngine.getPersistentStore();
                Explainer explainer = store.getExplainer();
                if (!Explainer.isExplainForcedForThread()) {
                    explainer.start(origin);
                }
                entityIterableBase.setOrigin(origin);
                explainer.explain(origin, Explainer.INITIAL_TREE, annotatedTree);
                explainer.explain(origin, Explainer.OPTIMIZED_TREE, optimizedTree);
                if (!Explainer.isExplainForcedForThread()) {
                    for (Entity entity : result) {
                        explainer.explain(origin, Explainer.ITERABLE_ADVANCES);
                    }
                    explainer.log(origin);
                }
            }
        }
    }
    return result;
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) PersistentEntityStoreImpl(jetbrains.exodus.entitystore.PersistentEntityStoreImpl) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Explainer(jetbrains.exodus.entitystore.Explainer)

Aggregations

Entity (jetbrains.exodus.entitystore.Entity)1 EntityIterable (jetbrains.exodus.entitystore.EntityIterable)1 Explainer (jetbrains.exodus.entitystore.Explainer)1 PersistentEntityStoreImpl (jetbrains.exodus.entitystore.PersistentEntityStoreImpl)1 EntityIterableBase (jetbrains.exodus.entitystore.iterate.EntityIterableBase)1