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 { elementClass = JpaMetamodelUtils.resolveKeyClass(entityBaseClass, (MapAttribute<?, ?, ?>) valuesLikeAttribute.getAttribute()); } else { valuesLikeAttribute = extendedManagedType.getAttribute(attributeName); elementClass = valuesLikeAttribute.getElementClass(); valuesLikeClause = ((EntityType<?>) extendedManagedType.getType()).getName() + "." + attributeName; qualificationExpression = null; if (valuesLikeAttribute.getAttribute() instanceof SingularAttribute<?, ?>) { singular = true; if (((SingularAttribute<?, ?>) valuesLikeAttribute.getAttribute()).getType() instanceof BasicType<?>) { if (valuesLikeAttribute.getColumnTypes().length != 1) { throw new IllegalArgumentException("Unsupported VALUES clause use with multi-column attribute type " + Arrays.toString(valuesLikeAttribute.getColumnTypes()) + "! Consider creating a synthetic type like a @CTE entity to hold this attribute and use that type via fromIdentifiableValues instead!"); return fromValuesLike(entityBaseClass, elementClass, valuesLikeAttribute.getColumnTypes()[0], alias, valueCount, valuesLikeClause, valuesLikeAttribute, true, null); Map<String, String> keyColumnTypes = valuesLikeAttribute.getJoinTable().getKeyColumnTypes(); if (keyColumnTypes.size() != 1) { throw new IllegalArgumentException("Unsupported VALUES clause use with multi-column attribute type " + keyColumnTypes.values() + "! Consider creating a synthetic type like a @CTE entity to hold this attribute and use that type via fromIdentifiableValues instead!"); return fromValuesLike(entityBaseClass, elementClass, columnType, alias, valueCount, valuesLikeClause, valuesLikeAttribute, false, qualificationExpression); } else { if (((PluralAttribute<?, ?, ?>) valuesLikeAttribute.getAttribute()).getElementType() instanceof BasicType<?>) {
private static void removeRequiredUpdatableAttribute(Set<String> requiredUpdatableAttributes, Set<String> mappedColumns, ExtendedManagedType<?> extendedManagedType, String mapping) { requiredUpdatableAttributes.remove(mapping); ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttributes().get(mapping); if (extendedAttribute != null) { mappedColumns.addAll(Arrays.asList(extendedAttribute.getColumnNames())); for (ExtendedAttribute<?, ?> columnEquivalentAttribute : extendedAttribute.getColumnEquivalentAttributes()) { requiredUpdatableAttributes.remove(columnEquivalentAttribute.getAttributePathString()); } if (extendedAttribute.getAttribute() instanceof SingularAttribute<?, ?>) { SingularAttribute<?, ?> singularAttribute = (SingularAttribute<?, ?>) extendedAttribute.getAttribute(); if (singularAttribute.getType() instanceof EmbeddableType<?>) { for (String embeddedPropertyName : JpaMetamodelUtils.getEmbeddedPropertyNames((EmbeddableType<?>) singularAttribute.getType())) { removeRequiredUpdatableAttribute(requiredUpdatableAttributes, mappedColumns, extendedManagedType, mapping + "." + embeddedPropertyName); } } } } }
protected boolean determineForcedUnique(MetamodelBuildingContext context) { if (isCollection() && getMapping() != null && getMapping().indexOf('.') == -1) { ExtendedManagedType<?> managedType = context.getEntityMetamodel().getManagedType(ExtendedManagedType.class, getDeclaringType().getJpaManagedType()); ExtendedAttribute<?, ?> attribute = managedType.getOwnedAttributes().get(getMapping()); if (attribute != null && attribute.getAttribute() instanceof javax.persistence.metamodel.PluralAttribute<?, ?, ?>) { // TODO: we should add that information to ExtendedAttribute return (((javax.persistence.metamodel.PluralAttribute<?, ?, ?>) attribute.getAttribute()).getCollectionType() != javax.persistence.metamodel.PluralAttribute.CollectionType.MAP) && (!StringUtils.isEmpty(attribute.getMappedBy()) || !attribute.isBag()) && (attribute.getJoinTable() == null || attribute.getJoinTable().getKeyColumnMappings() == null) && !MetamodelUtils.isIndexedList(context.getEntityMetamodel(), context.getExpressionFactory(), managedType.getType().getJavaType(), getMapping()); } } return false; }
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 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; }
Map.Entry<String, ExtendedAttribute> entry = iterator.next(); ExtendedAttribute attributeEntry = entry.getValue(); JoinTable joinTable = attributeEntry.getJoinTable(); if (joinTable == null && !"".equals(attributeEntry.getMappedBy()) && (entityMetamodel.getEntity(attributeEntry.getElementClass()) == null || !attributeEntry.isDeleteCascaded())) { iterator.remove(); ExtendedAttribute extendedAttribute = entry.getValue(); UnmappedAttributeCascadeDeleter deleter; if (extendedAttribute.getAttribute().isCollection()) { if ("".equals(extendedAttribute.getMappedBy())) { ExtendedManagedType managedType = entityMetamodel.getManagedType(ExtendedManagedType.class, extendedAttribute.getElementClass()); deleter = new UnmappedWritableBasicAttributeSetNullCascadeDeleter(evm, managedType, extendedAttribute.getWritableMappedByMappings((EntityType<?>) managedType.getType())); } else { if (((javax.persistence.metamodel.PluralAttribute<?, ?, ?>) extendedAttribute.getAttribute()).getCollectionType() == javax.persistence.metamodel.PluralAttribute.CollectionType.MAP) { deleter = new UnmappedMapAttributeCascadeDeleter(evm, unmappedAttributeName, extendedAttribute, entityClass, idAttributeName, false); } else { if ("".equals(extendedAttribute.getMappedBy())) { ExtendedManagedType managedType = entityMetamodel.getManagedType(ExtendedManagedType.class, extendedAttribute.getElementClass()); deleter = new UnmappedWritableBasicAttributeSetNullCascadeDeleter(evm, managedType, extendedAttribute.getWritableMappedByMappings((EntityType<?>) managedType.getType())); } else { deleter = new UnmappedBasicAttributeCascadeDeleter(evm, unmappedAttributeName, extendedAttribute, idAttributeName, false);
OUTER: for (Map.Entry<String, ? extends ExtendedAttribute<?, ?>> entry : extendedManagedType.getOwnedSingularAttributes().entrySet()) { ExtendedAttribute<?, ?> extendedAttribute = entry.getValue(); SingularAttribute<?, ?> attribute = (SingularAttribute<?, ?>) extendedAttribute.getAttribute(); if (!attribute.isVersion() && !attribute.isOptional()) { if ((attribute.getType() instanceof BasicType<?> || attribute.getType() instanceof EmbeddableType<?>) && extendedAttribute.getAttributePath().size() > 1) { List<Attribute<?, ?>> attributePath = extendedAttribute.getAttributePath(); if (extendedAttribute == null || mappedColumns.containsAll(Arrays.asList(extendedAttribute.getColumnNames()))) { iterator.remove(); ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttributes().get(iterator.next()); try { SingularAttribute<? super Object, ?> version = ((IdentifiableType<Object>) jpaManagedType).getVersion(extendedAttribute.getElementClass()); if (extendedAttribute.getAttributePathString().equals(version.getName())) { iterator.remove();
entry = mapping.get(attributes[i]); Attribute attribute = entry.getAttribute(); String[] columnTypes; if (valuesNode.getQualificationExpression() == null) { columnTypes = entry.getColumnTypes(); } else { Collection<String> types = entry.getJoinTable().getKeyColumnTypes().values(); columnTypes = types.toArray(new String[types.size()]); attribute.getPersistentAttributeType() != Attribute.PersistentAttributeType.EMBEDDED && valuesNode.getQualificationExpression() == null) { ManagedType<?> managedAttributeType = mainQuery.metamodel.getManagedType(entry.getElementClass()); if (managedAttributeType == null || mainQuery.jpaProvider.needsElementCollectionIdCutoff() && valuesNode.getValuesLikeAttribute() != null && mapping.get(valuesNode.getValuesLikeAttribute()).getAttribute().getPersistentAttributeType() == Attribute.PersistentAttributeType.ELEMENT_COLLECTION) { sb.append("e"); if (valuesNode.isValueClazzAttributeSingular()) {
Attribute attr = managedType.getAttribute(pathReference.getField()).getAttribute(); for (ExtendedAttribute<?, ?> columnEquivalentAttribute : managedType.getAttribute(associationNamePrefix + attribute).getColumnEquivalentAttributes()) { List<Attribute<?, ?>> attributePath = columnEquivalentAttribute.getAttributePath(); String attributeName; if (attributePath.size() == 1) {
final List<Attribute<?, ?>> attributePath = attributeEntry.getAttributePath(); final Attribute<?, ?> lastAttribute = attributePath.get(attributePath.size() - 1); boolean splitExpression = lastAttribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED; if (attributeEntry.getElementClass() != baseExpression.getPathReference().getType().getJavaType()) { throw new IllegalStateException("An association should be bound to its association type and not its identifier type"); for (String column : nestedAttributeEntry.getColumnNames()) { columnBindingMap.put(column, nestedAttributePath); selectManager.select(new ParameterExpression(subParamName), null, tupleIndex + offset); for (String column : nestedAttributeEntry.getColumnNames()) { columnBindingMap.put(column, nestedAttributePath); parameterManager.getParameter(parameterName).setTranformer(new SplittingParameterTransformer(parameterManager, metamodel, attributeEntry.getElementClass(), parameterAccessPaths));
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(' '); sb.append(" JOIN "); sb.append(node.getAlias()); sb.append('.').append(attribute.getMappedBy()); sb.append(" _synthetic_"); sb.append(node.getAlias()); } else { whereSb.append(node.getAlias()); whereSb.append('.').append(attribute.getMappedBy());
Attribute<?, ?> attr = extendedAttribute.getAttribute(); boolean resolve = false; if (ExpressionUtils.isAssociation(attr) && !attr.isCollection()) { List<PathElementExpression> paths = new ArrayList<>(expression.getExpressions().size() + 1); paths.addAll(expression.getExpressions()); for (Attribute<?, ?> attribute : extendedAttribute.getAttributePath()) { paths.add(new PropertyExpression(attribute.getName())); attrPath.setPathReference(new SimplePathReference(rootNode, propertyPath, m.type(extendedAttribute.getElementClass()))); pathExpressions.add(attrPath);
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);
if (entry.getKey().startsWith(prefix)) { if (filterCollections) { List<Attribute<?, ?>> attributePath = entry.getValue().getAttributePath(); for (int i = dotCount; i < attributePath.size(); i++) { if (attributePath.get(i).isCollection()) { embeddedPropertyNames.remove(attributeName); if (needsElementCollectionIdCutoff && attributeEntries.get(attributeName).getAttribute().getPersistentAttributeType() == Attribute.PersistentAttributeType.ELEMENT_COLLECTION) { Iterator<String> iterator = embeddedPropertyNames.iterator(); List<String> addProperties = new ArrayList<>();
Class<?> cteAttrType = attributeEntry.getElementClass(); throw new IllegalArgumentException("The cte attribute [" + cteAttribute + "] has already been bound!"); for (String column : attributeEntry.getColumnNames()) { if (columnBindingMap.put(column, cteAttribute) != null) { throw new IllegalArgumentException("The cte column [" + column + "] has already been bound!");
if (extendedAttribute.getAttribute().isCollection()) { if (((javax.persistence.metamodel.PluralAttribute<?, ?, ?>) extendedAttribute.getAttribute()).getCollectionType() == javax.persistence.metamodel.PluralAttribute.CollectionType.MAP) { deleters.add(new UnmappedMapAttributeCascadeDeleter( evm, )); } else if (extendedAttribute.getAttribute().isAssociation() && extendedAttribute.isDeleteCascaded()) { deleters.add(new UnmappedBasicAttributeCascadeDeleter( evm,
protected List<String> prepareAndGetColumnNames() { StringBuilder sb = null; for (ExtendedAttribute entry : attributeEntries.values()) { for (String column : entry.getColumnNames()) { if (!columnBindingMap.containsKey(column)) { if (sb == null) { sb = new StringBuilder(); sb.append("["); } else { sb.append(", "); } sb.append(column); } } } if (sb != null) { sb.insert(0, "The following column names have not been bound: "); sb.append("]"); throw new IllegalStateException(sb.toString()); } return new ArrayList<>(columnBindingMap.keySet()); }
public AbstractUnmappedAttributeCascadeDeleter(EntityViewManagerImpl evm, String attributeName, ExtendedAttribute<?, ?> attribute) { EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel(); this.elementEntityClass = attribute.getElementClass(); this.attributeName = attributeName; if (entityMetamodel.getEntity(elementEntityClass) == null) { this.elementIdAttributeName = null; this.attributeValuePath = attributeName; this.cascadeDeleteElement = false; } else { ExtendedManagedType extendedManagedType = entityMetamodel.getManagedType(ExtendedManagedType.class, elementEntityClass); this.elementIdAttributeName = extendedManagedType.getIdAttribute().getName(); this.attributeValuePath = attributeName + "." + elementIdAttributeName; this.cascadeDeleteElement = attribute.isDeleteCascaded(); } }
if (extendedAttribute != null && StringUtils.isEmpty(extendedAttribute.getMappedBy())) { ExtendedManagedType<?> managedType = metamodel.getManagedType(ExtendedManagedType.class, (ManagedType<?>) singularAttribute.getType()); for (String attrName : attributeNames) { addAttributes(ownerType, elementCollectionPath, fieldPrefix, newPrefix, (SingularAttribute<?, ?>) managedType.getAttributes().get(attrName).getAttribute(), orderedAttributes);
&& (attribute = managedType.getOwnedAttributes().get(this.mapping.substring(0, index))) != null && !StringUtils.isEmpty(attribute.getMappedBy())) { this.correlated = attribute.getElementClass(); this.correlationExpression = attribute.getMappedBy() + " IN __correlationAlias"; this.correlationResult = this.mapping.substring(index + 1); } else if (attribute != null && !StringUtils.isEmpty(attribute.getMappedBy())) { this.correlated = attribute.getElementClass(); this.correlationExpression = attribute.getMappedBy() + " IN __correlationAlias"; this.correlationResult = ""; } else {