public void addBatchPredicate(FullQueryBuilder<?, ?> criteriaBuilder) { if (viewRootExpression == CORRELATION_VIEW_ROOT_ALIAS) { criteriaBuilder.innerJoinOn(originalViewRootExpression, viewRootEntityType, CORRELATION_VIEW_ROOT_ALIAS) .on(originalViewRootExpression + "." + viewRootIdPath).eqExpression(CORRELATION_VIEW_ROOT_ALIAS + "." + viewRootIdPath) .end(); } }
onBuilder.setOnExpression(expression); } else { MultipleSubqueryInitiator<?> initiator = onBuilder.setOnExpressionSubqueries(expression);
@Override public void applyCorrelation(CorrelationBuilder correlationBuilder, String correlationExpression) { String alias = correlationBuilder.getCorrelationAlias(); // Exercise the parser first to resolve the view root ExpressionFactory expressionFactory = correlationBuilder.getService(ExpressionFactory.class); String expressionString = AbstractAttribute.replaceThisFromMapping(this.correlationExpression, alias); Expression expression = expressionFactory.createBooleanExpression(expressionString, false); // Find out the view root alias MacroFunction viewRootFunction = expressionFactory.getDefaultMacroConfiguration().get("VIEW_ROOT"); ViewRootJpqlMacro viewRootMacro = (ViewRootJpqlMacro) viewRootFunction.getState()[0]; // Prefix all paths except view root alias based ones and substitute the key alias with the correlation expression String aliasToSkip; if (viewRootMacro.getViewRoot() == null) { EmbeddingViewJpqlMacro embeddingViewJpqlMacro = (EmbeddingViewJpqlMacro) expressionFactory.getDefaultMacroConfiguration().get("EMBEDDING_VIEW").getState()[0]; aliasToSkip = embeddingViewJpqlMacro.getEmbeddingViewPath(); } else { aliasToSkip = viewRootMacro.getViewRoot(); } PrefixingAndAliasReplacementQueryGenerator generator = new PrefixingAndAliasReplacementQueryGenerator(alias, correlationExpression, correlationKeyAlias, aliasToSkip, true); StringBuilder buffer = new StringBuilder(approximateExpressionSize); generator.setQueryBuffer(buffer); expression.accept(generator); correlationBuilder.correlate(correlated) .setOnExpression(buffer.toString()); } }
onBuilder.setOnExpression(expression); } else { MultipleSubqueryInitiator<?> initiator = onBuilder.setOnExpressionSubqueries(expression);
@Override public void addBatchPredicate(FullQueryBuilder<?, ?> criteriaBuilder) { if (viewRootExpression == CORRELATION_EMBEDDING_VIEW_ALIAS) { criteriaBuilder.innerJoinOn(originalViewRootExpression, viewRootEntityType, CORRELATION_EMBEDDING_VIEW_ALIAS) .on(originalViewRootExpression + "." + viewRootIdPath).eqExpression(CORRELATION_EMBEDDING_VIEW_ALIAS + "." + viewRootIdPath) .end(); } }
public <T> List<T> getCatHierarchy(Integer catId, EntityViewSetting<T, CriteriaBuilder<T>> setting) { CriteriaBuilder<Tuple> cb = cbf.create(emHolder.getEntityManager(), Tuple.class) .withRecursive(CatHierarchyCTE.class) .from(Cat.class) .bind("id").select("id") .bind("motherId").select("mother.id") .bind("fatherId").select("father.id") .bind("generation").select("0") .where("id").eqExpression(catId.toString()) .unionAll() .from(Cat.class, "cat") .from(CatHierarchyCTE.class, "cte") .bind("id").select("cat.id") .bind("motherId").select("cat.mother.id") .bind("fatherId").select("cat.father.id") .bind("generation").select("cte.generation + 1") .whereOr() .where("cat.id").eqExpression("cte.motherId") .where("cat.id").eqExpression("cte.fatherId") .endOr() .end() .from(Cat.class, "cat") .innerJoinOn(CatHierarchyCTE.class, "cte").on("cte.id").eqExpression("cat.id").end() .orderByAsc("cte.generation"); return evm.applySetting(setting, cb).getResultList(); }
public <T> List<T> getCatHierarchy(Integer catId, EntityViewSetting<T, CriteriaBuilder<T>> setting) { CriteriaBuilder<Tuple> cb = cbf.create(emHolder.getEntityManager(), Tuple.class) .withRecursive(CatHierarchyCTE.class) .from(Cat.class) .bind("id").select("id") .bind("motherId").select("mother.id") .bind("fatherId").select("father.id") .bind("generation").select("0") .where("id").eqExpression(catId.toString()) .unionAll() .from(Cat.class, "cat") .from(CatHierarchyCTE.class, "cte") .bind("id").select("cat.id") .bind("motherId").select("cat.mother.id") .bind("fatherId").select("cat.father.id") .bind("generation").select("cte.generation + 1") .whereOr() .where("cat.id").eqExpression("cte.motherId") .where("cat.id").eqExpression("cte.fatherId") .endOr() .end() .from(Cat.class, "cat") .innerJoinOn(CatHierarchyCTE.class, "cte").on("cte.id").eqExpression("cat.id").end() .orderByAsc("cte.generation"); return evm.applySetting(setting, cb).getResultList(); }
public <T> List<T> getCatHierarchy(Integer catId, EntityViewSetting<T, CriteriaBuilder<T>> setting) { CriteriaBuilder<Tuple> cb = cbf.create(emHolder.getEntityManager(), Tuple.class) .withRecursive(CatHierarchyCTE.class) .from(Cat.class) .bind("id").select("id") .bind("motherId").select("mother.id") .bind("fatherId").select("father.id") .bind("generation").select("0") .where("id").eqExpression(catId.toString()) .unionAll() .from(Cat.class, "cat") .from(CatHierarchyCTE.class, "cte") .bind("id").select("cat.id") .bind("motherId").select("cat.mother.id") .bind("fatherId").select("cat.father.id") .bind("generation").select("cte.generation + 1") .whereOr() .where("cat.id").eqExpression("cte.motherId") .where("cat.id").eqExpression("cte.fatherId") .endOr() .end() .from(Cat.class, "cat") .innerJoinOn(CatHierarchyCTE.class, "cte").on("cte.id").eqExpression("cat.id").end() .orderByAsc("cte.generation"); return evm.applySetting(setting, cb).getResultList(); }