From 18003b92dceb06162799485d19786716d11b4178 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Mon, 31 Oct 2022 02:10:37 +0100 Subject: [PATCH] finally move propertyHolder from AnnotatedColumn --- .../org/hibernate/cfg/AnnotatedColumn.java | 49 ++++++++++--------- .../hibernate/cfg/AnnotatedJoinColumn.java | 14 +++--- .../hibernate/cfg/AnnotatedJoinColumns.java | 28 ++++------- .../java/org/hibernate/cfg/IndexColumn.java | 37 +++++++++----- .../cfg/annotations/EntityBinder.java | 8 ++- .../hibernate/cfg/annotations/ListBinder.java | 10 ++-- .../cfg/annotations/PropertyBinder.java | 2 +- 7 files changed, 80 insertions(+), 68 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedColumn.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedColumn.java index e3da37349b..b230687fd5 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedColumn.java @@ -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 joins; - @Deprecated // use AnnotatedColumns.propertyHolder - protected PropertyHolder propertyHolder; private boolean isImplicit; public String sqlType; private Long length; @@ -358,7 +356,7 @@ public class AnnotatedColumn { Identifier implicitName = normalizer.normalizeIdentifierQuoting( implicitNamingStrategy.determineBasicColumnName( new ImplicitBasicColumnNameSource() { - final AttributePath attributePath = AttributePath.parse(propertyName); + final AttributePath attributePath = AttributePath.parse( propertyName ); @Override public AttributePath getAttributePath() { @@ -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 { @@ -774,8 +767,8 @@ public class AnnotatedColumn { ); } final AnnotatedColumns result = new AnnotatedColumns(); - result.setPropertyHolder(propertyHolder); - result.setColumns(columns); + result.setPropertyHolder( propertyHolder ); + result.setColumns( columns ); return result; } @@ -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() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumn.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumn.java index 621ef12078..12f546da94 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumn.java @@ -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 ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumns.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumns.java index 752d227c4f..6ca3b7c1b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumns.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotatedJoinColumns.java @@ -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 joins, Map 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() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/IndexColumn.java b/hibernate-core/src/main/java/org/hibernate/cfg/IndexColumn.java index a4339c06e7..986b8f0755 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/IndexColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/IndexColumn.java @@ -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 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; } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java index 9d4664b9a4..748c11b8b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java @@ -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 ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java index 3f63659aef..82416fbf1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java @@ -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" ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java index e66ef43981..bcc07029f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java @@ -199,7 +199,7 @@ public class PropertyBinder { basicValueBinder.setAccessType( accessType ); - SimpleValue propertyValue = basicValueBinder.make(); + final SimpleValue propertyValue = basicValueBinder.make(); setValue( propertyValue ); return makeProperty(); }