public UnmappedWritableBasicAttributeSetNullCascadeDeleter(EntityViewManagerImpl evm, ExtendedManagedType<?> extendedManagedType, Map<String, String> writableMappings) { this.ownerEntityClass = extendedManagedType.getType().getJavaType(); Map<String, String> removeByIdMappings = new HashMap<>(writableMappings.size()); Map<String, String> removeByOwnerIdMappings = new HashMap<>(writableMappings.size()); for (Map.Entry<String, String> entry : writableMappings.entrySet()) { String ownerIdAttribute = extendedManagedType.getIdAttribute().getName(); List<String> idAttributes = evm.getJpaProvider().getIdentifierOrUniqueKeyEmbeddedPropertyNames((EntityType<?>) extendedManagedType.getType(), entry.getValue()); removeByIdMappings.put(entry.getValue(), ownerIdAttribute); // NOTE: We ignore the fact that there might be multiple id attributes here because we currently support id class attributes yet anyway if (!idAttributes.isEmpty()) { removeByOwnerIdMappings.put(entry.getValue(), entry.getValue() + "." + idAttributes.get(0)); } } this.removeByIdMappings = removeByIdMappings; this.removeByOwnerIdMappings = removeByOwnerIdMappings; }
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()]); }
@Override public boolean isForeignJoinColumn(EntityType<?> ownerType, String attributeName) { ExtendedAttribute attribute = (ExtendedAttribute) entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType.getName()).getAttributes().get(attributeName); return attribute != null && attribute.isForeignJoinColumn(); }
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; }
ExtendedAttribute valuesLikeAttribute = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, ValuesEntity.class).getAttribute("value"); } else { ExtendedManagedType<?> extendedManagedType = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, valueClass); Map.Entry<? extends EntityType<?>, String> entry = extendedManagedType.getEmbeddableSingularOwner(); boolean singular = true; if (entry == null) { singular = false; entry = extendedManagedType.getEmbeddablePluralOwner(); 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);
entityIdAttributeName = evm.getMetamodel().getEntityMetamodel().getManagedType(ExtendedManagedType.class, type.getJavaType()).getIdAttribute().getName(); evm, mapping, elementManagedType.getAttribute(mapping), mapping + "." + entityIdAttributeName, false loadOnlyViewToEntityMapper = createLoadOnlyViewToEntityMapper(attributeLocation, evm, elementType, cascadePersist, cascadeUpdate, readOnlyAllowedSubtypes, persistAllowedSubtypes, updateAllowedSubtypes, owner, ownerMapping); identifiable = viewToEntityMapper.getViewIdAccessor() != null; SingularAttribute idAttribute = evm.getMetamodel().getEntityMetamodel().getManagedType(ExtendedManagedType.class, elementType.getEntityClass()).getIdAttribute(); if (idAttribute != null) { entityIdAttributeName = idAttribute.getName();
if (baseNode.getParentTreeNode() == null && field == null) { ownerType = baseNode.getEntityType(); for (SingularAttribute<?, ?> idAttribute : managedType.getIdAttributes()) { addAttributes(ownerType, null, fieldPrefix, "", idAttribute, orderedAttributes); String elementCollectionPath = baseNode.getParentTreeNode().getRelationName(); ExtendedManagedType entityManagedType = metamodel.getManagedType(ExtendedManagedType.class, baseNode.getParent().getEntityType()); ownedAttributes = entityManagedType.getAttributes(); if (prefix == null) { prefix = elementCollectionPath; ownedAttributes = managedType.getOwnedSingularAttributes();
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()) { boolean singleValuedAssociationId = mainQuery.jpaProvider.supportsSingleValuedAssociationIdExpressions() && extendedManagedType.getIdAttributes().size() == 1; if (singleValuedAssociationId) { whereSb.append('.').append(extendedManagedType.getIdAttribute().getName()); node.getCorrelationParent().appendAlias(whereSb, false, externalRepresentation); if (singleValuedAssociationId) { whereSb.append('.').append(extendedManagedType.getIdAttribute().getName()); StringBuilder whereSb = new StringBuilder(); ExtendedManagedType elementManagedType = metamodel.getManagedType(ExtendedManagedType.class, node.getManagedType()); if (elementManagedType.getAttribute(attribute.getMappedBy()).getAttribute().isCollection()) { renderAlias = false; sb.append(' '); whereSb.append('.').append(attribute.getMappedBy()); boolean singleValuedAssociationId = mainQuery.jpaProvider.supportsSingleValuedAssociationIdExpressions() && extendedManagedType.getIdAttributes().size() == 1; if (singleValuedAssociationId) { whereSb.append('.').append(extendedManagedType.getIdAttribute().getName()); whereSb.append('.').append(extendedManagedType.getIdAttribute().getName());
private String getIdAttribute(Class<?> entityClass) { return cbf.getService(EntityMetamodel.class) .getManagedType(ExtendedManagedType.class, entityClass) .getIdAttribute() .getName(); }
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 { elementClass = JpaMetamodelUtils.resolveKeyClass(entityBaseClass, (MapAttribute<?, ?, ?>) valuesLikeAttribute.getAttribute()); valuesLikeClause = "KEY(" + ((EntityType<?>) extendedManagedType.getType()).getName() + "." + attributeName + ")"; qualificationExpression = "KEY"; } 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; valuesLikeClause = "INDEX(" + ((EntityType<?>) extendedManagedType.getType()).getName() + "." + attributeName + ")"; qualificationExpression = "INDEX"; } else { valuesLikeAttribute = extendedManagedType.getAttribute(attributeName); elementClass = valuesLikeAttribute.getElementClass(); valuesLikeClause = ((EntityType<?>) extendedManagedType.getType()).getName() + "." + attributeName; qualificationExpression = null;
requiredUpdatableAttributes = new HashSet<>(); mappedColumns = new HashSet<>(); OUTER: for (Map.Entry<String, ? extends ExtendedAttribute<?, ?>> entry : extendedManagedType.getOwnedSingularAttributes().entrySet()) { ExtendedAttribute<?, ?> extendedAttribute = entry.getValue(); SingularAttribute<?, ?> attribute = (SingularAttribute<?, ?>) extendedAttribute.getAttribute(); ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttributes().get(iterator.next()); if (extendedAttribute == null || mappedColumns.containsAll(Arrays.asList(extendedAttribute.getColumnNames()))) { iterator.remove(); if (((IdentifiableType<Object>) jpaManagedType).hasVersionAttribute()) { for (Iterator<String> iterator = requiredUpdatableAttributes.iterator(); iterator.hasNext(); ) { ExtendedAttribute<?, ?> extendedAttribute = extendedManagedType.getAttributes().get(iterator.next()); try { SingularAttribute<? super Object, ?> version = ((IdentifiableType<Object>) jpaManagedType).getVersion(extendedAttribute.getElementClass());
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 AbstractCTECriteriaBuilder(MainQuery mainQuery, QueryContext queryContext, String cteName, Class<Object> clazz, Y result, CTEBuilderListener listener, BaseFinalSetOperationCTECriteriaBuilderImpl<Object, ?> finalSetOperationBuilder) { super(mainQuery, queryContext, false, DbmsStatementType.SELECT, clazz, null, finalSetOperationBuilder, false); this.result = result; this.listener = listener; this.cteType = mainQuery.metamodel.entity(clazz); this.attributeEntries = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, clazz).getOwnedSingularAttributes(); this.cteName = cteName; this.bindingMap = new LinkedHashMap<>(attributeEntries.size()); this.columnBindingMap = new LinkedHashMap<>(attributeEntries.size()); this.subListener = new CTEBuilderListenerImpl(); }
ExtendedManagedType<?> correlationBasisManagedType = evm.getMetamodel().getEntityMetamodel().getManagedType(ExtendedManagedType.class, correlationBasisEntity); Iterator<? extends javax.persistence.metamodel.SingularAttribute<?, ?>> iterator = managedType.getIdAttributes().iterator(); javax.persistence.metamodel.SingularAttribute<?, ?> idAttribute = iterator.next(); if (iterator.hasNext()) { || "this".equalsIgnoreCase(right) && correlationKeyAlias.equals(left); } else if (correlationBasisExpression.equals(idAttribute.getName())) { iterator = correlationBasisManagedType.getIdAttributes().iterator(); javax.persistence.metamodel.SingularAttribute<?, ?> correlatedIdAttribute = iterator.next(); if (iterator.hasNext()) {
EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel(); ExtendedManagedType extendedManagedType = entityMetamodel.getManagedType(ExtendedManagedType.class, elementEntityClass); EntityType<?> entityType = (EntityType<?>) extendedManagedType.getType(); this.requiresDeleteCascadeAfterRemove = !attribute.isForeignJoinColumn(); this.ownerIdAttributeName = ownerIdAttributeName;
public static List<UnmappedAttributeCascadeDeleter> createUnmappedCascadeDeleters(EntityViewManagerImpl evm, Class<?> entityClass, String ownerIdAttributeName) { EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel(); ExtendedManagedType<?> extendedManagedType = entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass); Map<String, ? extends ExtendedAttribute<?, ?>> attributes = extendedManagedType.getOwnedAttributes(); List<UnmappedAttributeCascadeDeleter> deleters = new ArrayList<>(attributes.size());
boolean cascadeUpdate = attribute.isUpdateCascaded(); boolean cascadeDelete = attribute.isDeleteCascaded(); boolean viewOnlyDeleteCascaded = cascadeDelete && !entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass).getAttribute(attributeMapping).isDeleteCascaded(); boolean optimisticLockProtected = attribute.isOptimisticLockProtected(); Set<Type<?>> readOnlyAllowedSubtypes = attribute.getReadOnlyAllowedSubtypes(); String elementIdAttributeName = entityMetamodel.getManagedType(ExtendedManagedType.class, attributeType.getJavaType()).getIdAttribute().getName(); deleter = new UnmappedBasicAttributeCascadeDeleter( evm, attributeName, entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass).getAttribute(attributeMapping), attributeMapping + "." + elementIdAttributeName, false
ExtendedAttribute<?, ?> associationAttribute = managedType.getOwnedSingularAttributes().get(maybeSingularAssociationName); return managedType.getOwnedSingularAttributes().containsKey(maybeSingularAssociationName + "." + maybeSingularAssociationIdExpression) && associationAttribute != null && (contains(metamodel.getManagedType(ExtendedManagedType.class, associationAttribute.getElementClass()).getIdAttributes(), maybeSingularAssociationIdExpression) || mainQuery.jpaProvider.supportsSingleValuedAssociationNaturalIdExpressions()); } else { ExtendedManagedType<?> managedType = metamodel.getManagedType(ExtendedManagedType.class, JpaMetamodelUtils.getTypeName(baseType)); if (elementCollectionPath == null) { ExtendedAttribute<?, ?> associationAttribute = managedType.getOwnedSingularAttributes().get(fullAttributePath); return managedType.getOwnedSingularAttributes().containsKey(fullAttributePath + "." + maybeSingularAssociationIdExpression) && associationAttribute != null && (contains(metamodel.getManagedType(ExtendedManagedType.class, associationAttribute.getElementClass()).getIdAttributes(), maybeSingularAssociationIdExpression) || mainQuery.jpaProvider.supportsSingleValuedAssociationNaturalIdExpressions()); } else { ExtendedAttribute<?, ?> associationAttribute = managedType.getAttributes().get(fullAttributePath); return !mainQuery.jpaProvider.needsElementCollectionIdCutoff() && managedType.getAttributes().containsKey(fullAttributePath + "." + maybeSingularAssociationIdExpression) && associationAttribute != null && (contains(metamodel.getManagedType(ExtendedManagedType.class, associationAttribute.getElementClass()).getIdAttributes(), maybeSingularAssociationIdExpression) || mainQuery.jpaProvider.supportsSingleValuedAssociationNaturalIdExpressions());
private String getIdAttribute(Class<?> entityClass) { return cbf.getService(EntityMetamodel.class) .getManagedType(ExtendedManagedType.class, entityClass) .getIdAttribute() .getName(); }
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;