protected String[] getReturningColumns() { if (returningAttributeBindingMap.isEmpty()) { return null; } Collection<String> returningAttributeNames = returningAttributeBindingMap.values(); List<String> columns = new ArrayList<String>(returningAttributeNames.size()); for (String returningAttributeName : returningAttributeBindingMap.values()) { for (String column : mainQuery.metamodel.getManagedType(ExtendedManagedType.class, entityType.getJavaType()).getAttribute(returningAttributeName).getColumnNames()) { columns.add(column); } } return columns.toArray(new String[columns.size()]); }
public static Map<String, ExtendedAttribute<?, ?>> getCollectionAttributeEntries(EntityMetamodel metamodel, EntityType<?> entityType, ExtendedAttribute<?, ?> attribute) { Map<String, ExtendedAttribute<?, ?>> collectionAttributeEntries = new HashMap<>(); JoinTable joinTable = attribute.getJoinTable(); if (joinTable == null) { throw new IllegalArgumentException("No support for inserting into inverse collection via DML API yet!"); } ExtendedManagedType<?> extendedManagedType = metamodel.getManagedType(ExtendedManagedType.class, entityType); for (String idAttributeName : joinTable.getIdAttributeNames()) { collectionAttributeEntries.put(idAttributeName, extendedManagedType.getAttribute(idAttributeName)); } if (((PluralAttribute<?, ?, ?>) attribute.getAttribute()).getElementType() instanceof ManagedType<?>) { String prefix = attribute.getAttributePathString() + "."; for (Map.Entry<String, ? extends ExtendedAttribute<?, ?>> entry : extendedManagedType.getAttributes().entrySet()) { if (entry.getKey().startsWith(prefix)) { collectionAttributeEntries.put(entry.getKey(), entry.getValue()); } } } collectionAttributeEntries.put(attribute.getAttributePathString(), attribute); return collectionAttributeEntries; }
@Override public Map<String, String> getWritableMappedByMappings(EntityType<?> inverseType, EntityType<?> ownerType, String attributeName, String inverseAttribute) { if (attributeName.isEmpty()) { return entityMetamodel.getManagedType(ExtendedManagedType.class, inverseType).getAttribute(inverseAttribute).getWritableMappedByMappings(ownerType); } else { return entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType).getAttribute(attributeName).getWritableMappedByMappings(inverseType); } }
Attribute attr = managedType.getAttribute(field).getAttribute(); extendedManagedType = metamodel.getManagedType(ExtendedManagedType.class, baseNode.getManagedType().getJavaType()); ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttribute(associationName); Attribute<?, ?> attribute = extendedAttribute.getAttribute(); baseNodeKey = new AbstractMap.SimpleEntry<>(baseNode, associationName); String singleNonConstantifiedAttribute = getSingleNonConstantifiedAttribute(orderedAttributes); if (singleNonConstantifiedAttribute != null && (singleNonConstantifiedAttribute.isEmpty() || equalsAny(singleNonConstantifiedAttribute, extendedManagedType.getAttribute(expr.getField()).getColumnEquivalentAttributes()))) { nonConstantParent = false; orderedAttributes.clear(); String singleNonConstantifiedAttribute = getSingleNonConstantifiedAttribute(orderedAttributes); if (singleNonConstantifiedAttribute != null && (singleNonConstantifiedAttribute.isEmpty() || extendedManagedType.getAttributes().containsKey(subPath) && equalsAny(singleNonConstantifiedAttribute, extendedManagedType.getAttribute(subPath).getColumnEquivalentAttributes()))) { continue;
if (returningAttribute.get(i).isCollection()) { sb.setLength(sb.length() - 1); joinTable = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, entityType.getJavaType()).getAttribute(sb.toString()).getJoinTable(); sb.setLength(0); for (String column : mainQuery.metamodel.getManagedType(ExtendedManagedType.class, entityType.getJavaType()).getAttribute(sb.toString()).getColumnNames()) { columns.add(column);
@Override public String[] getColumnNames(EntityType<?> ownerType, String attributeName) { return entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType.getName()).getAttribute(attributeName).getColumnNames(); }
@Override public JoinTable getJoinTable(EntityType<?> ownerType, String attributeName) { return entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType.getName()).getAttribute(attributeName).getJoinTable(); }
@Override public String[] getColumnTypes(EntityType<?> ownerType, String attributeName) { return entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType.getName()).getAttribute(attributeName).getColumnTypes(); }
@Override public String getMappedBy(EntityType<?> ownerType, String attributeName) { return entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType.getName()).getAttribute(attributeName).getMappedBy(); }
public AbstractInsertCollectionCriteriaBuilder(MainQuery mainQuery, QueryContext queryContext, boolean isMainQuery, Class<T> clazz, String cteName, Class<?> cteClass, Y result, CTEBuilderListener listener, String collectionName) { super(mainQuery, queryContext, isMainQuery, clazz, cteName, cteClass, result, listener); this.collectionName = collectionName; ExtendedManagedType<?> extendedManagedType = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, entityType); ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttribute(collectionName); Map<String, ExtendedAttribute<?, ?>> collectionAttributeEntries = JpaUtils.getCollectionAttributeEntries(mainQuery.metamodel, entityType, extendedAttribute); if (extendedAttribute.getAttribute() instanceof MapAttribute<?, ?, ?>) { keyFunctionExpression = "key(" + collectionName + ")"; } else if (extendedAttribute.getAttribute() instanceof ListAttribute<?, ?> && !extendedAttribute.isBag()) { keyFunctionExpression = "index(" + collectionName + ")"; } else { keyFunctionExpression = null; } this.collectionColumnBindingMap = new LinkedHashMap<>(collectionAttributeEntries.size()); this.collectionAttributeEntries = collectionAttributeEntries; }
public AbstractUpdateCollectionCriteriaBuilder(MainQuery mainQuery, QueryContext queryContext, boolean isMainQuery, Class<T> clazz, String alias, String cteName, Class<?> cteClass, Y result, CTEBuilderListener listener, String collectionName) { super(mainQuery, queryContext, isMainQuery, clazz, alias, cteName, cteClass, result, listener); this.collectionName = collectionName; // Add the join here so that references in the where clause go the the expected join node // Also, this validates the collection actually exists joinManager.join(entityAlias + "." + collectionName, CollectionUpdateModificationQuerySpecification.COLLECTION_BASE_QUERY_ALIAS, JoinType.LEFT, false, true); ExtendedManagedType<?> extendedManagedType = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, entityType); ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttribute(collectionName); Map<String, ExtendedAttribute<?, ?>> collectionAttributeEntries = JpaUtils.getCollectionAttributeEntries(mainQuery.metamodel, entityType, extendedAttribute); if (extendedAttribute.getAttribute() instanceof MapAttribute<?, ?, ?>) { keyFunctionExpression = "key(" + collectionName + ")"; } else if (extendedAttribute.getAttribute() instanceof ListAttribute<?, ?> && !mainQuery.jpaProvider.isBag(entityType, collectionName)) { keyFunctionExpression = "index(" + collectionName + ")"; } else { keyFunctionExpression = null; } this.collectionColumnBindingMap = new LinkedHashMap<>(collectionAttributeEntries.size()); this.collectionAttributeEntries = collectionAttributeEntries; }
ExtendedAttribute valuesLikeAttribute = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, ValuesEntity.class).getAttribute("value"); ExtendedAttribute valuesLikeAttribute = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, valueHolderEntityClass).getAttribute(valuesLikeAttributeName); prepareFromModification(); joinManager.addRootValues(valueHolderEntityClass, valueClass, alias, valueCount, null, null, false, singular, valuesLikeAttributeName, valuesLikeAttribute, null, null);
Attribute attr = managedType.getAttribute(pathReference.getField()).getAttribute(); for (ExtendedAttribute<?, ?> columnEquivalentAttribute : managedType.getAttribute(associationNamePrefix + attribute).getColumnEquivalentAttributes()) { List<Attribute<?, ?>> attributePath = columnEquivalentAttribute.getAttributePath(); String attributeName;
String[] columns = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, cteInfo.cteType.getJavaType()).getAttribute(columnNames.get(i)).getColumnNames(); for (String column : columns) { list.add(column);
if (attributeName.regionMatches(true, 0, keyFunction, 0, keyFunction.length())) { attributeName = attributeName.substring(keyFunction.length(), attributeName.length() - 1); valuesLikeAttribute = extendedManagedType.getAttribute(attributeName); index = true; if (valuesLikeAttribute.getAttributePath().size() > 1) { ExtendedAttribute<?, ?> superAttr = extendedManagedType.getAttribute(valuesLikeAttribute.getAttributePathString().substring(0, valuesLikeAttribute.getAttributePathString().lastIndexOf('.'))); elementClass = JpaMetamodelUtils.resolveKeyClass(superAttr.getElementClass(), (MapAttribute<?, ?, ?>) valuesLikeAttribute.getAttribute()); } else { } else if (attributeName.regionMatches(true, 0, indexFunction, 0, indexFunction.length())) { attributeName = attributeName.substring(indexFunction.length(), attributeName.length() - 1); valuesLikeAttribute = extendedManagedType.getAttribute(attributeName); index = true; elementClass = Integer.class; qualificationExpression = "INDEX"; } else { valuesLikeAttribute = extendedManagedType.getAttribute(attributeName); elementClass = valuesLikeAttribute.getElementClass(); valuesLikeClause = ((EntityType<?>) extendedManagedType.getType()).getName() + "." + attributeName;
if (mainQuery.jpaProvider.needsCorrelationPredicateWhenCorrelatingWithWhereClause() || node.getTreatType() != null && !renderTreat && !mainQuery.jpaProvider.supportsSubtypeRelationResolving()) { ExtendedManagedType<?> extendedManagedType = metamodel.getManagedType(ExtendedManagedType.class, node.getCorrelationParent().getManagedType()); ExtendedAttribute attribute = extendedManagedType.getAttribute(node.getCorrelationPath()); if (StringUtils.isEmpty(attribute.getMappedBy())) { if (attribute.getAttribute() instanceof ListAttribute<?, ?> && !attribute.isBag()) { StringBuilder whereSb = new StringBuilder(); ExtendedManagedType elementManagedType = metamodel.getManagedType(ExtendedManagedType.class, node.getManagedType()); if (elementManagedType.getAttribute(attribute.getMappedBy()).getAttribute().isCollection()) { renderAlias = false; sb.append(' ');
ManagedType<?> managedType = baseNode.getManagedType(); ExtendedManagedType extendedManagedType = metamodel.getManagedType(ExtendedManagedType.class, JpaMetamodelUtils.getTypeName(managedType)); Attribute<?, ?> attr = extendedManagedType.getAttribute(expr.getField()).getAttribute(); Attribute<?, ?> associationAttribute = extendedManagedType.getAttribute(associationName).getAttribute(); if (isNullable(associationAttribute)) {
attr = managedType.getAttribute(pathReference.getField()).getAttribute();
evm, mapping, elementManagedType.getAttribute(mapping), mapping + "." + entityIdAttributeName, false
AttributeAccessor entityAttributeAccessor = Accessors.forEntityMapping(evm, attribute); boolean cascadeDelete = attribute.isDeleteCascaded(); boolean viewOnlyDeleteCascaded = cascadeDelete && !entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass).getAttribute(attributeMapping).isDeleteCascaded(); boolean optimisticLockProtected = attribute.isOptimisticLockProtected(); JpaProvider jpaProvider = evm.getJpaProvider();