diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AbstractConverterDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AbstractConverterDescriptor.java index 5f0ee13f7a..ca8be4f0c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AbstractConverterDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AbstractConverterDescriptor.java @@ -101,9 +101,8 @@ public abstract class AbstractConverterDescriptor implements ConverterDescriptor } @Override - @SuppressWarnings({ "unchecked", "rawtypes" }) - public JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context) { - final JavaType converterJtd = context + public JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context) { + final JavaType converterJtd = context .getJavaTypeRegistry() .getDescriptor( getAttributeConverterClass() ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/convert/spi/ConverterDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/model/convert/spi/ConverterDescriptor.java index ce92598779..2cb3205656 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/convert/spi/ConverterDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/convert/spi/ConverterDescriptor.java @@ -45,5 +45,5 @@ public interface ConverterDescriptor { /** * Factory for the runtime representation of the converter */ - JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context); + JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolution.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolution.java index dcc4cf2ed2..07d15185a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolution.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolution.java @@ -17,26 +17,26 @@ import org.hibernate.type.descriptor.jdbc.JdbcType; /** * @author Steve Ebersole */ -public class InferredBasicValueResolution implements BasicValue.Resolution { - private JavaType domainJtd; - private JavaType relationalJtd; - private JdbcType jdbcType; +public class InferredBasicValueResolution implements BasicValue.Resolution { + private final JavaType domainJtd; + private final JavaType relationalJtd; + private final JdbcType jdbcType; - private MutabilityPlan mutabilityPlan; + private final MutabilityPlan mutabilityPlan; - private JdbcMapping jdbcMapping; - private BasicValueConverter valueConverter; + private final JdbcMapping jdbcMapping; + private final BasicValueConverter valueConverter; private final BasicType legacyType; public InferredBasicValueResolution( JdbcMapping jdbcMapping, JavaType domainJtd, - JavaType relationalJtd, + JavaType relationalJtd, JdbcType jdbcType, - BasicValueConverter valueConverter, + BasicValueConverter valueConverter, BasicType legacyType, - MutabilityPlan mutabilityPlan) { + MutabilityPlan mutabilityPlan) { this.jdbcMapping = jdbcMapping; this.legacyType = legacyType; this.domainJtd = domainJtd; @@ -52,7 +52,7 @@ public class InferredBasicValueResolution implements BasicValue.Resolution } @Override - public BasicType getLegacyResolvedBasicType() { + public BasicType getLegacyResolvedBasicType() { return legacyType; } @@ -72,7 +72,7 @@ public class InferredBasicValueResolution implements BasicValue.Resolution } @Override - public BasicValueConverter getValueConverter() { + public BasicValueConverter getValueConverter() { return valueConverter; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java index 415e2b8447..e006d48018 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java @@ -18,7 +18,6 @@ import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Column; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Table; -import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.model.convert.internal.NamedEnumValueConverter; import org.hibernate.metamodel.model.convert.internal.OrdinalEnumValueConverter; import org.hibernate.type.AdjustableBasicType; @@ -45,12 +44,11 @@ public class InferredBasicValueResolver { /** * Create an inference-based resolution */ - @SuppressWarnings({"unchecked", "rawtypes"}) - public static BasicValue.Resolution from( + public static BasicValue.Resolution from( Function explicitJavaTypeAccess, Function explicitSqlTypeAccess, Type resolvedJavaType, - Supplier reflectedJtdResolver, + Supplier> reflectedJtdResolver, JdbcTypeIndicators stdIndicators, Table table, Selectable selectable, @@ -58,17 +56,21 @@ public class InferredBasicValueResolver { String propertyName, TypeConfiguration typeConfiguration) { - final BasicJavaType explicitJavaType = explicitJavaTypeAccess != null ? explicitJavaTypeAccess.apply( typeConfiguration ) : null; - final JdbcType explicitJdbcType = explicitSqlTypeAccess != null ? explicitSqlTypeAccess.apply( typeConfiguration ) : null; + final BasicJavaType explicitJavaType = explicitJavaTypeAccess != null + ? explicitJavaTypeAccess.apply( typeConfiguration ) + : null; + final JdbcType explicitJdbcType = explicitSqlTypeAccess + != null ? explicitSqlTypeAccess.apply( typeConfiguration ) + : null; - final BasicJavaType reflectedJtd = (BasicJavaType) reflectedJtdResolver.get(); + final JavaType reflectedJtd = reflectedJtdResolver.get(); // NOTE : the distinction that is made below wrt `explicitJavaType` and `reflectedJtd` is // needed temporarily to trigger "legacy resolution" versus "ORM6 resolution. Yes, it // makes the code a little more complicated but the benefit is well worth it - saving memory - final BasicType jdbcMapping; - final BasicType legacyType; + final BasicType jdbcMapping; + final BasicType legacyType; if ( explicitJavaType != null ) { // we have an explicit JavaType @@ -99,7 +101,7 @@ public class InferredBasicValueResolver { } else if ( explicitJavaType instanceof TemporalJavaType ) { return fromTemporal( - (TemporalJavaType) reflectedJtd, + (TemporalJavaType) reflectedJtd, explicitJavaType, null, resolvedJavaType, @@ -107,8 +109,9 @@ public class InferredBasicValueResolver { typeConfiguration ); } - else if ( explicitJavaType instanceof SerializableJavaType || explicitJavaType.getJavaType() instanceof Serializable ) { - legacyType = new SerializableType<>( explicitJavaType ); + else if ( explicitJavaType instanceof SerializableJavaType + || explicitJavaType.getJavaType() instanceof Serializable ) { + legacyType = new SerializableType( explicitJavaType ); jdbcMapping = legacyType; } else { @@ -154,7 +157,7 @@ public class InferredBasicValueResolver { } else if ( reflectedJtd instanceof TemporalJavaType ) { return fromTemporal( - (TemporalJavaType) reflectedJtd, + (TemporalJavaType) reflectedJtd, null, null, resolvedJavaType, @@ -165,7 +168,8 @@ public class InferredBasicValueResolver { else { // see if there is a registered BasicType for this JavaType and, if so, use it. // this mimics the legacy handling - final BasicType registeredType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( reflectedJtd.getJavaType() ); + final BasicType registeredType = typeConfiguration.getBasicTypeRegistry() + .getRegisteredType( reflectedJtd.getJavaType() ); if ( registeredType != null ) { // so here is the legacy resolution @@ -183,8 +187,9 @@ public class InferredBasicValueResolver { ); legacyType = jdbcMapping; } - else if ( reflectedJtd instanceof SerializableJavaType || Serializable.class.isAssignableFrom( reflectedJtd.getJavaTypeClass() ) ) { - legacyType = new SerializableType<>( reflectedJtd ); + else if ( reflectedJtd instanceof SerializableJavaType + || Serializable.class.isAssignableFrom( reflectedJtd.getJavaTypeClass() ) ) { + legacyType = new SerializableType( reflectedJtd ); jdbcMapping = legacyType; } else { @@ -217,17 +222,20 @@ public class InferredBasicValueResolver { } } } - final BasicJavaType recommendedJtd = explicitJdbcType.getJdbcRecommendedJavaTypeMapping( + + final BasicJavaType recommendedJtd = explicitJdbcType.getJdbcRecommendedJavaTypeMapping( length, scale, typeConfiguration ); - final BasicType resolved = typeConfiguration.getBasicTypeRegistry().resolve( - recommendedJtd, - explicitJdbcType - ); - jdbcMapping = resolveSqlTypeIndicators( stdIndicators, resolved, recommendedJtd ); + jdbcMapping = resolveSqlTypeIndicators( + stdIndicators, + typeConfiguration.getBasicTypeRegistry().resolve( + recommendedJtd, + explicitJdbcType + ), + recommendedJtd ); legacyType = jdbcMapping; } else { @@ -252,7 +260,7 @@ public class InferredBasicValueResolver { ); } - return new InferredBasicValueResolution( + return new InferredBasicValueResolution<>( jdbcMapping, jdbcMapping.getJavaTypeDescriptor(), jdbcMapping.getJavaTypeDescriptor(), @@ -263,14 +271,13 @@ public class InferredBasicValueResolver { ); } - @SuppressWarnings("rawtypes") - public static BasicType resolveSqlTypeIndicators( + public static BasicType resolveSqlTypeIndicators( JdbcTypeIndicators stdIndicators, - BasicType resolved, - JavaType domainJtd) { + BasicType resolved, + JavaType domainJtd) { if ( resolved instanceof AdjustableBasicType ) { - final AdjustableBasicType indicatorCapable = (AdjustableBasicType) resolved; - final BasicType indicatedType = indicatorCapable.resolveIndicatedType( stdIndicators, domainJtd ); + final AdjustableBasicType indicatorCapable = (AdjustableBasicType) resolved; + final BasicType indicatedType = indicatorCapable.resolveIndicatedType( stdIndicators, domainJtd ); return indicatedType != null ? indicatedType : resolved; } else { @@ -278,10 +285,9 @@ public class InferredBasicValueResolver { } } - @SuppressWarnings("rawtypes") - public static > InferredBasicValueResolution fromEnum( + public static > InferredBasicValueResolution fromEnum( EnumJavaType enumJavaType, - BasicJavaType explicitJavaType, + BasicJavaType explicitJavaType, JdbcType explicitJdbcType, JdbcTypeIndicators stdIndicators, TypeConfiguration typeConfiguration) { @@ -291,101 +297,21 @@ public class InferredBasicValueResolver { switch ( enumStyle ) { case STRING: { - final JavaType relationalJtd; - if ( explicitJavaType != null ) { - if ( ! String.class.isAssignableFrom( explicitJavaType.getJavaTypeClass() ) ) { - throw new MappingException( - "Explicit JavaType [" + explicitJavaType + - "] applied to enumerated value with EnumType#STRING" + - " should handle `java.lang.String` as its relational type descriptor" - ); - } - relationalJtd = explicitJavaType; - } - else { - final boolean useCharacter = stdIndicators.getColumnLength() == 1; - final Class relationalJavaType = useCharacter ? Character.class : String.class; - relationalJtd = typeConfiguration.getJavaTypeRegistry().getDescriptor( relationalJavaType ); - } - - final JdbcType jdbcType = explicitJdbcType != null ? explicitJdbcType : relationalJtd.getRecommendedJdbcType( stdIndicators ); - - //noinspection unchecked - final NamedEnumValueConverter valueConverter = new NamedEnumValueConverter( + return stringEnumValueResolution( enumJavaType, - jdbcType, - relationalJtd - ); - - final org.hibernate.type.EnumType legacyEnumType = new org.hibernate.type.EnumType<>( - enumJavaType.getJavaTypeClass(), - valueConverter, + explicitJavaType, + explicitJdbcType, + stdIndicators, typeConfiguration ); - - final CustomType legacyEnumTypeWrapper = new CustomType<>( legacyEnumType, typeConfiguration ); - - final JdbcMapping jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( relationalJtd, jdbcType ); - - //noinspection unchecked - return new InferredBasicValueResolution( - jdbcMapping, - enumJavaType, - relationalJtd, - jdbcType, - valueConverter, - legacyEnumTypeWrapper, - ImmutableMutabilityPlan.INSTANCE - ); } case ORDINAL: { - final JavaType relationalJtd; - if ( explicitJavaType != null ) { - if ( ! Integer.class.isAssignableFrom( explicitJavaType.getJavaTypeClass() ) ) { - throw new MappingException( - "Explicit JavaType [" + explicitJavaType + - "] applied to enumerated value with EnumType#ORDINAL" + - " should handle `java.lang.Integer` as its relational type descriptor" - ); - } - //noinspection unchecked - relationalJtd = explicitJavaType; - } - else { - relationalJtd = typeConfiguration.getJavaTypeRegistry().getDescriptor( Integer.class ); - } - - final JdbcType jdbcType = explicitJdbcType != null - ? explicitJdbcType - : typeConfiguration.getJdbcTypeRegistry().getDescriptor( SqlTypes.TINYINT ); - - //noinspection unchecked - final OrdinalEnumValueConverter valueConverter = new OrdinalEnumValueConverter( + return ordinalEnumValueResolution( enumJavaType, - jdbcType, - relationalJtd - ); - - final org.hibernate.type.EnumType legacyEnumType = new org.hibernate.type.EnumType<>( - enumJavaType.getJavaTypeClass(), - valueConverter, + explicitJavaType, + explicitJdbcType, typeConfiguration ); - - final CustomType legacyEnumTypeWrapper = new CustomType<>( legacyEnumType, typeConfiguration ); - - final JdbcMapping jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( relationalJtd, jdbcType ); - - //noinspection unchecked - return new InferredBasicValueResolution( - jdbcMapping, - enumJavaType, - relationalJtd, - jdbcType, - valueConverter, - legacyEnumTypeWrapper, - ImmutableMutabilityPlan.INSTANCE - ); } default: { throw new MappingException( "Unknown enumeration-style (JPA EnumType) : " + enumStyle ); @@ -393,10 +319,110 @@ public class InferredBasicValueResolver { } } - @SuppressWarnings({"rawtypes", "unchecked"}) - public static InferredBasicValueResolution fromTemporal( - TemporalJavaType reflectedJtd, - BasicJavaType explicitJavaType, + private static > InferredBasicValueResolution ordinalEnumValueResolution( + EnumJavaType enumJavaType, + BasicJavaType explicitJavaType, + JdbcType explicitJdbcType, + TypeConfiguration typeConfiguration) { + final JavaType relationalJtd; + if ( explicitJavaType != null ) { + if ( ! Integer.class.isAssignableFrom( explicitJavaType.getJavaTypeClass() ) ) { + throw new MappingException( + "Explicit JavaType [" + explicitJavaType + + "] applied to enumerated value with EnumType#ORDINAL" + + " should handle `java.lang.Integer` as its relational type descriptor" + ); + } + //noinspection unchecked + relationalJtd = (BasicJavaType) explicitJavaType; + } + else { + relationalJtd = typeConfiguration.getJavaTypeRegistry().getDescriptor( Integer.class ); + } + + final JdbcType jdbcType = explicitJdbcType != null + ? explicitJdbcType + : typeConfiguration.getJdbcTypeRegistry().getDescriptor( SqlTypes.TINYINT ); + + final OrdinalEnumValueConverter valueConverter = new OrdinalEnumValueConverter<>( + enumJavaType, + jdbcType, + relationalJtd + ); + + return new InferredBasicValueResolution<>( + typeConfiguration.getBasicTypeRegistry().resolve(relationalJtd, jdbcType), + enumJavaType, + relationalJtd, + jdbcType, + valueConverter, + new CustomType<>( + new org.hibernate.type.EnumType<>( + enumJavaType.getJavaTypeClass(), + valueConverter, + typeConfiguration + ), + typeConfiguration + ), + ImmutableMutabilityPlan.instance() + ); + } + + private static > InferredBasicValueResolution stringEnumValueResolution( + EnumJavaType enumJavaType, + BasicJavaType explicitJavaType, + JdbcType explicitJdbcType, + JdbcTypeIndicators stdIndicators, + TypeConfiguration typeConfiguration) { + final JavaType relationalJtd; + if ( explicitJavaType != null ) { + if ( ! String.class.isAssignableFrom( explicitJavaType.getJavaTypeClass() ) ) { + throw new MappingException( + "Explicit JavaType [" + explicitJavaType + + "] applied to enumerated value with EnumType#STRING" + + " should handle `java.lang.String` as its relational type descriptor" + ); + } + //noinspection unchecked + relationalJtd = (BasicJavaType) explicitJavaType; + } + else { + final boolean useCharacter = stdIndicators.getColumnLength() == 1; + relationalJtd = typeConfiguration.getJavaTypeRegistry() + .getDescriptor( useCharacter ? Character.class : String.class ); + } + + final JdbcType jdbcType = explicitJdbcType != null + ? explicitJdbcType + : relationalJtd.getRecommendedJdbcType(stdIndicators); + + final NamedEnumValueConverter valueConverter = new NamedEnumValueConverter<>( + enumJavaType, + jdbcType, + relationalJtd + ); + + return new InferredBasicValueResolution<>( + typeConfiguration.getBasicTypeRegistry().resolve(relationalJtd, jdbcType), + enumJavaType, + relationalJtd, + jdbcType, + valueConverter, + new CustomType<>( + new org.hibernate.type.EnumType<>( + enumJavaType.getJavaTypeClass(), + valueConverter, + typeConfiguration + ), + typeConfiguration + ), + ImmutableMutabilityPlan.instance() + ); + } + + public static InferredBasicValueResolution fromTemporal( + TemporalJavaType reflectedJtd, + BasicJavaType explicitJavaType, JdbcType explicitJdbcType, Type resolvedJavaType, JdbcTypeIndicators stdIndicators, @@ -407,14 +433,15 @@ public class InferredBasicValueResolver { // Case #1 - explicit JavaType if ( explicitJavaType != null ) { - if ( !TemporalJavaType.class.isInstance( explicitJavaType ) ) { + if ( !(explicitJavaType instanceof TemporalJavaType) ) { throw new MappingException( "Explicit JavaType [" + explicitJavaType + "] defined for temporal value must implement TemporalJavaType" ); } - final TemporalJavaType explicitTemporalJtd = (TemporalJavaType) explicitJavaType; + @SuppressWarnings("unchecked") + final TemporalJavaType explicitTemporalJtd = (TemporalJavaType) explicitJavaType; if ( requestedTemporalPrecision != null && explicitTemporalJtd.getPrecision() != requestedTemporalPrecision ) { throw new MappingException( @@ -424,18 +451,20 @@ public class InferredBasicValueResolver { ); } - final JdbcType jdbcType = explicitJdbcType != null ? explicitJdbcType : explicitTemporalJtd.getRecommendedJdbcType( stdIndicators ); + final JdbcType jdbcType = explicitJdbcType != null + ? explicitJdbcType + : explicitTemporalJtd.getRecommendedJdbcType( stdIndicators ); - final BasicType jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( explicitTemporalJtd, jdbcType ); + final BasicType jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( explicitTemporalJtd, jdbcType ); - return new InferredBasicValueResolution( + return new InferredBasicValueResolution<>( jdbcMapping, explicitTemporalJtd, explicitTemporalJtd, jdbcType, null, jdbcMapping, - explicitJavaType.getMutabilityPlan() + explicitTemporalJtd.getMutabilityPlan() ); } @@ -446,7 +475,7 @@ public class InferredBasicValueResolver { // due to the new annotations being used if ( explicitJdbcType != null ) { - final TemporalJavaType jtd; + final TemporalJavaType jtd; if ( requestedTemporalPrecision != null ) { jtd = reflectedJtd.resolveTypeForPrecision( @@ -458,9 +487,9 @@ public class InferredBasicValueResolver { jtd = reflectedJtd; } - final BasicType jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( jtd, explicitJdbcType ); + final BasicType jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( jtd, explicitJdbcType ); - return new InferredBasicValueResolution( + return new InferredBasicValueResolution<>( jdbcMapping, jtd, jtd, @@ -476,7 +505,7 @@ public class InferredBasicValueResolver { // // - for the moment continue to use the legacy resolution to registered // BasicType - final BasicType basicType; + final BasicType basicType; if ( requestedTemporalPrecision != null && requestedTemporalPrecision != reflectedJtd.getPrecision() ) { basicType = typeConfiguration.getBasicTypeRegistry().resolve( reflectedJtd.resolveTypeForPrecision( requestedTemporalPrecision, typeConfiguration ), @@ -490,7 +519,7 @@ public class InferredBasicValueResolver { ); } - return new InferredBasicValueResolution( + return new InferredBasicValueResolution<>( basicType, basicType.getJavaTypeDescriptor(), basicType.getJavaTypeDescriptor(), diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java index edb41c48f6..a33b54a75e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java @@ -32,10 +32,9 @@ import org.hibernate.type.spi.TypeConfiguration; /** * @author Steve Ebersole */ -@SuppressWarnings("rawtypes") public class NamedConverterResolution implements BasicValue.Resolution { - public static NamedConverterResolution from( + public static NamedConverterResolution from( ConverterDescriptor converterDescriptor, Function explicitJtdAccess, Function explicitStdAccess, @@ -47,13 +46,13 @@ public class NamedConverterResolution implements BasicValue.Resolution { explicitJtdAccess, explicitStdAccess, explicitMutabilityPlanAccess, - converterDescriptor.createJpaAttributeConverter( converterCreationContext ), + converter( converterCreationContext, converterDescriptor ), sqlTypeIndicators, context ); } - public static NamedConverterResolution from( + public static NamedConverterResolution from( String name, Function explicitJtdAccess, Function explicitStdAccess, @@ -64,12 +63,10 @@ public class NamedConverterResolution implements BasicValue.Resolution { assert name.startsWith( ConverterDescriptor.TYPE_NAME_PREFIX ); final String converterClassName = name.substring( ConverterDescriptor.TYPE_NAME_PREFIX.length() ); - final StandardServiceRegistry serviceRegistry = context.getBootstrapContext().getServiceRegistry(); - final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); - - final Class converterClass = classLoaderService.classForName( converterClassName ); final ClassBasedConverterDescriptor converterDescriptor = new ClassBasedConverterDescriptor( - converterClass, + context.getBootstrapContext().getServiceRegistry() + .getService( ClassLoaderService.class ) + .classForName( converterClassName ), context.getBootstrapContext().getClassmateContext() ); @@ -77,25 +74,33 @@ public class NamedConverterResolution implements BasicValue.Resolution { explicitJtdAccess, explicitStdAccess, explicitMutabilityPlanAccess, - converterDescriptor.createJpaAttributeConverter( converterCreationContext ), + converter( converterCreationContext, converterDescriptor ), sqlTypeIndicators, context ); } - private static NamedConverterResolution fromInternal( + private static JpaAttributeConverter converter( + JpaAttributeConverterCreationContext converterCreationContext, + ConverterDescriptor converterDescriptor) { + //noinspection unchecked + return (JpaAttributeConverter) converterDescriptor.createJpaAttributeConverter(converterCreationContext); + } + + private static NamedConverterResolution fromInternal( Function explicitJtdAccess, Function explicitStdAccess, Function explicitMutabilityPlanAccess, - JpaAttributeConverter converter, JdbcTypeIndicators sqlTypeIndicators, + JpaAttributeConverter converter, + JdbcTypeIndicators sqlTypeIndicators, MetadataBuildingContext context) { final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration(); - final JavaType explicitJtd = explicitJtdAccess != null + final JavaType explicitJtd = explicitJtdAccess != null ? explicitJtdAccess.apply( typeConfiguration ) : null; - final JavaType domainJtd = explicitJtd != null + final JavaType domainJtd = explicitJtd != null ? explicitJtd : converter.getDomainJavaType(); @@ -103,29 +108,29 @@ public class NamedConverterResolution implements BasicValue.Resolution { ? explicitStdAccess.apply( typeConfiguration ) : null; - final JavaType relationalJtd = converter.getRelationalJavaType(); + final JavaType relationalJtd = converter.getRelationalJavaType(); final JdbcType jdbcType = explicitJdbcType != null ? explicitJdbcType : relationalJtd.getRecommendedJdbcType( sqlTypeIndicators ); - final MutabilityPlan explicitMutabilityPlan = explicitMutabilityPlanAccess != null + final MutabilityPlan explicitMutabilityPlan = explicitMutabilityPlanAccess != null ? explicitMutabilityPlanAccess.apply( typeConfiguration ) : null; - final MutabilityPlan mutabilityPlan; + final MutabilityPlan mutabilityPlan; if ( explicitMutabilityPlan != null ) { mutabilityPlan = explicitMutabilityPlan; } else if ( ! domainJtd.getMutabilityPlan().isMutable() ) { - mutabilityPlan = ImmutableMutabilityPlan.INSTANCE; + mutabilityPlan = ImmutableMutabilityPlan.instance(); } else { - mutabilityPlan = new AttributeConverterMutabilityPlanImpl( converter, true ); + mutabilityPlan = new AttributeConverterMutabilityPlanImpl<>( converter, true ); } - return new NamedConverterResolution( + return new NamedConverterResolution( domainJtd, relationalJtd, jdbcType, @@ -136,24 +141,23 @@ public class NamedConverterResolution implements BasicValue.Resolution { } - private final JavaType domainJtd; - private final JavaType relationalJtd; + private final JavaType domainJtd; + private final JavaType relationalJtd; private final JdbcType jdbcType; - private final JpaAttributeConverter valueConverter; - private final MutabilityPlan mutabilityPlan; + private final JpaAttributeConverter valueConverter; + private final MutabilityPlan mutabilityPlan; private final JdbcMapping jdbcMapping; - private final BasicType legacyResolvedType; + private final BasicType legacyResolvedType; - @SuppressWarnings("unchecked") public NamedConverterResolution( - JavaType domainJtd, - JavaType relationalJtd, + JavaType domainJtd, + JavaType relationalJtd, JdbcType jdbcType, - JpaAttributeConverter valueConverter, - MutabilityPlan mutabilityPlan, + JpaAttributeConverter valueConverter, + MutabilityPlan mutabilityPlan, TypeConfiguration typeConfiguration) { assert domainJtd != null; this.domainJtd = domainJtd; @@ -208,8 +212,9 @@ public class NamedConverterResolution implements BasicValue.Resolution { // typeConfiguration // ); - this.legacyResolvedType = new AttributeConverterTypeAdapter( - ConverterDescriptor.TYPE_NAME_PREFIX + valueConverter.getConverterJavaType().getJavaType().getTypeName(), + this.legacyResolvedType = new AttributeConverterTypeAdapter<>( + ConverterDescriptor.TYPE_NAME_PREFIX + + valueConverter.getConverterJavaType().getJavaType().getTypeName(), String.format( "BasicType adapter for AttributeConverter<%s,%s>", domainJtd.getJavaType().getTypeName(), @@ -225,13 +230,11 @@ public class NamedConverterResolution implements BasicValue.Resolution { @Override public BasicType getLegacyResolvedBasicType() { - //noinspection unchecked return legacyResolvedType; } @Override public JavaType getDomainJavaType() { - //noinspection unchecked return domainJtd; } @@ -251,13 +254,12 @@ public class NamedConverterResolution implements BasicValue.Resolution { } @Override - public JpaAttributeConverter getValueConverter() { + public JpaAttributeConverter getValueConverter() { return valueConverter; } @Override public MutabilityPlan getMutabilityPlan() { - //noinspection unchecked return mutabilityPlan; } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java index c79a1e80da..84b45d1c26 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java @@ -756,8 +756,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol // envers - grr setTypeParameters( properties ); - final CustomType customType = new CustomType<>( (UserType) typeInstance, typeConfiguration ); - this.resolution = new UserTypeResolution( customType, null, properties ); + this.resolution = new UserTypeResolution( + new CustomType<>( (UserType) typeInstance, typeConfiguration ), + null, + properties + ); } } @@ -817,7 +820,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol * Converter, if any, to convert values between the * domain and relational JavaType representations */ - BasicValueConverter getValueConverter(); + BasicValueConverter getValueConverter(); /** * The resolved MutabilityPlan diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java index 18d279269d..76043db6de 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java @@ -52,7 +52,7 @@ import org.hibernate.type.Type; import org.hibernate.type.descriptor.JdbcTypeNameMapper; import org.hibernate.type.descriptor.converter.AttributeConverterJdbcTypeAdapter; import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter; -import org.hibernate.type.descriptor.java.BasicJavaType; +import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; import org.hibernate.type.descriptor.jdbc.LobTypeMappings; @@ -728,8 +728,7 @@ public abstract class SimpleValue implements KeyValue { */ private Type buildAttributeConverterTypeAdapter() { // todo : validate the number of columns present here? - - final JpaAttributeConverter jpaAttributeConverter = attributeConverterDescriptor.createJpaAttributeConverter( + return buildAttributeConverterTypeAdapter( attributeConverterDescriptor.createJpaAttributeConverter( new JpaAttributeConverterCreationContext() { @Override public ManagedBeanRegistry getManagedBeanRegistry() { @@ -744,9 +743,13 @@ public abstract class SimpleValue implements KeyValue { return getMetadata().getTypeConfiguration(); } } - ); + ) ); + } - final BasicJavaType domainJtd = (BasicJavaType) jpaAttributeConverter.getDomainJavaType(); + private AttributeConverterTypeAdapter buildAttributeConverterTypeAdapter( + JpaAttributeConverter jpaAttributeConverter) { + JavaType domainJavaType = jpaAttributeConverter.getDomainJavaType(); + JavaType relationalJavaType = jpaAttributeConverter.getRelationalJavaType(); // build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Going back to the illustration, this should be a SqlTypeDescriptor that handles the Integer <-> String @@ -754,7 +757,7 @@ public abstract class SimpleValue implements KeyValue { // corresponding to the AttributeConverter's declared "databaseColumnJavaType" (how we read that value out // of ResultSets). See JdbcTypeJavaClassMappings for details. Again, given example, this should return // VARCHAR/CHAR - final JdbcType recommendedJdbcType = jpaAttributeConverter.getRelationalJavaType().getRecommendedJdbcType( + final JdbcType recommendedJdbcType = relationalJavaType.getRecommendedJdbcType( // todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods new JdbcTypeIndicators() { @Override @@ -774,7 +777,7 @@ public abstract class SimpleValue implements KeyValue { jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode ); } else { - if ( Serializable.class.isAssignableFrom( domainJtd.getJavaTypeClass() ) ) { + if ( Serializable.class.isAssignableFrom( domainJavaType.getJavaTypeClass() ) ) { jdbcTypeCode = Types.BLOB; } else { @@ -793,33 +796,26 @@ public abstract class SimpleValue implements KeyValue { jdbcTypeCode = NationalizedTypeMappings.toNationalizedTypeCode( jdbcTypeCode ); } - final JdbcType jdbcType = metadata.getTypeConfiguration() - .getJdbcTypeRegistry() - .getDescriptor( jdbcTypeCode ); - - // and finally construct the adapter, which injects the AttributeConverter calls into the binding/extraction - // process... - final JdbcType jdbcTypeAdapter = new AttributeConverterJdbcTypeAdapter( - jpaAttributeConverter, - jdbcType, - jpaAttributeConverter.getRelationalJavaType() - ); // todo : cache the AttributeConverterTypeAdapter in case that AttributeConverter is applied multiple times. - - final String name = ConverterDescriptor.TYPE_NAME_PREFIX + jpaAttributeConverter.getConverterJavaType().getJavaType().getTypeName(); - final String description = String.format( - "BasicType adapter for AttributeConverter<%s,%s>", - jpaAttributeConverter.getDomainJavaType().getJavaType().getTypeName(), - jpaAttributeConverter.getRelationalJavaType().getJavaType().getTypeName() - ); return new AttributeConverterTypeAdapter<>( - name, - description, + ConverterDescriptor.TYPE_NAME_PREFIX + + jpaAttributeConverter.getConverterJavaType().getJavaType().getTypeName(), + String.format( + "BasicType adapter for AttributeConverter<%s,%s>", + domainJavaType.getJavaType().getTypeName(), + relationalJavaType.getJavaType().getTypeName() + ), jpaAttributeConverter, - jdbcTypeAdapter, - jpaAttributeConverter.getRelationalJavaType(), - jpaAttributeConverter.getDomainJavaType(), + // and finally construct the adapter, which injects the AttributeConverter + // calls into the binding/extraction process... + new AttributeConverterJdbcTypeAdapter( + jpaAttributeConverter, + metadata.getTypeConfiguration().getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ), + relationalJavaType + ), + relationalJavaType, + domainJavaType, null ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java index 8eb2205206..23cc429ace 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java @@ -215,7 +215,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType final MutabilityPlan mutabilityPlan; if ( updateable ) { - mutabilityPlan = new MutabilityPlan() { + mutabilityPlan = new MutabilityPlan<>() { @Override public boolean isMutable() { return true; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 84ec17f789..2e185d1e15 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -184,7 +184,7 @@ public class MappingModelCreationHelper { final Value value = bootProperty.getValue(); final BasicValue.Resolution resolution = ( (Resolvable) value ).resolve(); - final BasicValueConverter valueConverter = resolution.getValueConverter(); + final BasicValueConverter valueConverter = resolution.getValueConverter(); final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() { private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan(); @@ -258,7 +258,6 @@ public class MappingModelCreationHelper { // we want to "decompose" the "type" into its various pieces as expected by the mapping assert valueConverter.getRelationalJavaType() == resolution.getRelationalJavaType(); - //noinspection unchecked final BasicType mappingBasicType = creationProcess.getCreationContext() .getDomainModel() .getTypeConfiguration() diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 52aee4bc21..69109a1a09 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -4000,10 +4000,10 @@ public abstract class BaseSqmToSqlAstConverter extends Base } else { final MappingModelExpressible elementExpressible = getElementExpressible( localExpressible ); - if ( elementExpressible instanceof BasicType ) { + if ( elementExpressible instanceof BasicType ) { expressible = InferredBasicValueResolver.resolveSqlTypeIndicators( this, - (BasicType) elementExpressible, + (BasicType) elementExpressible, literal.getJavaTypeDescriptor() ); } @@ -4080,21 +4080,16 @@ public abstract class BaseSqmToSqlAstConverter extends Base } } else { - if ( literal instanceof SqmLiteral ) { - return new QueryLiteral<>( - literal.getLiteralValue(), - creationContext.getSessionFactory() - .getTypeConfiguration() - .getBasicTypeRegistry() - .getRegisteredType( - ( (BasicSqmPathSource) literal.getNodeType() ).getSqmPathType() - .getJavaType() - .getName() - ) - ); - } - throw new NotYetImplementedFor6Exception( - expressible == null ? literal.getLiteralValue().getClass() : expressible.getClass() + return new QueryLiteral<>( + literal.getLiteralValue(), + creationContext.getSessionFactory() + .getTypeConfiguration() + .getBasicTypeRegistry() + .getRegisteredType( + ( (BasicSqmPathSource) literal.getNodeType() ).getSqmPathType() + .getJavaType() + .getName() + ) ); } } @@ -4613,10 +4608,10 @@ public abstract class BaseSqmToSqlAstConverter extends Base @Override public Object visitCastTarget(SqmCastTarget target) { BasicValuedMapping targetType = (BasicValuedMapping) target.getType(); - if ( targetType instanceof BasicType ) { + if ( targetType instanceof BasicType ) { targetType = InferredBasicValueResolver.resolveSqlTypeIndicators( this, - (BasicType) targetType, + (BasicType) targetType, target.getNodeJavaType() ); } @@ -5320,7 +5315,6 @@ public abstract class BaseSqmToSqlAstConverter extends Base final BasicValuedMapping inferrableType = (BasicValuedMapping) resolveInferredType(); if ( inferrableType instanceof ConvertibleModelPart ) { final ConvertibleModelPart inferredPart = (ConvertibleModelPart) inferrableType; - @SuppressWarnings("unchecked") final BasicValueConverter,?> valueConverter = inferredPart.getValueConverter(); final Object jdbcValue = valueConverter.toRelationalValue( sqmEnumLiteral.getEnumValue() ); return new QueryLiteral<>( jdbcValue, inferredPart ); @@ -5335,7 +5329,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base return new ConvertedQueryLiteral( sqmEnumLiteral.getEnumValue(), - new OrdinalEnumValueConverter( enumJtd, jdbcType, relationalJtd ), + new OrdinalEnumValueConverter<>( enumJtd, jdbcType, relationalJtd ), jdbcMappingType ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractClassJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractClassJavaType.java index f71284f1b4..389e9efeaa 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractClassJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractClassJavaType.java @@ -35,9 +35,8 @@ public abstract class AbstractClassJavaType implements BasicJavaType, Seri * * @see #AbstractClassJavaType(Class, MutabilityPlan) */ - @SuppressWarnings({ "unchecked" }) protected AbstractClassJavaType(Class type) { - this( type, (MutabilityPlan) ImmutableMutabilityPlan.INSTANCE ); + this( type, ImmutableMutabilityPlan.instance() ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractJavaType.java index 1b69aec66f..8cf2ab18e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/AbstractJavaType.java @@ -36,9 +36,8 @@ public abstract class AbstractJavaType implements BasicJavaType, Serializa * * @see #AbstractJavaType(Type, MutabilityPlan) */ - @SuppressWarnings({ "unchecked" }) protected AbstractJavaType(Type type) { - this( type, (MutabilityPlan) ImmutableMutabilityPlan.INSTANCE ); + this( type, ImmutableMutabilityPlan.instance() ); } /** @@ -47,7 +46,7 @@ public abstract class AbstractJavaType implements BasicJavaType, Serializa * @param type The Java type. * @param mutabilityPlan The plan for handling mutability aspects of the java type. */ - @SuppressWarnings({ "unchecked" }) + @SuppressWarnings("unchecked") protected AbstractJavaType(Type type, MutabilityPlan mutabilityPlan) { this.type = type; this.mutabilityPlan = mutabilityPlan; @@ -86,13 +85,13 @@ public abstract class AbstractJavaType implements BasicJavaType, Serializa return (value == null) ? "null" : value.toString(); } - protected HibernateException unknownUnwrap(Class conversionType) { + protected HibernateException unknownUnwrap(Class conversionType) { throw new HibernateException( "Unknown unwrap conversion requested: " + type.getTypeName() + " to " + conversionType.getName() ); } - protected HibernateException unknownWrap(Class conversionType) { + protected HibernateException unknownWrap(Class conversionType) { throw new HibernateException( "Unknown wrap conversion requested: " + conversionType.getName() + " to " + type.getTypeName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java index 6a245e1fc5..4644a170fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java @@ -38,9 +38,8 @@ public class DurationJavaType extends AbstractClassJavaType { */ public static final DurationJavaType INSTANCE = new DurationJavaType(); - @SuppressWarnings("unchecked") public DurationJavaType() { - super( Duration.class, ImmutableMutabilityPlan.INSTANCE ); + super( Duration.class, ImmutableMutabilityPlan.instance() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java index c55bc2861c..83b946d69c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/EnumJavaType.java @@ -21,9 +21,8 @@ import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; * @author Steve Ebersole */ public class EnumJavaType> extends AbstractClassJavaType { - @SuppressWarnings("unchecked") public EnumJavaType(Class type) { - super( type, ImmutableMutabilityPlan.INSTANCE ); + super( type, ImmutableMutabilityPlan.instance() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java index b1bd84d5b9..c11b09e144 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/InstantJavaType.java @@ -38,9 +38,8 @@ public class InstantJavaType extends AbstractTemporalJavaType */ public static final InstantJavaType INSTANCE = new InstantJavaType(); - @SuppressWarnings("unchecked") public InstantJavaType() { - super( Instant.class, ImmutableMutabilityPlan.INSTANCE ); + super( Instant.class, ImmutableMutabilityPlan.instance() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java index 34eaac6d4b..dcd8d268a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java @@ -59,9 +59,8 @@ public interface JavaType extends Serializable { /** * Retrieve the mutability plan for this Java type. */ - @SuppressWarnings("unchecked") default MutabilityPlan getMutabilityPlan() { - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } default T getReplacement(T original, T target, SharedSessionContractImplementor session) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java index 074255266c..be8c7d434c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateJavaType.java @@ -36,9 +36,8 @@ public class LocalDateJavaType extends AbstractTemporalJavaType { */ public static final LocalDateJavaType INSTANCE = new LocalDateJavaType(); - @SuppressWarnings("unchecked") public LocalDateJavaType() { - super( LocalDate.class, ImmutableMutabilityPlan.INSTANCE ); + super( LocalDate.class, ImmutableMutabilityPlan.instance() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java index 6c890c8aba..aafc38454d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocalDateTimeJavaType.java @@ -37,9 +37,8 @@ public class LocalDateTimeJavaType extends AbstractTemporalJavaType { */ public static final LocalTimeJavaType INSTANCE = new LocalTimeJavaType(); - @SuppressWarnings("unchecked") public LocalTimeJavaType() { - super( LocalTime.class, ImmutableMutabilityPlan.INSTANCE ); + super( LocalTime.class, ImmutableMutabilityPlan.instance() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java index 3bd39e64ee..bac6851746 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/LocaleJavaType.java @@ -28,7 +28,7 @@ public class LocaleJavaType extends AbstractClassJavaType { } public LocaleJavaType() { - super( Locale.class, ImmutableMutabilityPlan.INSTANCE, LocaleComparator.INSTANCE ); + super( Locale.class, ImmutableMutabilityPlan.instance(), LocaleComparator.INSTANCE ); } public String toString(Locale value) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java index db7cfef650..8fe2ce8230 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ObjectArrayJavaType.java @@ -15,15 +15,15 @@ import org.hibernate.type.descriptor.WrapperOptions; */ public class ObjectArrayJavaType extends AbstractClassJavaType { - private final JavaType[] components; + private final JavaType[] components; - public ObjectArrayJavaType(JavaType[] components) { + public ObjectArrayJavaType(JavaType[] components) { super( Object[].class, - ImmutableMutabilityPlan.INSTANCE, - new ComponentArrayComparator( (JavaType[]) components ) + ImmutableMutabilityPlan.instance(), + new ComponentArrayComparator( components ) ); - this.components = (JavaType[]) components; + this.components = components; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java index ce74f7e157..5328bc08df 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/OffsetDateTimeJavaType.java @@ -40,9 +40,8 @@ public class OffsetDateTimeJavaType extends AbstractTemporalJavaType { */ public static final OffsetTimeJavaType INSTANCE = new OffsetTimeJavaType(); - @SuppressWarnings("unchecked") public OffsetTimeJavaType() { - super( OffsetTime.class, ImmutableMutabilityPlan.INSTANCE ); + super( OffsetTime.class, ImmutableMutabilityPlan.instance() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableJavaType.java index c12fb5ad59..36add44e5c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableJavaType.java @@ -54,10 +54,9 @@ public class SerializableJavaType extends AbstractClassJ super( type, mutabilityPlan == null ? createMutabilityPlan( type ) : mutabilityPlan ); } - @SuppressWarnings({ "unchecked" }) private static MutabilityPlan createMutabilityPlan(Class type) { if ( type.isAnnotationPresent( Immutable.class ) ) { - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } return (MutabilityPlan) SerializableMutabilityPlan.INSTANCE; } diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java index 543434f9d1..dae3dd2cf6 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneJavaType.java @@ -28,7 +28,7 @@ public class TimeZoneJavaType extends AbstractClassJavaType { } public TimeZoneJavaType() { - super( TimeZone.class, ImmutableMutabilityPlan.INSTANCE, TimeZoneComparator.INSTANCE ); + super( TimeZone.class, ImmutableMutabilityPlan.instance(), TimeZoneComparator.INSTANCE ); } public String toString(TimeZone value) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaType.java index 837746960f..f10834603c 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZoneOffsetJavaType.java @@ -31,7 +31,7 @@ public class ZoneOffsetJavaType extends AbstractClassJavaType { } public ZoneOffsetJavaType() { - super( ZoneOffset.class, ImmutableMutabilityPlan.INSTANCE, ZoneOffsetComparator.INSTANCE ); + super( ZoneOffset.class, ImmutableMutabilityPlan.instance(), ZoneOffsetComparator.INSTANCE ); } public String toString(ZoneOffset value) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java index 63d19ba677..059fc412c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ZonedDateTimeJavaType.java @@ -40,9 +40,8 @@ public class ZonedDateTimeJavaType extends AbstractTemporalJavaType MutabilityPlan determineMutabilityPlan(Type javaType, TypeConfiguration typeConfiguration) { final Class javaTypeClass = determineJavaTypeClass( javaType ); if ( javaTypeClass.isAnnotationPresent( Immutable.class ) ) { - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } if ( javaTypeClass.isAnnotationPresent( Mutability.class ) ) { @@ -71,11 +70,11 @@ public class RegistryHelper { } if ( javaTypeClass.isEnum() ) { - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } if ( javaTypeClass.isPrimitive() ) { - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } if ( Serializable.class.isAssignableFrom( javaTypeClass ) ) { @@ -85,7 +84,6 @@ public class RegistryHelper { return null; } - @SuppressWarnings("unchecked") private JavaType createTypeDescriptor( Type javaType, Function,MutabilityPlan> mutabilityPlanResolver) { @@ -93,14 +91,14 @@ public class RegistryHelper { if ( javaTypeClass.isEnum() ) { // enums are unequivocally immutable - //noinspection rawtypes + //noinspection rawtypes, unchecked return new EnumJavaType( javaTypeClass ); } final MutabilityPlan plan = mutabilityPlanResolver.apply( javaTypeClass ); if ( Serializable.class.isAssignableFrom( javaTypeClass ) ) { - //noinspection rawtypes + //noinspection rawtypes, unchecked return new SerializableJavaType( javaTypeClass, plan ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableConvertedBasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableConvertedBasicTypeImpl.java index 02eb214502..d68fa5e43b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableConvertedBasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableConvertedBasicTypeImpl.java @@ -27,7 +27,6 @@ public class ImmutableConvertedBasicTypeImpl extends ConvertedBasicTypeImpl getMutabilityPlan() { - //noinspection unchecked - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableNamedBasicTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableNamedBasicTypeImpl.java index 848632d1e3..ae8ddf8c5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableNamedBasicTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/type/internal/ImmutableNamedBasicTypeImpl.java @@ -25,7 +25,6 @@ public class ImmutableNamedBasicTypeImpl extends NamedBasicTypeImpl { @Override protected MutabilityPlan getMutabilityPlan() { - //noinspection unchecked - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java index 4b4a9062c9..a3a01bda90 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/ExplicitJavaTypeDescriptorTest.java @@ -89,7 +89,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT @After public void dropTestData() { inTransaction( - (session) -> session.createQuery( "delete TheEntity" ).executeUpdate() + session -> session.createQuery( "delete TheEntity" ).executeUpdate() ); } @@ -320,8 +320,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT @Override public MutabilityPlan getMutabilityPlan() { - //noinspection unchecked - return ImmutableMutabilityPlan.INSTANCE; + return ImmutableMutabilityPlan.instance(); } @Override