Skip to content

Commit 1b0cc59

Browse files
dreab8sebersole
authored andcommitted
HHH-18462 Provide alternatives to deprecated org.hibernate.engine.spi.Mapping
1 parent e411775 commit 1b0cc59

34 files changed

+408
-142
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import org.hibernate.boot.query.NamedProcedureCallDefinition;
2222
import org.hibernate.boot.query.NamedResultSetMappingDescriptor;
2323
import org.hibernate.engine.spi.FilterDefinition;
24-
import org.hibernate.engine.spi.Mapping;
2524
import org.hibernate.mapping.Collection;
2625
import org.hibernate.mapping.FetchProfile;
2726
import org.hibernate.mapping.PersistentClass;
2827
import org.hibernate.mapping.Table;
2928
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
29+
import org.hibernate.type.MappingContext;
3030

3131
/**
3232
* Represents the ORM model as determined by aggregating the provided mapping sources.
@@ -36,7 +36,7 @@
3636
*
3737
* @since 5.0
3838
*/
39-
public interface Metadata extends Mapping {
39+
public interface Metadata extends MappingContext {
4040
/**
4141
* Get the builder for {@link SessionFactory} instances based on this metamodel.
4242
*

hibernate-core/src/main/java/org/hibernate/engine/spi/Mapping.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
package org.hibernate.engine.spi;
88

9-
import org.hibernate.MappingException;
109
import org.hibernate.type.Type;
10+
import org.hibernate.type.MappingContext;
1111

1212
/**
1313
* Declares operations used by implementors of {@link Type} that are common to
@@ -23,11 +23,9 @@
2323
* @deprecated Use {@link org.hibernate.type.spi.TypeConfiguration},
2424
* {@link org.hibernate.boot.Metadata}, or
2525
* {@link org.hibernate.metamodel.RuntimeMetamodels}
26+
* or {@link MappingContext}
2627
* to access such information
2728
*/
2829
@Deprecated(since = "6.0")
29-
public interface Mapping {
30-
Type getIdentifierType(String className) throws MappingException;
31-
String getIdentifierPropertyName(String className) throws MappingException;
32-
Type getReferencedPropertyType(String className, String propertyName) throws MappingException;
30+
public interface Mapping extends MappingContext {
3331
}

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.hibernate.generator.Generator;
3434
import org.hibernate.type.descriptor.WrapperOptions;
3535
import org.hibernate.type.descriptor.java.JavaType;
36+
import org.hibernate.type.MappingContext;
3637
import org.hibernate.type.spi.TypeConfiguration;
3738

3839
/**
@@ -46,7 +47,7 @@
4647
* @author Steve Ebersole
4748
*/
4849
public interface SessionFactoryImplementor
49-
extends Mapping, SessionFactory, SqmCreationContext, SqlAstCreationContext,
50+
extends MappingContext, SessionFactory, SqmCreationContext, SqlAstCreationContext,
5051
QueryParameterBindingTypeResolver { //deprecated extension, use MappingMetamodel
5152
/**
5253
* Get the UUID for this {@code SessionFactory}.

hibernate-core/src/main/java/org/hibernate/id/ExportableColumn.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.hibernate.MappingException;
1313
import org.hibernate.boot.model.relational.Database;
1414
import org.hibernate.boot.spi.MetadataBuildingContext;
15-
import org.hibernate.engine.spi.Mapping;
1615
import org.hibernate.internal.util.collections.ArrayHelper;
1716
import org.hibernate.mapping.Column;
1817
import org.hibernate.mapping.Selectable;
@@ -22,6 +21,7 @@
2221
import org.hibernate.service.ServiceRegistry;
2322
import org.hibernate.type.BasicType;
2423
import org.hibernate.type.Type;
24+
import org.hibernate.type.MappingContext;
2525

2626
/**
2727
* @author Steve Ebersole
@@ -148,7 +148,7 @@ public boolean isSimpleValue() {
148148
}
149149

150150
@Override
151-
public boolean isValid(Mapping mapping) throws MappingException {
151+
public boolean isValid(MappingContext mappingContext) throws MappingException {
152152
return false;
153153
}
154154

hibernate-core/src/main/java/org/hibernate/mapping/Any.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import org.hibernate.MappingException;
1515
import org.hibernate.boot.spi.MetadataBuildingContext;
1616
import org.hibernate.engine.jdbc.spi.JdbcServices;
17-
import org.hibernate.engine.spi.Mapping;
1817
import org.hibernate.type.AnyType;
1918
import org.hibernate.type.Type;
19+
import org.hibernate.type.MappingContext;
2020

2121
/**
2222
* A mapping model object representing a {@linkplain org.hibernate.annotations.Any polymorphic association}
@@ -225,10 +225,12 @@ public void setLazy(boolean lazy) {
225225
this.lazy = lazy;
226226
}
227227

228+
@Override
228229
public void setTypeUsingReflection(String className, String propertyName)
229230
throws MappingException {
230231
}
231232

233+
@Override
232234
public Object accept(ValueVisitor visitor) {
233235
return visitor.accept(this);
234236
}
@@ -250,11 +252,12 @@ private String getTypeNameOrNull(SimpleValue simpleValue) {
250252
return simpleValue != null ? simpleValue.getTypeName() : null;
251253
}
252254

253-
public boolean isValid(Mapping mapping) throws MappingException {
255+
@Override
256+
public boolean isValid(MappingContext mappingContext) throws MappingException {
254257
if ( discriminatorDescriptor != null ) {
255-
return discriminatorDescriptor.isValid( mapping ) && keyDescriptor.isValid( mapping );
258+
return discriminatorDescriptor.isValid( mappingContext ) && keyDescriptor.isValid( mappingContext );
256259
}
257-
return metaMapping.isValid( mapping ) && keyMapping.isValid( mapping );
260+
return metaMapping.isValid( mappingContext ) && keyMapping.isValid( mappingContext );
258261
}
259262

260263
private static String columnName(Column column, MetadataBuildingContext buildingContext) {
@@ -391,9 +394,9 @@ public void addFormula(Formula formula) {
391394
}
392395

393396
@Override
394-
public boolean isValid(Mapping mapping) {
397+
public boolean isValid(MappingContext mappingContext) {
395398
return columnName != null
396-
&& getType().getColumnSpan( mapping ) == 1;
399+
&& getType().getColumnSpan( mappingContext ) == 1;
397400
}
398401
}
399402

@@ -465,9 +468,9 @@ public void addFormula(Formula formula) {
465468
}
466469

467470
@Override
468-
public boolean isValid(Mapping mapping) throws MappingException {
471+
public boolean isValid(MappingContext mappingContext) throws MappingException {
469472
// check
470-
return super.isValid( mapping );
473+
return super.isValid( mappingContext );
471474
}
472475
}
473476
}

hibernate-core/src/main/java/org/hibernate/mapping/Collection.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.hibernate.type.CollectionType;
3434
import org.hibernate.type.CustomCollectionType;
3535
import org.hibernate.type.Type;
36+
import org.hibernate.type.MappingContext;
3637
import org.hibernate.usertype.UserCollectionType;
3738

3839
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_BOOLEAN_ARRAY;
@@ -245,10 +246,12 @@ public Comparator<?> getComparator() {
245246
return comparator;
246247
}
247248

249+
@Override
248250
public boolean isLazy() {
249251
return lazy;
250252
}
251253

254+
@Override
252255
public void setLazy(boolean lazy) {
253256
this.lazy = lazy;
254257
}
@@ -267,6 +270,7 @@ public boolean isArray() {
267270
return false;
268271
}
269272

273+
@Override
270274
public boolean hasFormula() {
271275
return false;
272276
}
@@ -363,29 +367,39 @@ public void setBatchSize(int batchSize) {
363367
this.batchSize = batchSize;
364368
}
365369

370+
@Override
366371
public FetchMode getFetchMode() {
367372
return fetchMode;
368373
}
369374

375+
@Override
370376
public void setFetchMode(FetchMode fetchMode) {
371377
this.fetchMode = fetchMode;
372378
}
373379

380+
/**
381+
* @deprecated use {@link #validate(MappingContext)}
382+
*/
383+
@Deprecated(since = "7.0")
374384
public void validate(Mapping mapping) throws MappingException {
385+
validate( (MappingContext) mapping);
386+
}
387+
388+
public void validate(MappingContext mappingContext) throws MappingException {
375389
assert getKey() != null : "Collection key not bound : " + getRole();
376390
assert getElement() != null : "Collection element not bound : " + getRole();
377391

378-
if ( !getKey().isValid( mapping ) ) {
392+
if ( !getKey().isValid( mappingContext ) ) {
379393
throw new MappingException(
380-
"collection foreign key mapping has wrong number of columns: "
394+
"collection foreign key mappingContext has wrong number of columns: "
381395
+ getRole()
382396
+ " type: "
383397
+ getKey().getType().getName()
384398
);
385399
}
386-
if ( !getElement().isValid( mapping ) ) {
400+
if ( !getElement().isValid( mappingContext ) ) {
387401
throw new MappingException(
388-
"collection element mapping has wrong number of columns: "
402+
"collection element mappingContext has wrong number of columns: "
389403
+ getRole()
390404
+ " type: "
391405
+ getElement().getType().getName()
@@ -420,10 +434,12 @@ public List<Column> getColumns() {
420434
return Collections.emptyList();
421435
}
422436

437+
@Override
423438
public int getColumnSpan() {
424439
return 0;
425440
}
426441

442+
@Override
427443
public Type getType() throws MappingException {
428444
return getCollectionType();
429445
}
@@ -483,30 +499,36 @@ public CollectionType getCollectionType() {
483499
return cachedCollectionType;
484500
}
485501

502+
@Override
486503
public boolean isNullable() {
487504
return true;
488505
}
489506

507+
@Override
490508
public boolean isAlternateUniqueKey() {
491509
return false;
492510
}
493511

512+
@Override
494513
public Table getTable() {
495514
return owner.getTable();
496515
}
497516

517+
@Override
498518
public void createForeignKey() {
499519
}
500520

501521
@Override
502522
public void createUniqueKey(MetadataBuildingContext context) {
503523
}
504524

525+
@Override
505526
public boolean isSimpleValue() {
506527
return false;
507528
}
508529

509-
public boolean isValid(Mapping mapping) {
530+
@Override
531+
public boolean isValid(MappingContext mappingContext) {
510532
return true;
511533
}
512534

@@ -558,6 +580,7 @@ public void setCacheConcurrencyStrategy(String cacheConcurrencyStrategy) {
558580
this.cacheConcurrencyStrategy = cacheConcurrencyStrategy;
559581
}
560582

583+
@Override
561584
public void setTypeUsingReflection(String className, String propertyName) {
562585
}
563586

@@ -644,6 +667,7 @@ public ExecuteUpdateResultCheckStyle getCustomSQLDeleteAllCheckStyle() {
644667
return deleteAllCheckStyle;
645668
}
646669

670+
@Override
647671
public void addFilter(
648672
String name,
649673
String condition,
@@ -662,6 +686,7 @@ public void addFilter(
662686
);
663687
}
664688

689+
@Override
665690
public List<FilterConfiguration> getFilters() {
666691
return filters;
667692
}

0 commit comments

Comments
 (0)