Skip to content

Commit 3525545

Browse files
committed
mic very minor cleanups in mapping package
1 parent b75d9d7 commit 3525545

File tree

9 files changed

+67
-101
lines changed

9 files changed

+67
-101
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public final class JoinedSubclass extends Subclass implements TableOwner {
2121
private Table table;
2222
private KeyValue key;
2323

24-
public JoinedSubclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) {
25-
super( superclass, metadataBuildingContext );
24+
public JoinedSubclass(PersistentClass superclass, MetadataBuildingContext buildingContext) {
25+
super( superclass, buildingContext );
2626
}
2727

2828
@Override

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,9 @@ public Join getSecondaryTable(String name) {
213213

214214
@Override
215215
public IdentifiableTypeClass getSuperType() {
216-
if ( superPersistentClass != null ) {
217-
return superPersistentClass;
218-
}
219-
return superMappedSuperclass;
216+
return superPersistentClass != null
217+
? superPersistentClass
218+
: superMappedSuperclass;
220219
}
221220

222221
@Override
@@ -231,8 +230,8 @@ public Table getImplicitTable() {
231230

232231
@Override
233232
public void applyProperty(Property property) {
234-
assert property.getValue().getTable() != null;
235-
assert property.getValue().getTable().equals( getImplicitTable() );
233+
assert property.getValue().getTable() != null
234+
&& property.getValue().getTable().equals( getImplicitTable() );
236235
addDeclaredProperty( property );
237236
}
238237
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public static void checkPropertyColumnDuplication(
105105
Set<String> distinctColumns,
106106
List<Property> properties,
107107
String owner) throws MappingException {
108-
for ( var prop : properties ) {
109-
if ( prop.isUpdatable() || prop.isInsertable() ) {
110-
prop.getValue().checkColumnDuplication( distinctColumns, owner );
108+
for ( var property : properties ) {
109+
if ( property.isUpdatable() || property.isInsertable() ) {
110+
property.getValue().checkColumnDuplication( distinctColumns, owner );
111111
}
112112
}
113113
}
@@ -117,7 +117,7 @@ static Class<?> classForName(String typeName, BootstrapContext bootstrapContext)
117117
}
118118

119119
static <T> Class<? extends T> classForName(Class<T> supertype, String typeName, BootstrapContext bootstrapContext) {
120-
final Class<?> clazz = classForName( typeName, bootstrapContext );
120+
final var clazz = classForName( typeName, bootstrapContext );
121121
if ( supertype.isAssignableFrom( clazz ) ) {
122122
//noinspection unchecked
123123
return (Class<? extends T>) clazz;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
import org.hibernate.MappingException;
1212
import org.hibernate.annotations.NotFoundAction;
1313
import org.hibernate.boot.spi.MetadataBuildingContext;
14-
import org.hibernate.internal.util.collections.ArrayHelper;
1514
import org.hibernate.service.ServiceRegistry;
1615
import org.hibernate.type.ManyToOneType;
1716
import org.hibernate.type.Type;
1817
import org.hibernate.type.MappingContext;
1918

19+
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_BOOLEAN_ARRAY;
20+
2021
/**
2122
* A mapping model object representing a {@linkplain jakarta.persistence.OneToMany many-to-one association}.
2223
*
@@ -183,7 +184,7 @@ public boolean isSame(OneToMany other) {
183184
@Override
184185
public boolean[] getColumnInsertability() {
185186
//TODO: we could just return all false...
186-
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
187+
return EMPTY_BOOLEAN_ARRAY;
187188
}
188189

189190
@Override
@@ -194,7 +195,7 @@ public boolean hasAnyInsertableColumns() {
194195
@Override
195196
public boolean[] getColumnUpdateability() {
196197
//TODO: we could just return all false...
197-
return ArrayHelper.EMPTY_BOOLEAN_ARRAY;
198+
return EMPTY_BOOLEAN_ARRAY;
198199
}
199200

200201
@Override
@@ -215,9 +216,7 @@ public boolean isIgnoreNotFound() {
215216
}
216217

217218
public void setIgnoreNotFound(boolean ignoreNotFound) {
218-
this.notFoundAction = ignoreNotFound
219-
? NotFoundAction.IGNORE
220-
: null;
219+
notFoundAction = ignoreNotFound ? NotFoundAction.IGNORE : null;
221220
}
222221

223222
@Override

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.hibernate.service.ServiceRegistry;
3232
import org.hibernate.sql.Alias;
3333
import org.hibernate.type.CollectionType;
34-
import org.hibernate.type.Type;
3534
import org.hibernate.type.spi.TypeConfiguration;
3635

3736
import static java.util.Collections.emptyList;
@@ -370,7 +369,7 @@ public List<Property> getSubclassPropertyClosure() {
370369
final ArrayList<List<Property>> lists = new ArrayList<>();
371370
lists.add( getPropertyClosure() );
372371
lists.add( subclassProperties );
373-
for ( Join join : subclassJoins ) {
372+
for ( var join : subclassJoins ) {
374373
lists.add( join.getProperties() );
375374
}
376375
return new JoinedList<>( lists );
@@ -641,7 +640,7 @@ public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) {
641640
public void validate(Metadata mapping) throws MappingException {
642641
for ( var prop : getProperties() ) {
643642
if ( !prop.isValid( mapping ) ) {
644-
final Type type = prop.getType();
643+
final var type = prop.getType();
645644
final int actualColumns = prop.getColumnSpan();
646645
final int requiredColumns = type.getColumnSpan( mapping );
647646
throw new MappingException(
@@ -699,7 +698,7 @@ public List<Join> getJoinClosure() {
699698
}
700699

701700
public void addJoin(Join join) {
702-
if ( !joins.contains(join) ) {
701+
if ( !joins.contains( join ) ) {
703702
joins.add( join );
704703
}
705704
join.setPersistentClass( this );
@@ -868,8 +867,9 @@ protected void checkColumnDuplication() {
868867
if ( isDiscriminatorInsertable() && getDiscriminator() != null ) {
869868
getDiscriminator().checkColumnDuplication( cols, owner );
870869
}
871-
if ( getRootClass().getSoftDeleteColumn() != null ) {
872-
getRootClass().getSoftDeleteColumn().getValue().checkColumnDuplication( cols, owner );
870+
final var softDeleteColumn = getRootClass().getSoftDeleteColumn();
871+
if ( softDeleteColumn != null ) {
872+
softDeleteColumn.getValue().checkColumnDuplication( cols, owner );
873873
}
874874
checkPropertyColumnDuplication( cols, getNonDuplicatedProperties(), owner );
875875
for ( var join : getJoins() ) {
@@ -923,12 +923,14 @@ else if ( value instanceof org.hibernate.mapping.Collection collection ) {
923923
}
924924

925925
public boolean hasPartitionedSelectionMapping() {
926-
if ( getSuperclass() != null && getSuperclass().hasPartitionedSelectionMapping() ) {
926+
final var superclass = getSuperclass();
927+
if ( superclass != null
928+
&& superclass.hasPartitionedSelectionMapping() ) {
927929
return true;
928930
}
929931
for ( var property : getProperties() ) {
930-
final var value = property.getValue();
931-
if ( value instanceof BasicValue basicValue && basicValue.isPartitionKey() ) {
932+
if ( property.getValue() instanceof BasicValue basicValue
933+
&& basicValue.isPartitionKey() ) {
932934
return true;
933935
}
934936
}
@@ -952,13 +954,12 @@ public boolean hasIdentifierMapper() {
952954
}
953955

954956
public void addCallbackDefinitions(java.util.List<CallbackDefinition> callbackDefinitions) {
955-
if ( callbackDefinitions == null || callbackDefinitions.isEmpty() ) {
956-
return;
957-
}
958-
if ( this.callbackDefinitions == null ) {
959-
this.callbackDefinitions = new ArrayList<>();
957+
if ( callbackDefinitions != null && !callbackDefinitions.isEmpty() ) {
958+
if ( this.callbackDefinitions == null ) {
959+
this.callbackDefinitions = new ArrayList<>();
960+
}
961+
this.callbackDefinitions.addAll( callbackDefinitions );
960962
}
961-
this.callbackDefinitions.addAll( callbackDefinitions );
962963
}
963964

964965
public java.util.List<CallbackDefinition> getCallbackDefinitions() {

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55
package org.hibernate.mapping;
66

7-
import java.util.Arrays;
87
import java.util.List;
98

109
import org.hibernate.Internal;
1110

11+
import static java.util.Arrays.asList;
1212
import static org.hibernate.internal.util.StringHelper.qualify;
1313

1414
/**
@@ -55,7 +55,7 @@ public List<Column> getColumnsInOriginalOrder() {
5555
for ( int i = 0; i < columnsInOriginalOrder.length; i++ ) {
5656
columnsInOriginalOrder[originalOrder[i]] = columns.get( i );
5757
}
58-
return Arrays.asList( columnsInOriginalOrder );
58+
return asList( columnsInOriginalOrder );
5959
}
6060

6161
public void setOrderingUniqueKey(UniqueKey uniqueKey) {
@@ -71,22 +71,23 @@ public void reorderColumns(List<Column> reorderedColumns) {
7171
final var columns = getColumns();
7272
if ( originalOrder != null ) {
7373
assert columns.equals( reorderedColumns );
74-
return;
7574
}
76-
assert columns.size() == reorderedColumns.size()
77-
&& columns.containsAll( reorderedColumns );
78-
originalOrder = new int[columns.size()];
79-
final var orderingUniqueKey = getOrderingUniqueKey();
80-
final var newColumns =
81-
orderingUniqueKey != null
82-
? orderingUniqueKey.getColumns()
83-
: reorderedColumns;
84-
for ( int i = 0; i < newColumns.size(); i++ ) {
85-
final var reorderedColumn = newColumns.get( i );
86-
originalOrder[i] = columns.indexOf( reorderedColumn );
75+
else {
76+
assert columns.size() == reorderedColumns.size()
77+
&& columns.containsAll( reorderedColumns );
78+
originalOrder = new int[columns.size()];
79+
final var orderingUniqueKey = getOrderingUniqueKey();
80+
final var newColumns =
81+
orderingUniqueKey != null
82+
? orderingUniqueKey.getColumns()
83+
: reorderedColumns;
84+
for ( int i = 0; i < newColumns.size(); i++ ) {
85+
final var reorderedColumn = newColumns.get( i );
86+
originalOrder[i] = columns.indexOf( reorderedColumn );
87+
}
88+
columns.clear();
89+
columns.addAll( newColumns );
8790
}
88-
columns.clear();
89-
columns.addAll( newColumns );
9091
}
9192

9293
@Internal

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private void checkTableDuplication() {
295295
if ( hasSubclasses() ) {
296296
final Set<Table> tables = new HashSet<>();
297297
tables.add( getTable() );
298-
for ( Subclass subclass : getSubclasses() ) {
298+
for ( var subclass : getSubclasses() ) {
299299
if ( !(subclass instanceof SingleTableSubclass) ) {
300300
final var table = subclass.getTable();
301301
if ( !tables.add( table ) ) {

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

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,21 @@ public String getNullValue() {
485485
* @see org.hibernate.engine.spi.VersionValue
486486
*/
487487
public void setNullValue(String nullValue) {
488-
nullValueSemantic = switch (nullValue) {
488+
nullValueSemantic = decodeNullValueSemantic( nullValue );
489+
if ( nullValueSemantic == NullValueSemantic.VALUE ) {
490+
this.nullValue = nullValue;
491+
}
492+
}
493+
494+
private static NullValueSemantic decodeNullValueSemantic(String nullValue) {
495+
return switch ( nullValue ) {
489496
// magical values (legacy of hbm.xml)
490497
case "null" -> NullValueSemantic.NULL;
491498
case "none" -> NullValueSemantic.NONE;
492499
case "any" -> NullValueSemantic.ANY;
493500
case "undefined" -> NullValueSemantic.UNDEFINED;
494501
default -> NullValueSemantic.VALUE;
495502
};
496-
if ( nullValueSemantic == NullValueSemantic.VALUE ) {
497-
this.nullValue = nullValue;
498-
}
499503
}
500504

501505
/**
@@ -615,45 +619,6 @@ protected ConverterDescriptor<?,?> getAttributeConverterDescriptor() {
615619
return attributeConverterDescriptor;
616620
}
617621

618-
// public Type getType() throws MappingException {
619-
// if ( type != null ) {
620-
// return type;
621-
// }
622-
//
623-
// if ( typeName == null ) {
624-
// throw new MappingException( "No type name" );
625-
// }
626-
//
627-
// if ( typeParameters != null
628-
// && Boolean.valueOf( typeParameters.getProperty( DynamicParameterizedType.IS_DYNAMIC ) )
629-
// && typeParameters.get( DynamicParameterizedType.PARAMETER_TYPE ) == null ) {
630-
// createParameterImpl();
631-
// }
632-
//
633-
// Type result = getMetadata().getTypeConfiguration().getTypeResolver().heuristicType( typeName, typeParameters );
634-
//
635-
// if ( isVersion && result instanceof BinaryType ) {
636-
// // if this is a byte[] version/timestamp, then we need to use RowVersionType
637-
// // instead of BinaryType (HHH-10413)
638-
// // todo (6.0) - although for T/SQL databases we should use its
639-
// LOG.debug( "version is BinaryType; changing to RowVersionType" );
640-
// result = RowVersionType.INSTANCE;
641-
// }
642-
//
643-
// if ( result == null ) {
644-
// String msg = "Could not determine type for: " + typeName;
645-
// if ( table != null ) {
646-
// msg += ", at table: " + table.getName();
647-
// }
648-
// if ( columns != null && columns.size() > 0 ) {
649-
// msg += ", for columns: " + columns;
650-
// }
651-
// throw new MappingException( msg );
652-
// }
653-
//
654-
// return result;
655-
// }
656-
657622
@Override
658623
public void setTypeUsingReflection(String className, String propertyName) throws MappingException {
659624
// NOTE: this is called as the last piece in setting SimpleValue type information,
@@ -669,10 +634,10 @@ public void setTypeUsingReflection(String className, String propertyName) throws
669634
"Attribute types for a dynamic entity must be explicitly specified: " + propertyName );
670635
}
671636
typeName = getClass( className, propertyName ).getName();
672-
// todo : to fully support isNationalized here we need to do the process hinted at above
673-
// essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt resolving
674-
// a (1) JdbcType, a (2) JavaType and dynamically building a BasicType
675-
// combining them.
637+
// TODO: To fully support isNationalized here we need to do the process hinted at above
638+
// essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt
639+
// resolving a (1) JdbcType, a (2) JavaType and dynamically building a BasicType
640+
// combining them.
676641
}
677642
else {
678643
// we had an AttributeConverter
@@ -896,7 +861,6 @@ public boolean hasAnyUpdatableColumns() {
896861
return true;
897862
}
898863
}
899-
900864
return false;
901865
}
902866

@@ -944,9 +908,11 @@ public void setJpaAttributeConverterDescriptor(ConverterDescriptor<?,?> descript
944908
private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
945909
private static Annotation[] getAnnotations(MemberDetails memberDetails) {
946910
final var directAnnotationUsages =
947-
memberDetails == null ? null
911+
memberDetails == null
912+
? null
948913
: memberDetails.getDirectAnnotationUsages();
949-
return directAnnotationUsages == null ? NO_ANNOTATIONS
914+
return directAnnotationUsages == null
915+
? NO_ANNOTATIONS
950916
: directAnnotationUsages.toArray( Annotation[]::new );
951917
}
952918

hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ public EmbeddableDomainType<?> locateEmbeddable(Class<?> embeddableClass, Compon
878878
final var embeddableDomainTypes = embeddablesToProcess.get( embeddableClass );
879879
if ( embeddableDomainTypes != null ) {
880880
for ( var embeddableDomainType : embeddableDomainTypes ) {
881-
final Component cachedComponent = componentByEmbeddable.get( embeddableDomainType );
881+
final var cachedComponent = componentByEmbeddable.get( embeddableDomainType );
882882
if ( cachedComponent.isSame( component ) ) {
883883
return embeddableDomainType;
884884
}

0 commit comments

Comments
 (0)