finally move propertyHolder from AnnotatedColumn

This commit is contained in:
Gavin King 2022-10-31 02:10:37 +01:00
parent 585522fde1
commit 18003b92dc
7 changed files with 80 additions and 68 deletions

View File

@ -72,8 +72,6 @@ public class AnnotatedColumn {
private boolean updatable = true;
private String explicitTableName; // the JPA @Column annotation lets you specify a table name
protected Map<String, Join> joins;
@Deprecated // use AnnotatedColumns.propertyHolder
protected PropertyHolder propertyHolder;
private boolean isImplicit;
public String sqlType;
private Long length;
@ -424,12 +422,7 @@ public class AnnotatedColumn {
}
public PropertyHolder getPropertyHolder() {
return propertyHolder; //TODO: change this to delegate to the parent
}
@Deprecated // use AnnotatedColumns.setPropertyHolder() instead
public void setPropertyHolder(PropertyHolder propertyHolder) {
this.propertyHolder = propertyHolder;
return parent.getPropertyHolder();
}
protected void setMappingColumn(Column mappingColumn) {
@ -502,7 +495,7 @@ public class AnnotatedColumn {
//TODO: move to AnnotatedColumns
public boolean isSecondary() {
if ( propertyHolder == null ) {
if ( getPropertyHolder() == null ) {
throw new AssertionFailure( "Should not call isSecondary() on column w/o persistent class defined" );
}
return isNotEmpty( explicitTableName )
@ -680,11 +673,11 @@ public class AnnotatedColumn {
formulaColumn.setFormula( formulaAnn.value() );
formulaColumn.setImplicit( false );
formulaColumn.setBuildingContext( context );
formulaColumn.setPropertyHolder( propertyHolder );
formulaColumn.bind();
// formulaColumn.setPropertyHolder( propertyHolder );
final AnnotatedColumns result = new AnnotatedColumns();
result.setPropertyHolder( propertyHolder );
result.setColumns( new AnnotatedColumn[] {formulaColumn} );
formulaColumn.bind();
return result;
}
else {
@ -809,7 +802,7 @@ public class AnnotatedColumn {
column.setLength( (long) col.length() );
column.setPrecision( col.precision() );
column.setScale( col.scale() );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
column.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
column.setNullable( col.nullable() ); //TODO force to not null if available? This is a (bad) user choice.
if ( comment != null ) {
@ -824,7 +817,10 @@ public class AnnotatedColumn {
column.applyColumnDefault( inferredData, length );
column.applyGeneratedAs( inferredData, length );
column.applyCheckConstraint( inferredData, length );
column.extractDataFromPropertyData( inferredData );
column.extractDataFromPropertyData( propertyHolder, inferredData );
AnnotatedColumns temp = new AnnotatedColumns();
temp.setPropertyHolder( propertyHolder );
temp.setColumns( new AnnotatedColumn[] { column } );
column.bind();
return column;
}
@ -895,12 +891,12 @@ public class AnnotatedColumn {
}
//must only be called after all setters are defined and before binding
private void extractDataFromPropertyData(PropertyData inferredData) {
private void extractDataFromPropertyData(PropertyHolder propertyHolder, PropertyData inferredData) {
if ( inferredData != null ) {
XProperty property = inferredData.getProperty();
final XProperty property = inferredData.getProperty();
if ( property != null ) {
if ( getPropertyHolder().isComponent() ) {
processColumnTransformerExpressions( getPropertyHolder().getOverriddenColumnTransformer( logicalColumnName ) );
if ( propertyHolder.isComponent() ) {
processColumnTransformerExpressions( propertyHolder.getOverriddenColumnTransformer( logicalColumnName ) );
}
processColumnTransformerExpressions( property.getAnnotation( ColumnTransformer.class ) );
final ColumnTransformers annotations = property.getAnnotation( ColumnTransformers.class );
@ -966,7 +962,7 @@ public class AnnotatedColumn {
column.setNullable( false );
}
final String propertyName = inferredData.getPropertyName();
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
column.setJoins( secondaryTables );
column.setBuildingContext( context );
@ -979,7 +975,10 @@ public class AnnotatedColumn {
column.applyColumnDefault( inferredData, 1 );
column.applyGeneratedAs( inferredData, 1 );
column.applyCheckConstraint( inferredData, 1 );
column.extractDataFromPropertyData( inferredData );
column.extractDataFromPropertyData( propertyHolder, inferredData );
AnnotatedColumns temp = new AnnotatedColumns();
temp.setPropertyHolder( propertyHolder );
temp.setColumns( new AnnotatedColumn[] { column } );
column.bind();
return column;
}
@ -1020,7 +1019,8 @@ public class AnnotatedColumn {
}
void addIndex(String indexName, boolean inSecondPass) {
IndexOrUniqueKeySecondPass secondPass = new IndexOrUniqueKeySecondPass( indexName, this, context, false );
final IndexOrUniqueKeySecondPass secondPass =
new IndexOrUniqueKeySecondPass( indexName, this, context, false );
if ( inSecondPass ) {
secondPass.doSecondPass( context.getMetadataCollector().getEntityBindingMap() );
}
@ -1030,7 +1030,8 @@ public class AnnotatedColumn {
}
void addUniqueKey(String uniqueKeyName, boolean inSecondPass) {
IndexOrUniqueKeySecondPass secondPass = new IndexOrUniqueKeySecondPass( uniqueKeyName, this, context, true );
final IndexOrUniqueKeySecondPass secondPass =
new IndexOrUniqueKeySecondPass( uniqueKeyName, this, context, true );
if ( inSecondPass ) {
secondPass.doSecondPass( context.getMetadataCollector().getEntityBindingMap() );
}

View File

@ -115,7 +115,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
formulaColumn.setFormula( joinFormula.value() );
formulaColumn.setReferencedColumn( joinFormula.referencedColumnName() );
formulaColumn.setBuildingContext( buildingContext );
formulaColumn.setPropertyHolder( propertyHolder );
// formulaColumn.setPropertyHolder( propertyHolder );
formulaColumn.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
formulaColumn.setJoins( joins );
formulaColumn.bind();
@ -161,7 +161,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
column.setLogicalColumnName( propertyName + defaultColumnSuffix );
}
column.setJoins( joins );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
column.setImplicit( false );
column.bind();
@ -176,7 +176,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
MetadataBuildingContext context) {
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
column.setJoins( joins );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
// property name + suffix is an "explicit" column name
if ( isNotEmpty( defaultColumnSuffix ) ) {
@ -273,7 +273,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
column.setSqlType( columnDef );
column.setLogicalColumnName( logicalColumnName );
column.setReferencedColumn( referencedColumnName );
column.setPropertyHolder(propertyHolder);
// column.setPropertyHolder(propertyHolder);
column.setJoins(joins);
column.setBuildingContext(context);
column.setImplicit( false );
@ -290,7 +290,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();
column.setLogicalColumnName( normalizer.normalizeIdentifierQuotingAsString(defaultColumnName) );
column.setPropertyHolder(propertyHolder);
// column.setPropertyHolder( propertyHolder );
column.setJoins(joins);
column.setBuildingContext(context);
column.setImplicit( true );
@ -504,7 +504,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
column.setImplicit( true );
column.setNullable( false ); //I break the spec, but it's for good
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
column.setJoins( secondaryTables );
column.setBuildingContext( context );
@ -520,7 +520,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
JoinColumn joinColumn) {
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
column.setImplicit( true );
column.setPropertyHolder(propertyHolder);
// column.setPropertyHolder( propertyHolder );
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
column.setJoins( secondaryTables );
column.setBuildingContext( context );

View File

@ -48,7 +48,6 @@ import static org.hibernate.internal.util.StringHelper.qualify;
public class AnnotatedJoinColumns extends AnnotatedColumns {
private AnnotatedJoinColumn[] columns;
private PropertyHolder propertyHolder;
private String propertyName; // this is really a .-separated property path
private MetadataBuildingContext buildingContext;
@ -247,14 +246,6 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
return mappedByTableName;
}
public PropertyHolder getPropertyHolder() {
return propertyHolder;
}
public void setPropertyHolder(PropertyHolder propertyHolder) {
this.propertyHolder = propertyHolder;
}
/**
* Override persistent class on oneToMany Cases for late settings
* Must only be used on second level pass binding
@ -264,15 +255,16 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
Map<String, Join> joins,
Map<XClass, InheritanceState> inheritanceStatePerClass) {
// TODO shouldn't we deduce the class name from the persistentClass?
propertyHolder = buildPropertyHolder(
final PropertyHolder propertyHolder = buildPropertyHolder(
persistentClass,
joins,
buildingContext,
inheritanceStatePerClass
);
for ( AnnotatedJoinColumn column : columns ) {
column.setPropertyHolder( propertyHolder );
}
setPropertyHolder( propertyHolder );
// for ( AnnotatedJoinColumn column : columns ) {
// column.setPropertyHolder( propertyHolder );
// }
}
public void setBuildingContext(MetadataBuildingContext buildingContext) {
@ -479,7 +471,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
String.format(
Locale.ENGLISH,
"Association '%s' is 'mappedBy' a property '%s' of entity '%s' with no columns",
propertyHolder.getPath(),
getPropertyHolder().getPath(),
getMappedByPropertyName(),
getMappedByEntityName()
)
@ -491,9 +483,9 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
String.format(
Locale.ENGLISH,
"Association '%s' is 'mappedBy' a property '%s' of entity '%s' which maps to a formula",
propertyHolder.getPath(),
getPropertyHolder().getPath(),
getMappedByPropertyName(),
propertyHolder.getPath()
getPropertyHolder().getPath()
)
);
}
@ -502,9 +494,9 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
String.format(
Locale.ENGLISH,
"Association '%s' is 'mappedBy' a property '%s' of entity '%s' with multiple columns",
propertyHolder.getPath(),
getPropertyHolder().getPath(),
getMappedByPropertyName(),
propertyHolder.getPath()
getPropertyHolder().getPath()
)
);
}

View File

@ -60,7 +60,8 @@ public class IndexColumn extends AnnotatedColumn {
column.setLogicalColumnName( inferredData.getPropertyName() + "_ORDER" ); //JPA default name
column.setImplicit( true );
column.setBuildingContext( context );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
createParent( propertyHolder, column );
column.bind();
}
@ -71,6 +72,12 @@ public class IndexColumn extends AnnotatedColumn {
return column;
}
private static void createParent(PropertyHolder propertyHolder, IndexColumn column) {
final AnnotatedColumns columns = new AnnotatedColumns();
columns.setColumns( new AnnotatedColumn[] {column} );
columns.setPropertyHolder( propertyHolder );
}
public int getBase() {
return base;
}
@ -82,7 +89,7 @@ public class IndexColumn extends AnnotatedColumn {
/**
* JPA 2 {@link OrderColumn @OrderColumn} processing.
*
* @param ann The OrderColumn annotation instance
* @param orderColumn The OrderColumn annotation instance
* @param propertyHolder Information about the property
* @param inferredData Yeah, right. Uh...
* @param secondaryTables Any secondary tables available.
@ -90,24 +97,25 @@ public class IndexColumn extends AnnotatedColumn {
* @return The index column
*/
public static IndexColumn buildColumnFromAnnotation(
OrderColumn ann,
OrderColumn orderColumn,
PropertyHolder propertyHolder,
PropertyData inferredData,
Map<String, Join> secondaryTables,
MetadataBuildingContext buildingContext) {
if ( ann != null ) {
final String sqlType = isEmptyAnnotationValue( ann.columnDefinition() ) ? null : ann.columnDefinition();
final String name = isEmptyAnnotationValue( ann.name() ) ? inferredData.getPropertyName() + "_ORDER" : ann.name();
if ( orderColumn != null ) {
final String sqlType = isEmptyAnnotationValue( orderColumn.columnDefinition() ) ? null : orderColumn.columnDefinition();
final String name = isEmptyAnnotationValue( orderColumn.name() ) ? inferredData.getPropertyName() + "_ORDER" : orderColumn.name();
//TODO move it to a getter based system and remove the constructor
final IndexColumn column = new IndexColumn();
column.setLogicalColumnName( name );
column.setSqlType( sqlType );
column.setNullable( ann.nullable() );
column.setNullable( orderColumn.nullable() );
column.setJoins( secondaryTables );
column.setInsertable( ann.insertable() );
column.setUpdatable( ann.updatable() );
column.setInsertable( orderColumn.insertable() );
column.setUpdatable( orderColumn.updatable() );
column.setBuildingContext( buildingContext );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
createParent( propertyHolder, column );
column.bind();
return column;
}
@ -115,7 +123,8 @@ public class IndexColumn extends AnnotatedColumn {
final IndexColumn column = new IndexColumn();
column.setImplicit( true );
column.setBuildingContext( buildingContext );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
createParent( propertyHolder, column );
column.bind();
return column;
}
@ -145,7 +154,8 @@ public class IndexColumn extends AnnotatedColumn {
column.setNullable( ann.nullable() );
column.setBase( ann.base() );
column.setBuildingContext( buildingContext );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
createParent( propertyHolder, column );
column.bind();
return column;
}
@ -153,7 +163,8 @@ public class IndexColumn extends AnnotatedColumn {
final IndexColumn column = new IndexColumn();
column.setImplicit( true );
column.setBuildingContext( buildingContext );
column.setPropertyHolder( propertyHolder );
// column.setPropertyHolder( propertyHolder );
createParent( propertyHolder, column );
column.bind();
return column;
}

View File

@ -89,6 +89,8 @@ import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.cfg.AccessType;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotatedColumn;
import org.hibernate.cfg.AnnotatedColumns;
import org.hibernate.cfg.AnnotatedDiscriminatorColumn;
import org.hibernate.cfg.AnnotatedJoinColumns;
import org.hibernate.cfg.AnnotationBinder;
@ -788,7 +790,11 @@ public class EntityBinder {
throw new AssertionFailure( "discriminator column should have been built" );
}
discriminatorColumn.setJoins( secondaryTables );
discriminatorColumn.setPropertyHolder( propertyHolder );
// discriminatorColumn.setPropertyHolder( propertyHolder );
final AnnotatedColumns columns = new AnnotatedColumns();
columns.setColumns( new AnnotatedColumn[] { discriminatorColumn } );
columns.setPropertyHolder( propertyHolder );
final BasicValue discriminatorColumnBinding = new BasicValue( context, rootClass.getTable() );
rootClass.setDiscriminator( discriminatorColumnBinding );
discriminatorColumn.linkWithValue( discriminatorColumnBinding );

View File

@ -86,11 +86,13 @@ public class ListBinder extends CollectionBinder {
if ( !listValueMapping.isOneToMany() ) {
indexColumn.forceNotNull();
}
indexColumn.setPropertyHolder( valueHolder );
// indexColumn.setPropertyHolder( valueHolder );
final AnnotatedColumns columns = new AnnotatedColumns();
columns.setColumns( new AnnotatedColumn[] { indexColumn } );
columns.setPropertyHolder( valueHolder );
final BasicValueBinder valueBinder = new BasicValueBinder( BasicValueBinder.Kind.LIST_INDEX, buildingContext );
final AnnotatedColumns result = new AnnotatedColumns();
result.setColumns( new AnnotatedColumn[] { indexColumn } );
valueBinder.setColumns(result);
valueBinder.setColumns( columns );
valueBinder.setReturnedClassName( Integer.class.getName() );
valueBinder.setType( property, getElementType(), null, null );
// valueBinder.setExplicitType( "integer" );

View File

@ -199,7 +199,7 @@ public class PropertyBinder {
basicValueBinder.setAccessType( accessType );
SimpleValue propertyValue = basicValueBinder.make();
final SimpleValue propertyValue = basicValueBinder.make();
setValue( propertyValue );
return makeProperty();
}