Skip to content

Commit 28646ad

Browse files
committed
HHH-18462 Provide alternatives to deprecated org.hibernate.engine.spi.Mapping
1 parent e407c53 commit 28646ad

File tree

72 files changed

+1095
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1095
-148
lines changed

hibernate-core/src/main/java/org/hibernate/boot/Metadata.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.UUID;
1212
import java.util.function.Consumer;
1313

14+
import org.hibernate.MappingException;
1415
import org.hibernate.SessionFactory;
1516
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
1617
import org.hibernate.boot.model.NamedEntityGraphDefinition;
@@ -21,12 +22,13 @@
2122
import org.hibernate.boot.query.NamedProcedureCallDefinition;
2223
import org.hibernate.boot.query.NamedResultSetMappingDescriptor;
2324
import org.hibernate.engine.spi.FilterDefinition;
24-
import org.hibernate.engine.spi.Mapping;
2525
import org.hibernate.mapping.Collection;
2626
import org.hibernate.mapping.FetchProfile;
2727
import org.hibernate.mapping.PersistentClass;
2828
import org.hibernate.mapping.Table;
2929
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
30+
import org.hibernate.type.Type;
31+
import org.hibernate.type.spi.TypeConfiguration;
3032

3133
/**
3234
* Represents the ORM model as determined by aggregating the provided mapping sources.
@@ -36,7 +38,7 @@
3638
*
3739
* @since 5.0
3840
*/
39-
public interface Metadata extends Mapping {
41+
public interface Metadata {
4042
/**
4143
* Get the builder for {@link SessionFactory} instances based on this metamodel.
4244
*
@@ -203,4 +205,18 @@ public interface Metadata extends Mapping {
203205
* All of the known model contributors
204206
*/
205207
Set<String> getContributors();
208+
209+
TypeConfiguration getTypeConfiguration();
210+
211+
default Type getIdentifierType(String className) throws org.hibernate.MappingException {
212+
return getTypeConfiguration().getIdentifierType( className );
213+
}
214+
215+
default String getIdentifierPropertyName(String className) throws org.hibernate.MappingException {
216+
return getTypeConfiguration().getIdentifierPropertyName( className );
217+
}
218+
219+
default Type getReferencedPropertyType(String className, String propertyName) throws MappingException {
220+
return getTypeConfiguration().getReferencedPropertyType( className, propertyName );
221+
}
206222
}

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void validate() throws MappingException {
506506
}
507507

508508
for ( Collection collectionBinding : this.getCollectionBindings() ) {
509-
collectionBinding.validate( this );
509+
collectionBinding.validate( getTypeConfiguration() );
510510
}
511511
}
512512

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentSecondPass.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ else if ( value instanceof Collection ) {
239239
}
240240

241241
private boolean isAggregateArray() {
242-
switch ( component.getAggregateColumn().getSqlTypeCode( context.getMetadataCollector() ) ) {
242+
switch ( component.getAggregateColumn().getSqlTypeCode( context.getMetadataCollector().getTypeConfiguration() ) ) {
243243
case SqlTypes.STRUCT_ARRAY:
244244
case SqlTypes.STRUCT_TABLE:
245245
case SqlTypes.JSON_ARRAY:
@@ -386,7 +386,7 @@ private static void ensureChildrenInitialized(
386386
AggregateColumn aggregateColumn) {
387387
for ( Column aggregatedColumn : aggregateColumn.getComponent().getAggregatedColumns() ) {
388388
// Make sure this state is initialized
389-
aggregatedColumn.getSqlTypeCode( metadataCollector );
389+
aggregatedColumn.getSqlTypeCode( metadataCollector.getTypeConfiguration() );
390390
aggregatedColumn.getSqlType( metadataCollector );
391391
if ( aggregatedColumn instanceof AggregateColumn ) {
392392
ensureChildrenInitialized( metadataCollector, (AggregateColumn) aggregatedColumn );
@@ -402,7 +402,7 @@ private static void ensureParentInitialized(
402402
// Trigger resolving of the value so that the column gets properly filled
403403
aggregateColumn.getValue().getType();
404404
// Make sure this state is initialized
405-
aggregateColumn.getSqlTypeCode( metadataCollector );
405+
aggregateColumn.getSqlTypeCode( metadataCollector.getTypeConfiguration() );
406406
aggregateColumn.getSqlType( metadataCollector );
407407
aggregateColumn = aggregateColumn.getComponent().getParentAggregateColumn();
408408
} while ( aggregateColumn != null );

hibernate-core/src/main/java/org/hibernate/boot/model/relational/ColumnOrderingStrategyStandard.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.mapping.Table;
2222
import org.hibernate.mapping.UniqueKey;
2323
import org.hibernate.mapping.UserDefinedObjectType;
24+
import org.hibernate.type.spi.TypeConfiguration;
2425

2526
import static java.lang.Math.log;
2627
import static org.hibernate.type.SqlTypes.*;
@@ -80,14 +81,15 @@ protected ColumnComparator(Metadata metadata) {
8081
@Override
8182
public int compare(Column o1, Column o2) {
8283
final Dialect dialect = metadata.getDatabase().getDialect();
84+
final TypeConfiguration typeConfiguration = metadata.getTypeConfiguration();
8385
final int physicalSizeInBytes1 = physicalSizeInBytes(
84-
o1.getSqlTypeCode( metadata ),
85-
o1.getColumnSize( dialect, metadata ),
86+
o1.getSqlTypeCode( typeConfiguration ),
87+
o1.getColumnSize( dialect, typeConfiguration ),
8688
metadata
8789
);
8890
final int physicalSizeInBytes2 = physicalSizeInBytes(
89-
o2.getSqlTypeCode( metadata ),
90-
o2.getColumnSize( dialect, metadata ),
91+
o2.getSqlTypeCode( typeConfiguration ),
92+
o2.getColumnSize( dialect, typeConfiguration ),
9193
metadata
9294
);
9395
int cmp = Integer.compare( Integer.max( physicalSizeInBytes1, 4 ), Integer.max( physicalSizeInBytes2, 4 ) );

hibernate-core/src/main/java/org/hibernate/dialect/aggregate/DB2AggregateSupport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ private static void appendSerializer(List<Column> aggregatedColumns, StringBuild
396396
}
397397
else if ( needsVarcharForBitDataCast( udtColumn.getSqlType() ) ) {
398398
serializerSb.append( ",cast(" ).append( prefix ).append( udtColumn.getName() ).append( " as varchar(" )
399-
.append( udtColumn.getColumnSize( null, null ).getLength() ).append( ") for bit data)" );
399+
.append( udtColumn.getSize().getLength() )
400+
.append( ") for bit data)" );
400401
}
401402
else {
402403
serializerSb.append( ',' ).append( prefix ).append( udtColumn.getName() );
@@ -455,7 +456,7 @@ private static void appendDeserializerColumns(
455456
deserializerSb.append( prefix ).append( udtColumn.getName() ).append( ' ' );
456457
if ( needsVarcharForBitDataCast( udtColumn.getSqlType() ) ) {
457458
deserializerSb.append( "varchar(" )
458-
.append( udtColumn.getColumnSize( null, null ).getLength() ).append( ") for bit data" );
459+
.append( udtColumn.getSize().getLength() ).append( ") for bit data" );
459460
}
460461
else {
461462
deserializerSb.append( udtColumn.getSqlType() );

hibernate-core/src/main/java/org/hibernate/dialect/lock/AbstractSelectLockingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void lock(Object id, Object version, Object object, int timeout, EventSou
8585
lockable.getVersionType().nullSafeSet(
8686
st,
8787
version,
88-
lockable.getIdentifierType().getColumnSpan( factory ) + 1,
88+
lockable.getIdentifierType().getColumnSpan( factory.getTypeConfiguration() ) + 1,
8989
session
9090
);
9191
}

hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadUpdateLockingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void lock(Object id, Object version, Object object, int timeout, EventSou
8686
int offset = 2;
8787

8888
lockable.getIdentifierType().nullSafeSet( st, id, offset, session );
89-
offset += lockable.getIdentifierType().getColumnSpan( factory );
89+
offset += lockable.getIdentifierType().getColumnSpan( factory.getTypeConfiguration() );
9090

9191
if ( lockable.isVersioned() ) {
9292
lockable.getVersionType().nullSafeSet( st, version, offset, session );

hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteUpdateLockingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void lock(Object id, Object version, Object object, int timeout, EventSou
8585
int offset = 2;
8686

8787
lockable.getIdentifierType().nullSafeSet( st, id, offset, session );
88-
offset += lockable.getIdentifierType().getColumnSpan( factory );
88+
offset += lockable.getIdentifierType().getColumnSpan( factory.getTypeConfiguration() );
8989

9090
if ( lockable.isVersioned() ) {
9191
lockable.getVersionType().nullSafeSet( st, version, offset, session );

hibernate-core/src/main/java/org/hibernate/dialect/lock/UpdateLockingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void lock(
9292

9393
final Type lockableIdentifierType = lockable.getIdentifierType();
9494
lockableIdentifierType.nullSafeSet( st, id, offset, session );
95-
offset += lockableIdentifierType.getColumnSpan( factory );
95+
offset += lockableIdentifierType.getColumnSpan( factory.getTypeConfiguration() );
9696

9797
if ( lockable.isVersioned() ) {
9898
lockableVersionType.nullSafeSet( st, version, offset, session );

hibernate-core/src/main/java/org/hibernate/dialect/temptable/TemporaryTable.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static TemporaryTable createIdTable(
195195
),
196196
column.getColumnSize(
197197
dialect,
198-
runtimeModelCreationContext.getMetadata()
198+
runtimeModelCreationContext.getTypeConfiguration()
199199
),
200200
column.isNullable(),
201201
true
@@ -238,7 +238,7 @@ public static TemporaryTable createIdTable(
238238
),
239239
column.getColumnSize(
240240
dialect,
241-
runtimeModelCreationContext.getMetadata()
241+
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
242242
),
243243
column.isNullable()
244244
)
@@ -324,7 +324,7 @@ public static TemporaryTable createEntityTable(
324324
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
325325
sqlTypeName = column.getSqlType( runtimeModelCreationContext.getMetadata() ) + " ";
326326
}
327-
sqlTypeName = sqlTypeName + dialect.getIdentityColumnSupport().getIdentityColumnString( column.getSqlTypeCode( runtimeModelCreationContext.getMetadata() ) );
327+
sqlTypeName = sqlTypeName + dialect.getIdentityColumnSupport().getIdentityColumnString( column.getSqlTypeCode( runtimeModelCreationContext.getMetadata().getTypeConfiguration() ) );
328328
columns.add(
329329
new TemporaryTableColumn(
330330
temporaryTable,
@@ -333,7 +333,7 @@ public static TemporaryTable createEntityTable(
333333
sqlTypeName,
334334
column.getColumnSize(
335335
dialect,
336-
runtimeModelCreationContext.getMetadata()
336+
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
337337
),
338338
// Always report as nullable as the identity column string usually includes the not null constraint
339339
true,//column.isNullable()
@@ -365,7 +365,7 @@ public static TemporaryTable createEntityTable(
365365
),
366366
column.getColumnSize(
367367
dialect,
368-
runtimeModelCreationContext.getMetadata()
368+
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
369369
),
370370
// We have to set the identity column after the root table insert
371371
column.isNullable() || identityColumn || hasOptimizer,
@@ -387,7 +387,7 @@ public static TemporaryTable createEntityTable(
387387
),
388388
discriminator.getColumnSize(
389389
dialect,
390-
runtimeModelCreationContext.getMetadata()
390+
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
391391
),
392392
// We have to set the identity column after the root table insert
393393
discriminator.isNullable()
@@ -418,7 +418,7 @@ public static TemporaryTable createEntityTable(
418418
),
419419
column.getColumnSize(
420420
dialect,
421-
runtimeModelCreationContext.getMetadata()
421+
runtimeModelCreationContext.getMetadata().getTypeConfiguration()
422422
),
423423
// Treat regular temporary table columns as nullable for simplicity
424424
true

0 commit comments

Comments
 (0)