protected String treatJoinWhereFragment(Class<?> sourceType, String attribute, String alias, Class<?> type, JoinType joinType, String whereFragment) { JpaProvider.ConstraintType constraintType = jpaProvider.requiresTreatFilter(em.getMetamodel().entity(sourceType), attribute, joinType); if (constraintType != JpaProvider.ConstraintType.WHERE) { return whereFragment == null ? "" : whereFragment; } String constraint = "TYPE(" + alias + ") = " + type.getSimpleName(); if (whereFragment == null || whereFragment.isEmpty()) { return " WHERE " + constraint; } else { return whereFragment + " AND " + constraint; } }
protected String treatJoinWhereFragment(Class<?> sourceType, String attribute, String alias, Class<?> type, JoinType joinType, String whereFragment) { JpaProvider.ConstraintType constraintType = jpaProvider.requiresTreatFilter(em.getMetamodel().entity(sourceType), attribute, joinType); if (constraintType != JpaProvider.ConstraintType.WHERE) { return whereFragment == null ? "" : whereFragment; } String constraint = "TYPE(" + alias + ") = " + type.getSimpleName(); if (whereFragment == null || whereFragment.isEmpty()) { return " WHERE " + constraint; } else { return whereFragment + " AND " + constraint; } }
protected String treatRootTreatJoin(JoinType joinType, String path, Class<?> type, String property, Class<?> type2, String alias) { String joinPrefix; if (joinType == JoinType.INNER) { joinPrefix = "JOIN "; } else if (joinType == JoinType.LEFT) { joinPrefix = "LEFT JOIN "; } else if (joinType == JoinType.RIGHT) { joinPrefix = "RIGHT JOIN "; } else { throw new IllegalArgumentException("Invalid join type: " + joinType); } if (jpaProvider.supportsRootTreatTreatJoin()) { return joinPrefix + "TREAT(TREAT(" + path + " AS " + type.getSimpleName() + ")." + property + " AS " + type2.getSimpleName() + ") " + alias; } else if (jpaProvider.supportsSubtypeRelationResolving()) { if (jpaProvider.supportsTreatJoin() && joinType == JoinType.INNER) { String joinPath = joinPrefix + "TREAT(" + path + "." + property + " AS " + type2.getSimpleName() + ") " + alias; JpaProvider.ConstraintType constraintType = jpaProvider.requiresTreatFilter(em.getEntityManagerFactory().getMetamodel().entity(type), property, joinType); if (constraintType == JpaProvider.ConstraintType.ON) { return joinPath + ON_CLAUSE + "TYPE(" + alias + ") = " + type2.getSimpleName(); } else { return joinPath; } } else { return joinPrefix + path + "." + property + " " + alias; } } throw new IllegalArgumentException("Treat should not be used as the JPA provider does not support subtype property access!"); }
protected String treatRootTreatJoin(JoinType joinType, String path, Class<?> type, String property, Class<?> type2, String alias) { String joinPrefix; if (joinType == JoinType.INNER) { joinPrefix = "JOIN "; } else if (joinType == JoinType.LEFT) { joinPrefix = "LEFT JOIN "; } else if (joinType == JoinType.RIGHT) { joinPrefix = "RIGHT JOIN "; } else { throw new IllegalArgumentException("Invalid join type: " + joinType); } if (jpaProvider.supportsRootTreatTreatJoin()) { return joinPrefix + "TREAT(TREAT(" + path + " AS " + type.getSimpleName() + ")." + property + " AS " + type2.getSimpleName() + ") " + alias; } else if (jpaProvider.supportsSubtypeRelationResolving()) { if (jpaProvider.supportsTreatJoin() && joinType == JoinType.INNER) { String joinPath = joinPrefix + "TREAT(" + path + "." + property + " AS " + type2.getSimpleName() + ") " + alias; JpaProvider.ConstraintType constraintType = jpaProvider.requiresTreatFilter(em.getEntityManagerFactory().getMetamodel().entity(type), property, joinType); if (constraintType == JpaProvider.ConstraintType.ON) { return joinPath + ON_CLAUSE + "TYPE(" + alias + ") = " + type2.getSimpleName(); } else { return joinPath; } } else { return joinPrefix + path + "." + property + " " + alias; } } throw new IllegalArgumentException("Treat should not be used as the JPA provider does not support subtype property access!"); }
final String treatType = node.getTreatType().getName(); final String relationName = node.getParentTreeNode().getRelationName(); JpaProvider.ConstraintType constraintType = mainQuery.jpaProvider.requiresTreatFilter(baseNode.getEntityType(), relationName, node.getJoinType()); if (constraintType != JpaProvider.ConstraintType.NONE) { String constraint = "TYPE(" + node.getAlias() + ") = " + treatType;
this.columnTypes = jpaProvider.getColumnTypes(entityType, attributeName); for (JoinType joinType : joinTypes) { requiresTreatFilter[joinType.ordinal()] = jpaProvider.requiresTreatFilter(entityType, attributeName, joinType);