use of org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess in project hibernate-orm by hibernate.
the class AbstractEntityPersister method prepareMappingModel.
private void prepareMappingModel(MappingModelCreationProcess creationProcess, PersistentClass bootEntityDescriptor) {
final EntityInstantiator instantiator = getRepresentationStrategy().getInstantiator();
final Supplier<?> templateInstanceCreator;
if (!instantiator.canBeInstantiated()) {
templateInstanceCreator = null;
} else {
final LazyValue<?> templateCreator = new LazyValue<>(() -> instantiator.instantiate(creationProcess.getCreationContext().getSessionFactory()));
templateInstanceCreator = templateCreator::getValue;
}
identifierMapping = creationProcess.processSubPart(EntityIdentifierMapping.ROLE_LOCAL_NAME, (role, process) -> generateIdentifierMapping(templateInstanceCreator, bootEntityDescriptor, process));
versionMapping = generateVersionMapping(templateInstanceCreator, bootEntityDescriptor, creationProcess);
if (rowIdName == null) {
rowIdMapping = null;
} else {
rowIdMapping = creationProcess.processSubPart(rowIdName, (role, process) -> new EntityRowIdMappingImpl(rowIdName, this.getTableName(), this));
}
discriminatorMapping = generateDiscriminatorMapping(bootEntityDescriptor, creationProcess);
}
use of org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess in project hibernate-orm by hibernate.
the class AbstractEntityPersister method generateNonIdAttributeMapping.
private AttributeMapping generateNonIdAttributeMapping(NonIdentifierAttribute tupleAttrDefinition, Property bootProperty, int stateArrayPosition, MappingModelCreationProcess creationProcess) {
final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory();
final JdbcServices jdbcServices = sessionFactory.getJdbcServices();
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final Dialect dialect = jdbcEnvironment.getDialect();
final String attrName = tupleAttrDefinition.getName();
final Type attrType = tupleAttrDefinition.getType();
final int propertyIndex = getPropertyIndex(bootProperty.getName());
final String tableExpression = getTableName(getPropertyTableNumbers()[propertyIndex]);
final String[] attrColumnNames = getPropertyColumnNames(propertyIndex);
final PropertyAccess propertyAccess = getRepresentationStrategy().resolvePropertyAccess(bootProperty);
if (propertyIndex == getVersionProperty()) {
Column column = bootProperty.getValue().getColumns().get(0);
return MappingModelCreationHelper.buildBasicAttributeMapping(attrName, getNavigableRole().append(bootProperty.getName()), stateArrayPosition, bootProperty, this, (BasicType<?>) attrType, tableExpression, attrColumnNames[0], false, null, null, column.getSqlType(), column.getLength(), column.getPrecision(), column.getScale(), propertyAccess, tupleAttrDefinition.getCascadeStyle(), creationProcess);
}
if (attrType instanceof BasicType) {
final Value bootValue = bootProperty.getValue();
final String attrColumnExpression;
final boolean isAttrColumnExpressionFormula;
final String customReadExpr;
final String customWriteExpr;
final String columnDefinition;
final Long length;
final Integer precision;
final Integer scale;
if (bootValue instanceof DependantValue) {
attrColumnExpression = attrColumnNames[0];
isAttrColumnExpressionFormula = false;
customReadExpr = null;
customWriteExpr = null;
Column column = bootValue.getColumns().get(0);
columnDefinition = column.getSqlType();
length = column.getLength();
precision = column.getPrecision();
scale = column.getScale();
} else {
final BasicValue basicBootValue = (BasicValue) bootValue;
if (attrColumnNames[0] != null) {
attrColumnExpression = attrColumnNames[0];
isAttrColumnExpressionFormula = false;
final List<Selectable> selectables = basicBootValue.getSelectables();
assert !selectables.isEmpty();
final Selectable selectable = selectables.get(0);
assert attrColumnExpression.equals(selectable.getText(sessionFactory.getJdbcServices().getDialect()));
customReadExpr = selectable.getTemplate(dialect, sessionFactory.getQueryEngine().getSqmFunctionRegistry());
customWriteExpr = selectable.getCustomWriteExpression();
Column column = bootValue.getColumns().get(0);
columnDefinition = column.getSqlType();
length = column.getLength();
precision = column.getPrecision();
scale = column.getScale();
} else {
final String[] attrColumnFormulaTemplate = propertyColumnFormulaTemplates[propertyIndex];
attrColumnExpression = attrColumnFormulaTemplate[0];
isAttrColumnExpressionFormula = true;
customReadExpr = null;
customWriteExpr = null;
columnDefinition = null;
length = null;
precision = null;
scale = null;
}
}
return MappingModelCreationHelper.buildBasicAttributeMapping(attrName, getNavigableRole().append(bootProperty.getName()), stateArrayPosition, bootProperty, this, (BasicType<?>) attrType, tableExpression, attrColumnExpression, isAttrColumnExpressionFormula, customReadExpr, customWriteExpr, columnDefinition, length, precision, scale, propertyAccess, tupleAttrDefinition.getCascadeStyle(), creationProcess);
} else if (attrType instanceof AnyType) {
final JavaType<Object> baseAssociationJtd = sessionFactory.getTypeConfiguration().getJavaTypeRegistry().getDescriptor(Object.class);
final AnyType anyType = (AnyType) attrType;
return new DiscriminatedAssociationAttributeMapping(navigableRole.append(bootProperty.getName()), baseAssociationJtd, this, stateArrayPosition, entityMappingType -> new StateArrayContributorMetadata() {
private final MutabilityPlan<?> mutabilityPlan = new DiscriminatedAssociationAttributeMapping.MutabilityPlanImpl(anyType);
private final boolean nullable = bootProperty.isOptional();
private final boolean insertable = bootProperty.isInsertable();
private final boolean updateable = bootProperty.isUpdateable();
private final boolean optimisticallyLocked = 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() {
return updateable;
}
@Override
public boolean isIncludedInOptimisticLocking() {
return optimisticallyLocked;
}
}, bootProperty.isLazy() ? FetchTiming.DELAYED : FetchTiming.IMMEDIATE, propertyAccess, bootProperty, (AnyType) attrType, (Any) bootProperty.getValue(), creationProcess);
} else if (attrType instanceof CompositeType) {
return MappingModelCreationHelper.buildEmbeddedAttributeMapping(attrName, stateArrayPosition, bootProperty, this, (CompositeType) attrType, tableExpression, null, propertyAccess, tupleAttrDefinition.getCascadeStyle(), creationProcess);
} else if (attrType instanceof CollectionType) {
return MappingModelCreationHelper.buildPluralAttributeMapping(attrName, stateArrayPosition, bootProperty, this, propertyAccess, tupleAttrDefinition.getCascadeStyle(), getFetchMode(stateArrayPosition), creationProcess);
} else if (attrType instanceof EntityType) {
return MappingModelCreationHelper.buildSingularAssociationAttributeMapping(attrName, getNavigableRole().append(attrName), stateArrayPosition, bootProperty, this, this, (EntityType) attrType, propertyAccess, tupleAttrDefinition.getCascadeStyle(), creationProcess);
}
return null;
}
Aggregations