Search in sources :

Example 1 with Explainer

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

Aggregations

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