@SuppressWarnings("unchecked") @Override public <X> BasicUserType<X> getBasicUserType(Class<X> clazz) { BasicUserType<?> userType = basicUserTypes.get(clazz); if (userType == null) { if (clazz.isEnum()) { // Enums are always considered immutable userType = ImmutableBasicUserType.INSTANCE; } else if (entityMetamodel.getEntity(clazz) != null) { userType = entityBasicUserType; } else if (Date.class.isAssignableFrom(clazz)) { userType = DateBasicUserType.INSTANCE; } else if (Calendar.class.isAssignableFrom(clazz)) { userType = CalendarBasicUserType.INSTANCE; } else { userType = MutableBasicUserType.INSTANCE; } } return (BasicUserType<X>) userType; } }
@Override public ParameterValueTransformer getToEntityTranformer(Class<?> entityType) { IdentifiableType<?> managedType = (IdentifiableType<?>) metamodel.getManagedType(entityType); Attribute<?, ?> idAttribute = JpaMetamodelUtils.getSingleIdAttribute(managedType); return AssociationFromIdParameterTransformer.getInstance(entityType, idAttribute); }
public ScalarTargetResolvingExpressionVisitor(Class<?> managedType, EntityMetamodel metamodel, Map<String, JpqlFunction> functions) { this(metamodel.managedType(managedType), metamodel, functions); }
EntityType<?> entityType = m.getEntity(rootNode.getJavaType()); if (entityType == null) { ExtendedManagedType<?> extendedManagedType = m.getManagedType(ExtendedManagedType.class, entityType); Set<String> attributePaths; if (rootNode.getValuesIdNames() != null && !rootNode.getValuesIdNames().isEmpty()) { attrPath.setPathReference(new SimplePathReference(rootNode, propertyPath, m.type(extendedAttribute.getElementClass()))); pathExpressions.add(attrPath);
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(); } }
this.flushStrategy = viewType.getFlushStrategy(); EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel(); EntityType<?> entityType = entityMetamodel.getEntity(entityClass); ViewToEntityMapper viewIdMapper = null; versionAttribute = (AbstractMethodAttribute<?, ?>) ((ViewType) viewType).getVersionAttribute(); versionFlusher = versionAttribute != null ? createVersionFlusher(evm, entityType, versionAttribute) : null; jpaIdAttribute = JpaMetamodelUtils.getSingleIdAttribute(entityMetamodel.entity(entityClass)); idAttributeName = jpaIdAttribute.getName(); String mapping = idAttribute.getMapping(); Map<String, ExtendedAttribute> joinTableUnmappedEntityAttributes = new TreeMap<>(entityMetamodel.getManagedType(ExtendedManagedType.class, entityClass).getOwnedAttributes()); if (jpaIdAttribute != null) { joinTableUnmappedEntityAttributes.remove(jpaIdAttribute.getName()); ExtendedAttribute attributeEntry = entry.getValue(); JoinTable joinTable = attributeEntry.getJoinTable(); if (joinTable == null && !"".equals(attributeEntry.getMappedBy()) && (entityMetamodel.getEntity(attributeEntry.getElementClass()) == null || !attributeEntry.isDeleteCascaded())) { iterator.remove(); 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 { ExtendedManagedType managedType = entityMetamodel.getManagedType(ExtendedManagedType.class, extendedAttribute.getElementClass()); deleter = new UnmappedWritableBasicAttributeSetNullCascadeDeleter(evm, managedType, extendedAttribute.getWritableMappedByMappings((EntityType<?>) managedType.getType())); } else {
public UpdatableExpressionVisitor(EntityMetamodel metamodel, Class<?> startClass, boolean updatable) { super(metamodel, metamodel.type(startClass), null); this.updatable = updatable; }
if (type instanceof ManagedViewType<?>) { ManagedViewType<?> subviewType = (ManagedViewType<?>) type; if (entityMetamodel.getEntity(subviewType.getEntityClass()) == null) { javax.persistence.metamodel.Type<?> attributeIdAttributeType = entityMetamodel.type(JpaMetamodelUtils.resolveFieldClass(attributeViewType.getEntityClass(), attributeIdAttribute)); List<String> idComponentMappings; boolean requiresComponentWiseSetInUpdate = true;
private EntityType<?> getTreatType(EntityMetamodel metamodel, Class<?> baseType, Class<?> subtype) { if (baseType == subtype) { return null; } return metamodel.entity(subtype); }
ManagedType<?> entityType = context.getEntityMetamodel().getManagedType(getElementType().getJavaType()); if (entityType == null) { context.addError("Specifying fetches for non-entity attribute type [" + Arrays.toString(fetches) + "] at the " + getLocation() + " is not allowed!"); validateTypesCompatible(context.getEntityMetamodel().managedType(correlated), stripThisFromMapping(correlationResult), expressionType, elementType, true, !isCollection(), context, ExpressionLocation.CORRELATION_RESULT, getLocation());
ManagedType<?> managedType = evm.getMetamodel().getEntityMetamodel().getManagedType(elementEntityClass); Attribute<?, ?> inverseAttribute = JpaMetamodelUtils.getAttribute(managedType, attribute.getMappedBy()); ExtendedManagedType elementManagedType = entityMetamodel.getManagedType(ExtendedManagedType.class, elementEntityClass); parentIdAttributeName = entityMetamodel.getManagedType(ExtendedManagedType.class, viewType.getEntityClass()).getIdAttribute().getName(); childIdAttributeName = elementManagedType.getIdAttribute().getName(); childEntityToEntityMapper = new InverseEntityToEntityMapper( evm, evm.getMetamodel().getEntityMetamodel().entity(childType), parentEntityOnChildEntityAddMapper, parentEntityOnChildEntityRemoveMapper,
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(); if (entityMetamodel.getEntity(subviewType.getEntityClass()) == null) { AttributeAccessor viewAttributeAccessor = Accessors.forViewAttribute(evm, attribute, true); javax.persistence.metamodel.Type<?> attributeIdAttributeType = entityMetamodel.type(JpaMetamodelUtils.resolveFieldClass(attributeViewType.getEntityClass(), attributeIdAttribute)); List<String> idComponentMappings; boolean requiresComponentWiseSetInUpdate = true; 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
if (elementType instanceof BasicType<?> && context.getEntityMetamodel().getEntity(elementType.getJavaType()) == null || elementType instanceof FlatViewType<?>) { context.addError("Cascading configuration for basic, embeddable or flat view type attributes is not allowed. Invalid definition found on the " + mapping.getErrorLocation() + "!"); if (embeddableMapping == null) { mappingPath = this.mapping; managedType = context.getEntityMetamodel().getManagedType(declaringType.getEntityClass()); } else { mappingPath = embeddableMapping.getEmbeddableMapping() + "." + this.mapping; managedType = context.getEntityMetamodel().getManagedType(embeddableMapping.getEntityClass());
@Override public void visit(TimeLiteral expression) { currentPosition.setCurrentType(metamodel.type(Date.class)); }
protected final <T> EntityType<T> getTreatType(Class<T> type) { return criteriaBuilder.getEntityMetamodel().entity(type); }
@Override protected void validate(RepositoryMetadata repositoryMetadata) { super.validate(repositoryMetadata); if (cbf.getService(EntityMetamodel.class).getEntity(repositoryMetadata.getDomainType()) == null) { throw new InvalidDataAccessApiUsageException( String.format("Cannot implement repository %s when using a non-entity domain type %s. Only types annotated with @Entity are supported!", repositoryMetadata.getRepositoryInterface().getName(), repositoryMetadata.getDomainType().getName())); } }
ManagedType<?> managedType = context.getEntityMetamodel().getManagedType(declaringType.getEntityClass()); this.mappedBy = mapping.determineMappedBy(managedType, this.mapping, context, embeddableMapping); this.disallowOwnedUpdatableSubview = context.isDisallowOwnedUpdatableSubview() && mapping.determineDisallowOwnedUpdatableSubview(context, embeddableMapping, updateMappableAttribute) && type instanceof ManagedViewType<?> && mappedBy == null if (type instanceof BasicType<?> && context.getEntityMetamodel().getEntity(type.getJavaType()) == null || type instanceof FlatViewType<?>) { context.addError("Cascading configuration for basic, embeddable or flat view type attributes is not allowed. Invalid definition found on the " + mapping.getErrorLocation() + "!");
@Override public void visit(DateLiteral expression) { currentPosition.setCurrentType(metamodel.type(Date.class)); }
private String getIdAttribute(Class<?> entityClass) { return cbf.getService(EntityMetamodel.class) .getManagedType(ExtendedManagedType.class, entityClass) .getIdAttribute() .getName(); }
protected final <T> EntityType<T> getTreatType(Class<T> type) { return criteriaBuilder.getEntityMetamodel().entity(type); }