Skip to content

Commit 044ad2c

Browse files
committed
fix some typecasts
1 parent abf5543 commit 044ad2c

File tree

24 files changed

+174
-222
lines changed

24 files changed

+174
-222
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ else if ( value instanceof Component component ) {
402402
component.setTypeName( typeName );
403403
}
404404
}
405-
else if ( value instanceof SimpleValue ) {
406-
( (SimpleValue) value ).setTypeName( typeName );
405+
else if ( value instanceof SimpleValue simpleValue ) {
406+
simpleValue.setTypeName( typeName );
407407
}
408408
}
409409

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,8 @@ private static void handleGenerationTiming(
24192419
GenerationTiming timing) {
24202420
if ( timing != null ) {
24212421
if ( (timing == GenerationTiming.INSERT || timing == GenerationTiming.UPDATE)
2422-
&& property.getValue() instanceof SimpleValue
2423-
&& ((SimpleValue) property.getValue()).isVersion() ) {
2422+
&& property.getValue() instanceof SimpleValue simpleValue
2423+
&& simpleValue.isVersion() ) {
24242424
// this is enforced by DTD, but just make sure
24252425
throw new MappingException(
24262426
"'generated' attribute cannot be 'insert' or 'update' for version/timestamp property",
@@ -2685,8 +2685,8 @@ private static void bindSimpleValueType(
26852685

26862686
if ( CollectionHelper.isNotEmpty( typeResolution.parameters ) ) {
26872687
simpleValue.setTypeParameters( typeResolution.parameters );
2688-
if ( simpleValue instanceof BasicValue ) {
2689-
( (BasicValue) simpleValue ).setExplicitTypeParams( typeResolution.parameters );
2688+
if ( simpleValue instanceof BasicValue basicValue ) {
2689+
basicValue.setExplicitTypeParams( typeResolution.parameters );
26902690
}
26912691
}
26922692

hibernate-core/src/main/java/org/hibernate/dialect/function/InverseDistributionFunction.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,12 @@ protected MappingModelExpressible<?> getMappingModelExpressible(
185185
.getSortExpression()
186186
.accept( walker );
187187
final JdbcMappingContainer expressionType = expression.getExpressionType();
188-
if ( expressionType instanceof BasicValuedMapping ) {
189-
return (BasicValuedMapping) expressionType;
188+
if ( expressionType instanceof BasicValuedMapping basicValuedMapping ) {
189+
return basicValuedMapping;
190190
}
191191
try {
192-
return walker.getCreationContext()
193-
.getSessionFactory()
194-
.getRuntimeMetamodels()
195-
.getMappingMetamodel()
196-
.resolveMappingExpressible(
197-
getNodeType(),
198-
walker.getFromClauseAccess()::getTableGroup
199-
);
192+
return walker.getCreationContext().getSessionFactory().getMappingMetamodel()
193+
.resolveMappingExpressible( getNodeType(), walker.getFromClauseAccess()::getTableGroup );
200194
}
201195
catch (Exception e) {
202196
return null; // this works at least approximately

hibernate-core/src/main/java/org/hibernate/dialect/function/array/ArrayViaArgumentReturnTypeResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public ReturnableType<?> resolveFunctionReturnType(
4848
if ( inferredType instanceof ReturnableType<?> ) {
4949
return (ReturnableType<?>) inferredType;
5050
}
51-
else if ( inferredType instanceof BasicValuedMapping ) {
52-
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
51+
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
52+
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
5353
}
5454
}
5555
if ( impliedType != null ) {

hibernate-core/src/main/java/org/hibernate/dialect/function/array/ArrayViaElementArgumentReturnTypeResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public ReturnableType<?> resolveFunctionReturnType(
5252
if ( inferredType instanceof ReturnableType<?> ) {
5353
return (ReturnableType<?>) inferredType;
5454
}
55-
else if ( inferredType instanceof BasicValuedMapping ) {
56-
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
55+
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
56+
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
5757
}
5858
}
5959
if ( impliedType != null ) {

hibernate-core/src/main/java/org/hibernate/dialect/function/array/ElementViaArrayArgumentReturnTypeResolver.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.hibernate.metamodel.mapping.BasicValuedMapping;
1111
import org.hibernate.metamodel.mapping.MappingModelExpressible;
12-
import org.hibernate.metamodel.model.domain.DomainType;
1312
import org.hibernate.metamodel.model.domain.ReturnableType;
1413
import org.hibernate.query.sqm.SqmExpressible;
1514
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
@@ -41,26 +40,23 @@ public ReturnableType<?> resolveFunctionReturnType(
4140
@Nullable SqmToSqlAstConverter converter,
4241
List<? extends SqmTypedNode<?>> arguments,
4342
TypeConfiguration typeConfiguration) {
44-
final MappingModelExpressible<?> inferredType = converter == null
45-
? null
46-
: converter.resolveFunctionImpliedReturnType();
43+
final MappingModelExpressible<?> inferredType =
44+
converter == null ? null : converter.resolveFunctionImpliedReturnType();
4745
if ( inferredType != null ) {
48-
if ( inferredType instanceof ReturnableType<?> ) {
49-
return (ReturnableType<?>) inferredType;
46+
if ( inferredType instanceof ReturnableType<?> returnableType ) {
47+
return returnableType;
5048
}
51-
else if ( inferredType instanceof BasicValuedMapping ) {
52-
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
49+
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
50+
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
5351
}
5452
}
5553
if ( impliedType != null ) {
5654
return impliedType;
5755
}
5856
final SqmExpressible<?> expressible = arguments.get( arrayIndex ).getExpressible();
59-
final DomainType<?> type;
60-
if ( expressible != null && ( type = expressible.getSqmType() ) instanceof BasicPluralType<?, ?> ) {
61-
return ( (BasicPluralType<?, ?>) type ).getElementType();
62-
}
63-
return null;
57+
return expressible != null && expressible.getSqmType() instanceof BasicPluralType<?, ?> type
58+
? type.getElementType()
59+
: null;
6460
}
6561

6662
@Override

hibernate-core/src/main/java/org/hibernate/dialect/function/array/JsonArrayViaElementArgumentReturnTypeResolver.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.List;
99
import java.util.function.Supplier;
1010

11-
import org.hibernate.dialect.Dialect;
1211
import org.hibernate.metamodel.mapping.BasicValuedMapping;
1312
import org.hibernate.metamodel.mapping.MappingModelExpressible;
1413
import org.hibernate.metamodel.model.domain.DomainType;
@@ -52,11 +51,11 @@ public ReturnableType<?> resolveFunctionReturnType(
5251
}
5352
final MappingModelExpressible<?> inferredType = converter.resolveFunctionImpliedReturnType();
5453
if ( inferredType != null ) {
55-
if ( inferredType instanceof ReturnableType<?> ) {
56-
return (ReturnableType<?>) inferredType;
54+
if ( inferredType instanceof ReturnableType<?> returnableType ) {
55+
return returnableType;
5756
}
58-
else if ( inferredType instanceof BasicValuedMapping ) {
59-
return (ReturnableType<?>) ( (BasicValuedMapping) inferredType ).getJdbcMapping();
57+
else if ( inferredType instanceof BasicValuedMapping basicValuedMapping ) {
58+
return (ReturnableType<?>) basicValuedMapping.getJdbcMapping();
6059
}
6160
}
6261
}
@@ -79,25 +78,25 @@ public BasicValuedMapping resolveFunctionReturnType(
7978
return null;
8079
}
8180

82-
@SuppressWarnings("unchecked")
83-
public static BasicType<?> resolveJsonArrayType(DomainType<?> elementType, TypeConfiguration typeConfiguration) {
84-
@SuppressWarnings("unchecked") final BasicPluralJavaType<Object> arrayJavaType = (BasicPluralJavaType<Object>) typeConfiguration.getJavaTypeRegistry()
85-
.getDescriptor(
86-
Array.newInstance( elementType.getBindableJavaType(), 0 ).getClass()
87-
);
88-
final Dialect dialect = typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect();
89-
final JdbcTypeIndicators jdbcTypeIndicators = new DelegatingJdbcTypeIndicators( typeConfiguration.getCurrentBaseSqlTypeIndicators() ) {
90-
@Override
91-
public Integer getExplicitJdbcTypeCode() {
92-
return SqlTypes.JSON;
93-
}
94-
};
81+
public static <T> BasicType<?> resolveJsonArrayType(DomainType<T> elementType, TypeConfiguration typeConfiguration) {
82+
final Class<?> arrayClass = Array.newInstance( elementType.getBindableJavaType(), 0 ).getClass();
83+
@SuppressWarnings("unchecked")
84+
final BasicPluralJavaType<T> arrayJavaType =
85+
(BasicPluralJavaType<T>)
86+
typeConfiguration.getJavaTypeRegistry()
87+
.getDescriptor( arrayClass );
88+
final JdbcTypeIndicators currentBaseSqlTypeIndicators = typeConfiguration.getCurrentBaseSqlTypeIndicators();
9589
return arrayJavaType.resolveType(
9690
typeConfiguration,
97-
dialect,
98-
(BasicType<Object>) elementType,
91+
currentBaseSqlTypeIndicators.getDialect(),
92+
(BasicType<T>) elementType,
9993
null,
100-
jdbcTypeIndicators
94+
new DelegatingJdbcTypeIndicators( currentBaseSqlTypeIndicators ) {
95+
@Override
96+
public Integer getExplicitJdbcTypeCode() {
97+
return SqlTypes.JSON;
98+
}
99+
}
101100
);
102101
}
103102
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public boolean resolve(MetadataBuildingContext buildingContext) {
9191

9292
@Override
9393
public BasicValue.Resolution<?> resolve() {
94-
if ( wrappedValue instanceof BasicValue ) {
95-
return ( (BasicValue) wrappedValue ).resolve();
94+
if ( wrappedValue instanceof BasicValue basicValue ) {
95+
return basicValue.resolve();
9696
}
9797
// not sure it is ever possible
9898
throw new UnsupportedOperationException("Trying to resolve the wrapped value but it is non a BasicValue");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ public boolean hasPartitionedSelectionMapping() {
920920
}
921921
for ( Property property : getProperties() ) {
922922
final Value value = property.getValue();
923-
if ( value instanceof BasicValue && ( (BasicValue) value ).isPartitionKey() ) {
923+
if ( value instanceof BasicValue basicValue && basicValue.isPartitionKey() ) {
924924
return true;
925925
}
926926
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public boolean isValid(Mapping mapping) throws MappingException {
286286

287287
public boolean isValid(MappingContext mappingContext) throws MappingException {
288288
final Value value = getValue();
289-
if ( value instanceof BasicValue && ( (BasicValue) value ).isDisallowedWrapperArray() ) {
289+
if ( value instanceof BasicValue basicValue && basicValue.isDisallowedWrapperArray() ) {
290290
throw new MappingException(
291291
"The property " + persistentClass.getEntityName() + "#" + name +
292292
" uses a wrapper type Byte[]/Character[] which indicates an issue in your domain model. " +

0 commit comments

Comments
 (0)