public TreeKeepingEntityIterable()

in query/src/main/java/jetbrains/exodus/query/TreeKeepingEntityIterable.java [44:101]


    public TreeKeepingEntityIterable(@Nullable final Iterable<Entity> entityIterable, @NotNull String entityType,
                                     @NotNull final NodeBase queryTree, @Nullable String leftChildPresentation,
                                     @Nullable String rightChildPresentation, @NotNull QueryEngine queryEngine) {
        super(queryEngine);
        final Explainer explainer = queryEngine.getPersistentStore().getExplainer();
        isExplainOn = explainer.isExplainOn();
        origin = explainer.genOrigin();
        if (isExplainOn) {
            strippedStacktrace = Explainer.stripStackTrace(new Throwable());
        }
        // get entityType from iterable
        if (entityIterable instanceof StaticTypedEntityIterable) {
            final String entityIterableType = ((StaticTypedEntityIterable) entityIterable).getEntityType();
            if (!(entityType.equals(entityIterableType)) && Utils.isTypeOf(entityIterableType, entityType,
                    queryEngine.getModelMetaData())) {
                entityType = entityIterableType;
            }
        }
        //
        if (isExplainOn) {
            if (queryTree instanceof BinaryOperator && (leftChildPresentation != null || rightChildPresentation != null)) {
                BinaryOperator binaryOperator = (BinaryOperator) queryTree;
                if (leftChildPresentation == null) {
                    leftChildPresentation = binaryOperator.getLeft().toString();
                }
                if (rightChildPresentation == null) {
                    rightChildPresentation = binaryOperator.getRight().toString();
                }
                annotatedTree = "at " + strippedStacktrace + '\n' + binaryOperator.getClass().getSimpleName() + ('\n' + leftChildPresentation + '\n' + rightChildPresentation).replace("\n", '\n' + NodeBase.TREE_LEVEL_INDENT);
            } else {
                annotatedTree = "at " + strippedStacktrace + '\n' + queryTree;
            }
        }
        if (entityIterable instanceof TreeKeepingEntityIterable) {
            final TreeKeepingEntityIterable instanceTreeIt = (TreeKeepingEntityIterable) entityIterable;
            final NodeBase instanceTree = instanceTreeIt.sourceTree;
            if (queryTree instanceof Sort && ((UnaryNode) queryTree).getChild().equals(NodeFactory.all())) {
                sourceTree = queryTree.getClone();
                sourceTree.replaceChild(((UnaryNode) sourceTree).getChild(), instanceTree.getClone());
                if (isExplainOn) {
                    annotatedTree = "at " + strippedStacktrace + '\n' + sourceTree.getClass().getSimpleName() +
                            ("\n" + (instanceTreeIt.annotatedTree != null ? instanceTreeIt.annotatedTree : instanceTree)).replace("\n", '\n' + NodeBase.TREE_LEVEL_INDENT);
                }
            } else {
                sourceTree = instanceTree instanceof GetAll ? queryTree : And.and(instanceTree.getClone(), queryTree);
                if (isExplainOn && !(instanceTree instanceof GetAll)) {
                    annotatedTree = "at " + strippedStacktrace + "\nAnd" +
                            ("\n" + (instanceTreeIt.annotatedTree != null ? instanceTreeIt.annotatedTree : instanceTree) + '\n' + annotatedTree).replace("\n", '\n' + NodeBase.TREE_LEVEL_INDENT);
                }
            }
            instance = instanceTreeIt.instance;
        } else {
            instance = entityIterable;
            sourceTree = queryTree;
        }
        this.entityType = entityType;
        optimizedTree = null;
    }