this.elementClass = fieldType; if (elementCollectionPath == null) { this.isOrphanRemoval = jpaProvider.isOrphanRemoval(ownerType, attributeName); this.isDeleteCascaded = jpaProvider.isDeleteCascaded(ownerType, attributeName); } else { this.isOrphanRemoval = jpaProvider.isOrphanRemoval(ownerType, elementCollectionPath, attributeName); this.isDeleteCascaded = jpaProvider.isDeleteCascaded(ownerType, elementCollectionPath, attributeName); EntityType<?> entityType = (EntityType<?>) ownerType; if (elementCollectionPath == null) { this.isForeignJoinColumn = jpaProvider.isForeignJoinColumn(entityType, attributeName); this.isColumnShared = jpaProvider.isColumnShared(entityType, attributeName); this.isBag = jpaProvider.isBag(entityType, attributeName); this.mappedBy = jpaProvider.getMappedBy(entityType, attributeName); this.joinTable = jpaProvider.getJoinTable(entityType, attributeName); this.columnNames = jpaProvider.getColumnNames(entityType, attributeName); this.columnTypes = jpaProvider.getColumnTypes(entityType, attributeName); for (JoinType joinType : joinTypes) { requiresTreatFilter[joinType.ordinal()] = jpaProvider.requiresTreatFilter(entityType, attributeName, joinType); this.mappedBy = null; this.joinTable = null; this.columnNames = jpaProvider.getColumnNames(entityType, elementCollectionPath, attributeName); this.columnTypes = jpaProvider.getColumnTypes(entityType, elementCollectionPath, attributeName); for (JoinType joinType : joinTypes) { requiresTreatFilter[joinType.ordinal()] = JpaProvider.ConstraintType.NONE;
@Override public boolean containsEntity(EntityManager em, Class<?> entityClass, Object id) { return jpaProvider.containsEntity(em, entityClass, id); }
@Override protected String escapeCharacter(char character) { return jpaProvider.escapeCharacter(character); }
private static String joinAliasValue(JpaProvider provider, String alias, String field) { if (provider.getCollectionValueFunction() != null && (field == null || provider.supportsCollectionValueDereference())) { alias = provider.getCollectionValueFunction() + "(" + alias + ")"; } if (field == null) { return alias; } return alias + "." + field; }
super.visit(expression); } else { boolean valueFunction = needsValueFunction(expression, baseNode, field) && jpaProvider.getCollectionValueFunction() != null; sb.append(jpaProvider.getCollectionValueFunction()); sb.append('('); boolean addTypeCaseWhen = !treatedJoinNodes.isEmpty() && baseNodeType instanceof EntityType<?> && jpaProvider.needsTypeConstraintForColumnSharing() && jpaProvider.isColumnShared((EntityType<?>) baseNodeType, field); if (addTypeCaseWhen) { sb.append("CASE WHEN "); if (jpaProvider.supportsTreatJoin() && treatedJoinNode.isTreatJoinNode()) { continue; boolean valueFunction = needsValueFunction(expression, baseNode, field) && jpaProvider.getCollectionValueFunction() != null; boolean renderTreat = jpaProvider.supportsRootTreat(); sb.append(jpaProvider.getCollectionValueFunction()); sb.append('('); baseNode.appendDeReference(sb, field, renderTreat, externalRepresentation, jpaProvider.needsElementCollectionIdCutoff());
@Override public JpaMetamodelAccessor getJpaMetamodelAccessor() { return jpaProvider.getJpaMetamodelAccessor(); } }
protected String function(String name, String... args) { String registeredFunctionName; if ((registeredFunctionName = resolveRegisteredFunctionName(name)) != null) { StringBuilder sb = new StringBuilder(); sb.append(jpaProvider.getCustomFunctionInvocation(registeredFunctionName, args.length)); StringUtils.join(sb, ",", args); sb.append(')'); return sb.toString(); } else if (jpaProvider.supportsJpa21()) { StringBuilder sb = new StringBuilder(); sb.append("FUNCTION('").append(name).append('\''); for (String arg : args) { sb.append(",").append(arg); } sb.append(')'); return sb.toString(); } else { throw new IllegalArgumentException("Invalid JPA provider which does not support function syntax!"); } }
String ownerAlias = extendedQuerySupport.getSqlAlias(em, baseQuery, entityAlias); String targetAlias = extendedQuerySupport.getSqlAlias(em, baseQuery, CollectionUpdateModificationQuerySpecification.COLLECTION_BASE_QUERY_ALIAS); JoinTable joinTable = mainQuery.jpaProvider.getJoinTable(entityType, collectionName); int joinTableIndex = SqlUtils.indexOfTableName(sql, joinTable.getTableName()); String collectionAlias = SqlUtils.extractAlias(sql, joinTableIndex + joinTable.getTableName().length()); Map<String, String> columnExpressionRemappings = new HashMap<>(); String[] discriminatorColumnCheck = mainQuery.jpaProvider.getDiscriminatorColumnCheck(entityType); String discriminatorPredicate = ""; if (discriminatorColumnCheck != null) {
private void visitKeyOrIndexExpression(PathExpression pathExpression) { JoinNode node = (JoinNode) pathExpression.getBaseNode(); Attribute<?, ?> attribute = node.getParentTreeNode().getAttribute(); // Exclude element collections as they are not problematic if (!jpaProvider.getJpaMetamodelAccessor().isElementCollection(attribute)) { // There are weird mappings possible, we have to check if the attribute is a join table if (jpaProvider.getJoinTable(node.getParent().getEntityType(), attribute.getName()) != null) { keyRestrictedLeftJoins.add(node); } } } }
@Override public boolean shouldPersist(Object entity) { return entity != null && jpaProvider.getIdentifier(entity) == null; }
@Override public List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames(EntityType<?> owner, String attributeName) { // TODO: cache this via extended metamodel return jpaProvider.getIdentifierOrUniqueKeyEmbeddedPropertyNames(owner, attributeName); }
protected void clearCollections(EntityManager em, Class<?>... entityClasses) { for (Class<?> c : entityClasses) { List<String> deletes = PLURAL_DELETES.get(c); if (deletes == null) { Metamodel entityMetamodel = cbf.getService(Metamodel.class); EntityType<?> t = entityMetamodel.entity(c); deletes = new ArrayList<>(); for (PluralAttribute<?, ?, ?> pluralAttribute : t.getPluralAttributes()) { JoinTable joinTable = jpaProvider.getJoinTable(t, pluralAttribute.getName()); if (joinTable != null) { deletes.add("delete from " + joinTable.getTableName()); } } PLURAL_DELETES.put(c, deletes); } for (String delete : deletes) { em.createNativeQuery(delete).executeUpdate(); } } }
boolean isResultUnique; if (countAll) { if (mainQuery.jpaProvider.supportsCountStar()) { sbSelectFrom.append("COUNT(*)"); } else { sbSelectFrom.append(mainQuery.jpaProvider.getCustomFunctionInvocation("count_star", 0)).append(')'); sbSelectFrom.append(mainQuery.jpaProvider.getCustomFunctionInvocation(AbstractCountFunction.FUNCTION_NAME, 1)); sbSelectFrom.append("'DISTINCT',"); if (mainQuery.jpaProvider.supportsCountStar()) { countStar = "COUNT(*"; } else { countStar = mainQuery.jpaProvider.getCustomFunctionInvocation("count_star", 0);
AttributePath basicAttributePath = context.getJpaProvider().getJpaMetamodelAccessor().getAttributePath(context.getEntityMetamodel(), managedType, mapping); List<Attribute<?, ?>> attributes = basicAttributePath.getAttributes(); for (int i = 1; i < attributes.size(); i++) { mappedBy = context.getJpaProvider().getMappedBy((EntityType<?>) managedType, mapping); if (embeddableMapping == null) { this.mappedBy = mappedBy;
@Override public String getBooleanConditionalExpression(boolean value) { return jpaProvider.getBooleanConditionalExpression(value); }
@Override public String getCustomFunctionInvocation(String functionName, int argumentCount) { return jpaProvider.getCustomFunctionInvocation(functionName, argumentCount); }
JpaProvider jpaProvider = queryBuilder.mainQuery.jpaProvider; EntityMetamodel metamodel = queryBuilder.mainQuery.metamodel; JpaMetamodelAccessor jpaMetamodelAccessor = jpaProvider.getJpaMetamodelAccessor(); boolean needsElementCollectionIdCutoff = jpaProvider.needsElementCollectionIdCutoff(); final Queue<String> attributeQueue = new ArrayDeque<>(bindingMap.keySet()); while (!attributeQueue.isEmpty()) { final Collection<String> embeddedPropertyNames = getEmbeddedPropertyPaths(attributeEntries, attributeName, jpaProvider.needsElementCollectionIdCutoff(), false);
final boolean isElementCollection = jpaProvider.getJpaMetamodelAccessor().isElementCollection(targetAttribute); jpaProvider.isBag((EntityType<?>) targetAttribute.getDeclaringType(), targetAttribute.getName()) || requiresBlacklistedNode(sizeArg) || aggregateFunctionContext;
@Override public String getCollectionValueFunction() { return jpaProvider.getCollectionValueFunction(); }
protected void addAttribute(String attributeName) { // Just do that to assert the attribute exists JpaMetamodelAccessor jpaMetamodelAccessor = mainQuery.jpaProvider.getJpaMetamodelAccessor(); jpaMetamodelAccessor.getBasicAttributePath(getMetamodel(), entityType, attributeName); Integer attributeBindIndex = setAttributeBindingMap.get(attributeName); if (attributeBindIndex != null) { throw new IllegalArgumentException("The attribute [" + attributeName + "] has already been bound!"); } setAttributeBindingMap.put(attributeName, selectManager.getSelectInfos().size()); }