use of org.hibernate.metamodel.mapping.AttributeMetadataAccess in project hibernate-orm by hibernate.
the class AbstractEntityPersister method getPropertyValues.
@Override
public Object[] getPropertyValues(Object object) {
if (accessOptimizer != null) {
return accessOptimizer.getPropertyValues(object);
} else {
final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
final LazyAttributesMetadata lazyAttributesMetadata = enhancementMetadata.getLazyAttributesMetadata();
final Object[] values = new Object[getNumberOfAttributeMappings()];
for (int i = 0; i < attributeMappings.size(); i++) {
final AttributeMapping attributeMapping = attributeMappings.get(i);
final AttributeMetadataAccess attributeMetadataAccess = attributeMapping.getAttributeMetadataAccess();
if (!lazyAttributesMetadata.isLazyAttribute(attributeMapping.getAttributeName()) || enhancementMetadata.isAttributeLoaded(object, attributeMapping.getAttributeName())) {
values[i] = attributeMetadataAccess.resolveAttributeMetadata(this).getPropertyAccess().getGetter().get(object);
} else {
values[i] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
}
return values;
}
}
use of org.hibernate.metamodel.mapping.AttributeMetadataAccess in project hibernate-orm by hibernate.
the class MappingModelCreationHelper method buildBasicAttributeMapping.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Non-identifier attributes
@SuppressWarnings("rawtypes")
public static BasicAttributeMapping buildBasicAttributeMapping(String attrName, NavigableRole navigableRole, int stateArrayPosition, Property bootProperty, ManagedMappingType declaringType, BasicType attrType, String tableExpression, String attrColumnName, boolean isAttrFormula, String readExpr, String writeExpr, String columnDefinition, Long length, Integer precision, Integer scale, PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) {
final Value value = bootProperty.getValue();
final BasicValue.Resolution<?> resolution = ((Resolvable) value).resolve();
final BasicValueConverter<?, ?> valueConverter = resolution.getValueConverter();
final AttributeMetadataAccess attributeMetadataAccess = entityMappingType -> new AttributeMetadata() {
private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan();
private final boolean nullable = value.isNullable();
private final boolean insertable = bootProperty.isInsertable();
private final boolean updateable = bootProperty.isUpdateable();
private final boolean includeInOptimisticLocking = bootProperty.isOptimisticLocked();
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;
}
@Override
public MutabilityPlan getMutabilityPlan() {
return mutabilityPlan;
}
@Override
public boolean isNullable() {
return nullable;
}
@Override
public boolean isInsertable() {
return insertable;
}
@Override
public boolean isUpdatable() {
return updateable;
}
@Override
public boolean isIncludedInDirtyChecking() {
// todo (6.0) : do not believe this is correct
return updateable;
}
@Override
public boolean isIncludedInOptimisticLocking() {
return includeInOptimisticLocking;
}
@Override
public CascadeStyle getCascadeStyle() {
return cascadeStyle;
}
};
final FetchTiming fetchTiming;
final FetchStyle fetchStyle;
if (declaringType instanceof EmbeddableMappingType) {
if (bootProperty.isLazy()) {
LOGGER.debugf("Attribute was declared lazy, but is part of an embeddable - `%s#%s` - LAZY will be ignored", declaringType.getNavigableRole().getFullPath(), bootProperty.getName());
}
fetchTiming = FetchTiming.IMMEDIATE;
fetchStyle = FetchStyle.JOIN;
} else {
fetchTiming = bootProperty.isLazy() ? FetchTiming.DELAYED : FetchTiming.IMMEDIATE;
fetchStyle = bootProperty.isLazy() ? FetchStyle.SELECT : FetchStyle.JOIN;
}
final ValueGeneration valueGeneration = bootProperty.getValueGenerationStrategy();
if (valueConverter != null) {
// we want to "decompose" the "type" into its various pieces as expected by the mapping
assert valueConverter.getRelationalJavaType() == resolution.getRelationalJavaType();
final BasicType<?> mappingBasicType = creationProcess.getCreationContext().getDomainModel().getTypeConfiguration().getBasicTypeRegistry().resolve(valueConverter.getRelationalJavaType(), resolution.getJdbcType());
return new BasicAttributeMapping(attrName, navigableRole, stateArrayPosition, attributeMetadataAccess, fetchTiming, fetchStyle, tableExpression, attrColumnName, isAttrFormula, null, null, columnDefinition, length, precision, scale, valueConverter, mappingBasicType.getJdbcMapping(), declaringType, propertyAccess, valueGeneration);
} else {
return new BasicAttributeMapping(attrName, navigableRole, stateArrayPosition, attributeMetadataAccess, fetchTiming, fetchStyle, tableExpression, attrColumnName, isAttrFormula, readExpr, writeExpr, columnDefinition, length, precision, scale, null, attrType, declaringType, propertyAccess, valueGeneration);
}
}
use of org.hibernate.metamodel.mapping.AttributeMetadataAccess in project hibernate-orm by hibernate.
the class MappingModelCreationHelper method buildEmbeddedAttributeMapping.
public static EmbeddedAttributeMapping buildEmbeddedAttributeMapping(String attrName, int stateArrayPosition, Property bootProperty, ManagedMappingType declaringType, CompositeType attrType, String tableExpression, String[] rootTableKeyColumnNames, PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) {
final AttributeMetadataAccess attributeMetadataAccess = getAttributeMetadataAccess(bootProperty, attrType, propertyAccess, cascadeStyle, creationProcess);
final Component component = (Component) bootProperty.getValue();
final EmbeddableMappingTypeImpl embeddableMappingType = EmbeddableMappingTypeImpl.from(component, attrType, tableExpression, rootTableKeyColumnNames, attributeMappingType -> {
if (component.isEmbedded()) {
return new VirtualEmbeddedAttributeMapping(attrName, declaringType.getNavigableRole().append(attrName), stateArrayPosition, tableExpression, attributeMetadataAccess, component.getParentProperty(), FetchTiming.IMMEDIATE, FetchStyle.JOIN, attributeMappingType, declaringType, propertyAccess, bootProperty.getValueGenerationStrategy());
} else {
return new EmbeddedAttributeMapping(attrName, declaringType.getNavigableRole().append(attrName), stateArrayPosition, tableExpression, attributeMetadataAccess, component.getParentProperty(), FetchTiming.IMMEDIATE, FetchStyle.JOIN, attributeMappingType, declaringType, propertyAccess, bootProperty.getValueGenerationStrategy());
}
}, creationProcess);
return (EmbeddedAttributeMapping) embeddableMappingType.getEmbeddedValueMapping();
}
use of org.hibernate.metamodel.mapping.AttributeMetadataAccess in project hibernate-orm by hibernate.
the class MappingModelCreationHelper method buildSingularAssociationAttributeMapping.
public static ToOneAttributeMapping buildSingularAssociationAttributeMapping(String attrName, NavigableRole navigableRole, int stateArrayPosition, Property bootProperty, ManagedMappingType declaringType, EntityPersister declaringEntityPersister, EntityType attrType, PropertyAccess propertyAccess, CascadeStyle cascadeStyle, MappingModelCreationProcess creationProcess) {
if (bootProperty.getValue() instanceof ToOne) {
final ToOne value = (ToOne) bootProperty.getValue();
final EntityPersister entityPersister = creationProcess.getEntityPersister(value.getReferencedEntityName());
final AttributeMetadataAccess attributeMetadataAccess = getAttributeMetadataAccess(bootProperty, attrType, propertyAccess, cascadeStyle, creationProcess);
SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
final AssociationType type = (AssociationType) bootProperty.getType();
final FetchStyle fetchStyle = FetchOptionsHelper.determineFetchStyleByMetadata(bootProperty.getValue().getFetchMode(), type, sessionFactory);
final FetchTiming fetchTiming;
final String role = declaringType.getNavigableRole().toString() + "." + bootProperty.getName();
final boolean lazy = value.isLazy();
if (lazy && entityPersister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading()) {
if (value.isUnwrapProxy()) {
fetchTiming = FetchOptionsHelper.determineFetchTiming(fetchStyle, type, lazy, role, sessionFactory);
} else if (value instanceof ManyToOne && value.isNullable() && ((ManyToOne) value).isIgnoreNotFound()) {
fetchTiming = FetchTiming.IMMEDIATE;
} else {
fetchTiming = FetchOptionsHelper.determineFetchTiming(fetchStyle, type, lazy, role, sessionFactory);
}
} else if (!lazy || value instanceof OneToOne && value.isNullable() || value instanceof ManyToOne && value.isNullable() && ((ManyToOne) value).isIgnoreNotFound()) {
fetchTiming = FetchTiming.IMMEDIATE;
} else {
fetchTiming = FetchOptionsHelper.determineFetchTiming(fetchStyle, type, lazy, role, sessionFactory);
}
final ToOneAttributeMapping attributeMapping = new ToOneAttributeMapping(attrName, navigableRole, stateArrayPosition, (ToOne) bootProperty.getValue(), attributeMetadataAccess, fetchTiming, fetchStyle, entityPersister, declaringType, declaringEntityPersister, propertyAccess);
creationProcess.registerForeignKeyPostInitCallbacks("To-one key - " + navigableRole, () -> {
final Dialect dialect = creationProcess.getCreationContext().getSessionFactory().getJdbcServices().getDialect();
return MappingModelCreationHelper.interpretToOneKeyDescriptor(attributeMapping, bootProperty, (ToOne) bootProperty.getValue(), null, dialect, creationProcess);
});
return attributeMapping;
} else {
throw new NotYetImplementedFor6Exception("AnyType support has not yet been implemented");
}
}
use of org.hibernate.metamodel.mapping.AttributeMetadataAccess in project hibernate-orm by hibernate.
the class CompoundNaturalIdMapping method isMutable.
private static boolean isMutable(EntityMappingType entityDescriptor, List<SingularAttributeMapping> attributes, MappingModelCreationProcess creationProcess) {
for (int i = 0; i < attributes.size(); i++) {
final SingularAttributeMapping attributeMapping = attributes.get(i);
final AttributeMetadataAccess metadataAccess = attributeMapping.getAttributeMetadataAccess();
if (!metadataAccess.resolveAttributeMetadata(entityDescriptor).isUpdatable()) {
return false;
}
}
return true;
}
Aggregations