Skip to content

Commit 0b25e5a

Browse files
committed
HHH-18462 Provide alternatives to deprecated org.hibernate.engine.spi.Mapping
1 parent 4bd1642 commit 0b25e5a

File tree

72 files changed

+1088
-145
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

+1088
-145
lines changed

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

Lines changed: 11 additions & 0 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;
@@ -27,6 +28,8 @@
2728
import org.hibernate.mapping.PersistentClass;
2829
import org.hibernate.mapping.Table;
2930
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
31+
import org.hibernate.type.Type;
32+
import org.hibernate.type.spi.TypeConfiguration;
3033

3134
/**
3235
* Represents the ORM model as determined by aggregating the provided mapping sources.
@@ -203,4 +206,12 @@ public interface Metadata extends Mapping {
203206
* All of the known model contributors
204207
*/
205208
Set<String> getContributors();
209+
210+
TypeConfiguration getTypeConfiguration();
211+
212+
Type getIdentifierType(String className) throws org.hibernate.MappingException;
213+
214+
String getIdentifierPropertyName(String className);
215+
216+
Type getReferencedPropertyType(String className, String propertyName);
206217
}

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
@@ -477,7 +477,7 @@ public void validate() throws MappingException {
477477
}
478478

479479
for ( Collection collectionBinding : this.getCollectionBindings() ) {
480-
collectionBinding.validate( this );
480+
collectionBinding.validate( getTypeConfiguration() );
481481
}
482482
}
483483

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
@@ -397,7 +397,8 @@ private static void appendSerializer(List<Column> aggregatedColumns, StringBuild
397397
}
398398
else if ( needsVarcharForBitDataCast( udtColumn.getSqlType() ) ) {
399399
serializerSb.append( ",cast(" ).append( prefix ).append( udtColumn.getName() ).append( " as varchar(" )
400-
.append( udtColumn.getColumnSize( null, null ).getLength() ).append( ") for bit data)" );
400+
.append( udtColumn.getSize().getLength() )
401+
.append( ") for bit data)" );
401402
}
402403
else {
403404
serializerSb.append( ',' ).append( prefix ).append( udtColumn.getName() );
@@ -456,7 +457,7 @@ private static void appendDeserializerColumns(
456457
deserializerSb.append( prefix ).append( udtColumn.getName() ).append( ' ' );
457458
if ( needsVarcharForBitDataCast( udtColumn.getSqlType() ) ) {
458459
deserializerSb.append( "varchar(" )
459-
.append( udtColumn.getColumnSize( null, null ).getLength() ).append( ") for bit data" );
460+
.append( udtColumn.getSize().getLength() ).append( ") for bit data" );
460461
}
461462
else {
462463
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)