Skip to content

Commit c0a1433

Browse files
committed
some misc cleanups to mapping package
Signed-off-by: Gavin King <[email protected]>
1 parent 4dcfdb5 commit c0a1433

File tree

8 files changed

+86
-111
lines changed

8 files changed

+86
-111
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ public static String[] unquote(final String[] names, final Dialect dialect) {
819819
return names;
820820
}
821821
else {
822-
String[] unquoted = new String[length];
822+
final String[] unquoted = new String[length];
823823
System.arraycopy( names, 0, unquoted, 0, failedIndex );
824824
for ( int i = failedIndex; i < length; i++ ) {
825825
unquoted[i] = unquote( names[i], dialect );
@@ -889,8 +889,8 @@ public interface Renderer<T> {
889889
* if both {@code firstExpression} and {@code secondExpression} are empty, then null is returned.
890890
*/
891891
public static String getNonEmptyOrConjunctionIfBothNonEmpty( String firstExpression, String secondExpression ) {
892-
final boolean isFirstExpressionNonEmpty = StringHelper.isNotEmpty( firstExpression );
893-
final boolean isSecondExpressionNonEmpty = StringHelper.isNotEmpty( secondExpression );
892+
final boolean isFirstExpressionNonEmpty = isNotEmpty( firstExpression );
893+
final boolean isSecondExpressionNonEmpty = isNotEmpty( secondExpression );
894894
if ( isFirstExpressionNonEmpty && isSecondExpressionNonEmpty ) {
895895
return "( " + firstExpression + " ) and ( " + secondExpression + " )";
896896
}
@@ -918,12 +918,7 @@ else if ( isSecondExpressionNonEmpty ) {
918918
* @return The interned string.
919919
*/
920920
public static String safeInterning(final String string) {
921-
if ( string == null ) {
922-
return null;
923-
}
924-
else {
925-
return string.intern();
926-
}
921+
return string == null ? null : string.intern();
927922
}
928923

929924
}

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

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.hibernate.annotations.SoftDelete;
1818
import org.hibernate.annotations.SoftDeleteType;
1919
import org.hibernate.annotations.TimeZoneStorageType;
20+
import org.hibernate.boot.internal.ClassmateContext;
2021
import org.hibernate.boot.model.TypeDefinition;
2122
import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorBypassedImpl;
2223
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
@@ -33,6 +34,7 @@
3334
import org.hibernate.boot.registry.StandardServiceRegistry;
3435
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
3536
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
37+
import org.hibernate.boot.spi.InFlightMetadataCollector;
3638
import org.hibernate.boot.spi.MetadataBuildingContext;
3739
import org.hibernate.dialect.Dialect;
3840
import org.hibernate.engine.jdbc.Size;
@@ -172,10 +174,8 @@ public void setTypeUsingReflection(String className, String propertyName) throws
172174
if ( resolution != null ) {
173175
throw new IllegalStateException( "BasicValue already resolved" );
174176
}
175-
176177
this.ownerName = className;
177178
this.propertyName = propertyName;
178-
179179
super.setTypeUsingReflection( className, propertyName );
180180
}
181181

@@ -197,7 +197,6 @@ public void setTimeZoneStorageType(TimeZoneStorageType timeZoneStorageType) {
197197

198198
public void setJpaAttributeConverterDescriptor(ConverterDescriptor descriptor) {
199199
setAttributeConverterDescriptor( descriptor );
200-
201200
super.setJpaAttributeConverterDescriptor( descriptor );
202201
}
203202

@@ -249,8 +248,10 @@ public int getColumnPrecision() {
249248
if ( temporalPrecision != null ) {
250249
return temporalPrecision;
251250
}
252-
final Integer precision = column.getPrecision();
253-
return precision == null ? NO_COLUMN_PRECISION : precision;
251+
else {
252+
final Integer precision = column.getPrecision();
253+
return precision == null ? NO_COLUMN_PRECISION : precision;
254+
}
254255
}
255256
else {
256257
return NO_COLUMN_PRECISION;
@@ -313,7 +314,6 @@ public void addColumn(Column incomingColumn, boolean isInsertable, boolean isUpd
313314
@Override
314315
public void addFormula(Formula formula) {
315316
super.addFormula( formula );
316-
317317
checkSelectable( formula );
318318
}
319319

@@ -324,7 +324,6 @@ public void addFormula(Formula formula) {
324324
public Type getType() throws MappingException {
325325
resolve();
326326
assert getResolution() != null;
327-
328327
return getResolution().getLegacyResolvedBasicType();
329328
}
330329

@@ -343,32 +342,30 @@ public Resolution<?> resolve() {
343342
if ( resolution != null ) {
344343
return resolution;
345344
}
346-
347-
resolution = buildResolution();
348-
349-
if ( resolution == null ) {
350-
throw new IllegalStateException( "Unable to resolve BasicValue : " + this );
351-
}
352-
353-
final Selectable selectable = getColumn();
354-
final Size size;
355-
if ( selectable instanceof Column column ) {
356-
resolveColumn( column, getDialect() );
357-
size = column.calculateColumnSize( getDialect(), getBuildingContext().getMetadataCollector() );
358-
}
359345
else {
360-
size = Size.nil();
346+
resolution = buildResolution();
347+
if ( resolution == null ) {
348+
throw new IllegalStateException( "Unable to resolve BasicValue : " + this );
349+
}
350+
else {
351+
final Size size;
352+
if ( getColumn() instanceof Column column ) {
353+
resolveColumn( column, getDialect() );
354+
size = column.calculateColumnSize( getDialect(), getMetadataCollector() );
355+
}
356+
else {
357+
size = Size.nil();
358+
}
359+
resolution.getJdbcType().addAuxiliaryDatabaseObjects(
360+
resolution.getRelationalJavaType(),
361+
resolution.getValueConverter(),
362+
size,
363+
getMetadataCollector().getDatabase(),
364+
this
365+
);
366+
return resolution;
367+
}
361368
}
362-
363-
resolution.getJdbcType().addAuxiliaryDatabaseObjects(
364-
resolution.getRelationalJavaType(),
365-
resolution.getValueConverter(),
366-
size,
367-
getBuildingContext().getMetadataCollector().getDatabase(),
368-
this
369-
);
370-
371-
return resolution;
372369
}
373370

374371
@Override
@@ -378,7 +375,7 @@ public String getExtraCreateTableInfo() {
378375
resolution.getRelationalJavaType(),
379376
getColumn().getText(),
380377
getTable().getName(),
381-
getBuildingContext().getMetadataCollector().getDatabase()
378+
getMetadataCollector().getDatabase()
382379
);
383380
}
384381

@@ -483,26 +480,18 @@ private ConverterDescriptor getSoftDeleteConverterDescriptor(
483480
SoftDelete.UnspecifiedConversion.class.equals( attributeConverterDescriptor.getAttributeConverterClass() );
484481
if ( conversionWasUnspecified ) {
485482
final JdbcType jdbcType = BooleanJdbcType.INSTANCE.resolveIndicatedType( this, javaType);
483+
final ClassmateContext classmateContext = getBuildingContext().getBootstrapContext().getClassmateContext();
486484
if ( jdbcType.isNumber() ) {
487-
return new InstanceBasedConverterDescriptor(
488-
NumericBooleanConverter.INSTANCE,
489-
getBuildingContext().getBootstrapContext().getClassmateContext()
490-
);
485+
return new InstanceBasedConverterDescriptor( NumericBooleanConverter.INSTANCE, classmateContext );
491486
}
492487
else if ( jdbcType.isString() ) {
493488
// here we pick 'T' / 'F' storage, though 'Y' / 'N' is equally valid - its 50/50
494-
return new InstanceBasedConverterDescriptor(
495-
TrueFalseConverter.INSTANCE,
496-
getBuildingContext().getBootstrapContext().getClassmateContext()
497-
);
489+
return new InstanceBasedConverterDescriptor( TrueFalseConverter.INSTANCE, classmateContext );
498490
}
499491
else {
500492
// should indicate BIT or BOOLEAN == no conversion needed
501493
// - we still create the converter to properly set up JDBC type, etc
502-
return new InstanceBasedConverterDescriptor(
503-
PassThruSoftDeleteConverter.INSTANCE,
504-
getBuildingContext().getBootstrapContext().getClassmateContext()
505-
);
494+
return new InstanceBasedConverterDescriptor( PassThruSoftDeleteConverter.INSTANCE, classmateContext );
506495
}
507496
}
508497
else {

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,10 @@ public void addFetch(Fetch fetch) {
6868
}
6969

7070
@Override
71-
public boolean equals(Object o) {
72-
if ( this == o ) {
73-
return true;
74-
}
75-
if ( o == null || getClass() != o.getClass() ) {
76-
return false;
77-
}
78-
79-
FetchProfile that = ( FetchProfile ) o;
80-
81-
return name.equals( that.name );
71+
public boolean equals(Object that) {
72+
return this == that
73+
|| that instanceof FetchProfile profile
74+
&& name.equals( profile.name );
8275
}
8376

8477
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public String toString() {
9494
}
9595

9696
@Override
97-
public boolean equals(Object obj) {
98-
return obj instanceof Formula
99-
&& ( (Formula) obj ).formula.equals( formula );
97+
public boolean equals(Object that) {
98+
return that instanceof Formula other
99+
&& formula.equals( other.formula );
100100
}
101101

102102
@Override

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,15 @@ public MetadataImplementor getMetadata() {
149149
return metadata;
150150
}
151151

152+
InFlightMetadataCollector getMetadataCollector() {
153+
return getBuildingContext().getMetadataCollector();
154+
}
155+
152156
@Override
153157
public ServiceRegistry getServiceRegistry() {
154158
return getMetadata().getMetadataBuildingOptions().getServiceRegistry();
155159
}
156160

157-
158161
public TypeConfiguration getTypeConfiguration() {
159162
return getBuildingContext().getBootstrapContext().getTypeConfiguration();
160163
}
@@ -234,8 +237,8 @@ public void sortColumns(int[] originalOrder) {
234237
for ( int i = 0; i < originalOrder.length; i++ ) {
235238
final int originalIndex = originalOrder[i];
236239
final Selectable selectable = originalColumns[i];
237-
if ( selectable instanceof Column ) {
238-
( (Column) selectable ).setTypeIndex( originalIndex );
240+
if ( selectable instanceof Column column ) {
241+
column.setTypeIndex( originalIndex );
239242
}
240243
columns.set( originalIndex, selectable );
241244
insertability.set( originalIndex, originalInsertability[i] );
@@ -422,9 +425,8 @@ public void setColumnToIdentity() {
422425
if ( getColumnSpan() != 1 ) {
423426
throw new MappingException( "Identity generation requires exactly one column" );
424427
}
425-
final Selectable column = getColumn(0);
426-
if ( column instanceof Column ) {
427-
( (Column) column).setIdentity( true );
428+
else if ( getColumn(0) instanceof Column column ) {
429+
column.setIdentity( true );
428430
}
429431
else {
430432
throw new MappingException( "Identity generation requires a column" );
@@ -513,10 +515,12 @@ public boolean isNullable() {
513515
// considered nullable
514516
return true;
515517
}
516-
else if ( !( (Column) selectable ).isNullable() ) {
517-
// if there is a single non-nullable column, the Value
518-
// overall is considered non-nullable.
519-
return false;
518+
else if ( selectable instanceof Column column ) {
519+
if ( !column.isNullable() ) {
520+
// if there is a single non-nullable column, the Value
521+
// overall is considered non-nullable.
522+
return false;
523+
}
520524
}
521525
}
522526
// nullable by default
@@ -755,7 +759,7 @@ public void setTypeParameters(Properties parameterMap) {
755759

756760
public void setTypeParameters(Map<String, ?> parameters) {
757761
if ( parameters != null ) {
758-
Properties properties = new Properties();
762+
final Properties properties = new Properties();
759763
properties.putAll( parameters );
760764
setTypeParameters( properties );
761765
}
@@ -891,10 +895,9 @@ protected void createParameterImpl() {
891895
// todo : not sure this works for handling @MapKeyEnumerated
892896
final Annotation[] annotations = getAnnotations( attributeMember );
893897

894-
final ClassLoaderService classLoaderService = getMetadata()
895-
.getMetadataBuildingOptions()
896-
.getServiceRegistry()
897-
.requireService( ClassLoaderService.class );
898+
final ClassLoaderService classLoaderService =
899+
getMetadata().getMetadataBuildingOptions().getServiceRegistry()
900+
.requireService( ClassLoaderService.class );
898901
typeParameters.put(
899902
DynamicParameterizedType.PARAMETER_TYPE,
900903
new ParameterTypeImpl(
@@ -906,7 +909,7 @@ protected void createParameterImpl() {
906909
table.getCatalog(),
907910
table.getSchema(),
908911
table.getName(),
909-
parseBoolean(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)),
912+
parseBoolean( typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY) ),
910913
columnNames,
911914
columnLengths
912915
)
@@ -944,19 +947,18 @@ public DynamicParameterizedType.ParameterType makeParameterImpl() {
944947
// todo : not sure this works for handling @MapKeyEnumerated
945948
final Annotation[] annotations = getAnnotations( attributeMember );
946949

947-
final ClassLoaderService classLoaderService = getMetadata()
948-
.getMetadataBuildingOptions()
949-
.getServiceRegistry()
950-
.requireService( ClassLoaderService.class );
950+
final ClassLoaderService classLoaderService =
951+
getMetadata().getMetadataBuildingOptions().getServiceRegistry()
952+
.requireService( ClassLoaderService.class );
951953

952954
return new ParameterTypeImpl(
953-
classLoaderService.classForTypeName(typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)),
955+
classLoaderService.classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ),
954956
attributeMember != null ? attributeMember.getType() : null,
955957
annotations,
956958
table.getCatalog(),
957959
table.getSchema(),
958960
table.getName(),
959-
parseBoolean(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)),
961+
parseBoolean( typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY) ),
960962
columnNames,
961963
columnLengths
962964
);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ public int hashCode() {
416416

417417
@Override
418418
public boolean equals(Object object) {
419-
return object instanceof Table && equals((Table) object);
419+
return object instanceof Table table
420+
&& equals( table );
420421
}
421422

422423
public boolean equals(Table table) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public void setPropertyName(String propertyName) {
9090
@Override
9191
public void setTypeUsingReflection(String className, String propertyName) throws MappingException {
9292
if ( referencedEntityName == null ) {
93-
final ClassLoaderService cls = getMetadata().getMetadataBuildingOptions()
94-
.getServiceRegistry()
95-
.requireService( ClassLoaderService.class );
93+
final ClassLoaderService cls =
94+
getMetadata().getMetadataBuildingOptions().getServiceRegistry()
95+
.requireService( ClassLoaderService.class );
9696
referencedEntityName = ReflectHelper.reflectedPropertyClass( className, propertyName, cls ).getName();
9797
}
9898
}

0 commit comments

Comments
 (0)