clean up a bunch of generics-related warnings

This commit is contained in:
Gavin King 2022-02-05 19:57:41 +01:00
parent 86cdf67016
commit bedd31b36e
31 changed files with 298 additions and 294 deletions

View File

@ -101,9 +101,8 @@ public abstract class AbstractConverterDescriptor implements ConverterDescriptor
} }
@Override @Override
@SuppressWarnings({ "unchecked", "rawtypes" }) public JpaAttributeConverter<?,?> createJpaAttributeConverter(JpaAttributeConverterCreationContext context) {
public JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context) { final JavaType<?> converterJtd = context
final JavaType<Object> converterJtd = context
.getJavaTypeRegistry() .getJavaTypeRegistry()
.getDescriptor( getAttributeConverterClass() ); .getDescriptor( getAttributeConverterClass() );

View File

@ -45,5 +45,5 @@ public interface ConverterDescriptor {
/** /**
* Factory for the runtime representation of the converter * Factory for the runtime representation of the converter
*/ */
JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context); JpaAttributeConverter<?,?> createJpaAttributeConverter(JpaAttributeConverterCreationContext context);
} }

View File

@ -17,26 +17,26 @@ import org.hibernate.type.descriptor.jdbc.JdbcType;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class InferredBasicValueResolution<J> implements BasicValue.Resolution<J> { public class InferredBasicValueResolution<J,T> implements BasicValue.Resolution<J> {
private JavaType<J> domainJtd; private final JavaType<J> domainJtd;
private JavaType<J> relationalJtd; private final JavaType<T> relationalJtd;
private JdbcType jdbcType; private final JdbcType jdbcType;
private MutabilityPlan mutabilityPlan; private final MutabilityPlan<J> mutabilityPlan;
private JdbcMapping jdbcMapping; private final JdbcMapping jdbcMapping;
private BasicValueConverter valueConverter; private final BasicValueConverter<J,T> valueConverter;
private final BasicType<J> legacyType; private final BasicType<J> legacyType;
public InferredBasicValueResolution( public InferredBasicValueResolution(
JdbcMapping jdbcMapping, JdbcMapping jdbcMapping,
JavaType<J> domainJtd, JavaType<J> domainJtd,
JavaType<J> relationalJtd, JavaType<T> relationalJtd,
JdbcType jdbcType, JdbcType jdbcType,
BasicValueConverter valueConverter, BasicValueConverter<J,T> valueConverter,
BasicType<J> legacyType, BasicType<J> legacyType,
MutabilityPlan mutabilityPlan) { MutabilityPlan<J> mutabilityPlan) {
this.jdbcMapping = jdbcMapping; this.jdbcMapping = jdbcMapping;
this.legacyType = legacyType; this.legacyType = legacyType;
this.domainJtd = domainJtd; this.domainJtd = domainJtd;
@ -52,7 +52,7 @@ public class InferredBasicValueResolution<J> implements BasicValue.Resolution<J>
} }
@Override @Override
public BasicType getLegacyResolvedBasicType() { public BasicType<J> getLegacyResolvedBasicType() {
return legacyType; return legacyType;
} }
@ -72,7 +72,7 @@ public class InferredBasicValueResolution<J> implements BasicValue.Resolution<J>
} }
@Override @Override
public BasicValueConverter getValueConverter() { public BasicValueConverter<J,T> getValueConverter() {
return valueConverter; return valueConverter;
} }

View File

@ -18,7 +18,6 @@ import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table; 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.NamedEnumValueConverter;
import org.hibernate.metamodel.model.convert.internal.OrdinalEnumValueConverter; import org.hibernate.metamodel.model.convert.internal.OrdinalEnumValueConverter;
import org.hibernate.type.AdjustableBasicType; import org.hibernate.type.AdjustableBasicType;
@ -45,12 +44,11 @@ public class InferredBasicValueResolver {
/** /**
* Create an inference-based resolution * Create an inference-based resolution
*/ */
@SuppressWarnings({"unchecked", "rawtypes"}) public static <T> BasicValue.Resolution<T> from(
public static BasicValue.Resolution from(
Function<TypeConfiguration, BasicJavaType> explicitJavaTypeAccess, Function<TypeConfiguration, BasicJavaType> explicitJavaTypeAccess,
Function<TypeConfiguration, JdbcType> explicitSqlTypeAccess, Function<TypeConfiguration, JdbcType> explicitSqlTypeAccess,
Type resolvedJavaType, Type resolvedJavaType,
Supplier<JavaType> reflectedJtdResolver, Supplier<JavaType<T>> reflectedJtdResolver,
JdbcTypeIndicators stdIndicators, JdbcTypeIndicators stdIndicators,
Table table, Table table,
Selectable selectable, Selectable selectable,
@ -58,17 +56,21 @@ public class InferredBasicValueResolver {
String propertyName, String propertyName,
TypeConfiguration typeConfiguration) { TypeConfiguration typeConfiguration) {
final BasicJavaType explicitJavaType = explicitJavaTypeAccess != null ? explicitJavaTypeAccess.apply( typeConfiguration ) : null; final BasicJavaType<T> explicitJavaType = explicitJavaTypeAccess != null
final JdbcType explicitJdbcType = explicitSqlTypeAccess != null ? explicitSqlTypeAccess.apply( typeConfiguration ) : null; ? explicitJavaTypeAccess.apply( typeConfiguration )
: null;
final JdbcType explicitJdbcType = explicitSqlTypeAccess
!= null ? explicitSqlTypeAccess.apply( typeConfiguration )
: null;
final BasicJavaType reflectedJtd = (BasicJavaType) reflectedJtdResolver.get(); final JavaType<T> reflectedJtd = reflectedJtdResolver.get();
// NOTE : the distinction that is made below wrt `explicitJavaType` and `reflectedJtd` is // NOTE : the distinction that is made below wrt `explicitJavaType` and `reflectedJtd` is
// needed temporarily to trigger "legacy resolution" versus "ORM6 resolution. Yes, it // 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 // makes the code a little more complicated but the benefit is well worth it - saving memory
final BasicType<?> jdbcMapping; final BasicType<T> jdbcMapping;
final BasicType<?> legacyType; final BasicType<T> legacyType;
if ( explicitJavaType != null ) { if ( explicitJavaType != null ) {
// we have an explicit JavaType // we have an explicit JavaType
@ -99,7 +101,7 @@ public class InferredBasicValueResolver {
} }
else if ( explicitJavaType instanceof TemporalJavaType ) { else if ( explicitJavaType instanceof TemporalJavaType ) {
return fromTemporal( return fromTemporal(
(TemporalJavaType) reflectedJtd, (TemporalJavaType<T>) reflectedJtd,
explicitJavaType, explicitJavaType,
null, null,
resolvedJavaType, resolvedJavaType,
@ -107,8 +109,9 @@ public class InferredBasicValueResolver {
typeConfiguration typeConfiguration
); );
} }
else if ( explicitJavaType instanceof SerializableJavaType || explicitJavaType.getJavaType() instanceof Serializable ) { else if ( explicitJavaType instanceof SerializableJavaType
legacyType = new SerializableType<>( explicitJavaType ); || explicitJavaType.getJavaType() instanceof Serializable ) {
legacyType = new SerializableType( explicitJavaType );
jdbcMapping = legacyType; jdbcMapping = legacyType;
} }
else { else {
@ -154,7 +157,7 @@ public class InferredBasicValueResolver {
} }
else if ( reflectedJtd instanceof TemporalJavaType ) { else if ( reflectedJtd instanceof TemporalJavaType ) {
return fromTemporal( return fromTemporal(
(TemporalJavaType) reflectedJtd, (TemporalJavaType<T>) reflectedJtd,
null, null,
null, null,
resolvedJavaType, resolvedJavaType,
@ -165,7 +168,8 @@ public class InferredBasicValueResolver {
else { else {
// see if there is a registered BasicType for this JavaType and, if so, use it. // see if there is a registered BasicType for this JavaType and, if so, use it.
// this mimics the legacy handling // this mimics the legacy handling
final BasicType registeredType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( reflectedJtd.getJavaType() ); final BasicType<T> registeredType = typeConfiguration.getBasicTypeRegistry()
.getRegisteredType( reflectedJtd.getJavaType() );
if ( registeredType != null ) { if ( registeredType != null ) {
// so here is the legacy resolution // so here is the legacy resolution
@ -183,8 +187,9 @@ public class InferredBasicValueResolver {
); );
legacyType = jdbcMapping; legacyType = jdbcMapping;
} }
else if ( reflectedJtd instanceof SerializableJavaType || Serializable.class.isAssignableFrom( reflectedJtd.getJavaTypeClass() ) ) { else if ( reflectedJtd instanceof SerializableJavaType
legacyType = new SerializableType<>( reflectedJtd ); || Serializable.class.isAssignableFrom( reflectedJtd.getJavaTypeClass() ) ) {
legacyType = new SerializableType( reflectedJtd );
jdbcMapping = legacyType; jdbcMapping = legacyType;
} }
else { else {
@ -217,17 +222,20 @@ public class InferredBasicValueResolver {
} }
} }
} }
final BasicJavaType recommendedJtd = explicitJdbcType.getJdbcRecommendedJavaTypeMapping(
final BasicJavaType<T> recommendedJtd = explicitJdbcType.getJdbcRecommendedJavaTypeMapping(
length, length,
scale, scale,
typeConfiguration 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; legacyType = jdbcMapping;
} }
else { else {
@ -252,7 +260,7 @@ public class InferredBasicValueResolver {
); );
} }
return new InferredBasicValueResolution( return new InferredBasicValueResolution<>(
jdbcMapping, jdbcMapping,
jdbcMapping.getJavaTypeDescriptor(), jdbcMapping.getJavaTypeDescriptor(),
jdbcMapping.getJavaTypeDescriptor(), jdbcMapping.getJavaTypeDescriptor(),
@ -263,14 +271,13 @@ public class InferredBasicValueResolver {
); );
} }
@SuppressWarnings("rawtypes") public static <T> BasicType<T> resolveSqlTypeIndicators(
public static BasicType<?> resolveSqlTypeIndicators(
JdbcTypeIndicators stdIndicators, JdbcTypeIndicators stdIndicators,
BasicType<?> resolved, BasicType<T> resolved,
JavaType<?> domainJtd) { JavaType<T> domainJtd) {
if ( resolved instanceof AdjustableBasicType ) { if ( resolved instanceof AdjustableBasicType ) {
final AdjustableBasicType indicatorCapable = (AdjustableBasicType) resolved; final AdjustableBasicType<T> indicatorCapable = (AdjustableBasicType<T>) resolved;
final BasicType indicatedType = indicatorCapable.resolveIndicatedType( stdIndicators, domainJtd ); final BasicType<T> indicatedType = indicatorCapable.resolveIndicatedType( stdIndicators, domainJtd );
return indicatedType != null ? indicatedType : resolved; return indicatedType != null ? indicatedType : resolved;
} }
else { else {
@ -278,10 +285,9 @@ public class InferredBasicValueResolver {
} }
} }
@SuppressWarnings("rawtypes") public static <E extends Enum<E>> InferredBasicValueResolution<E,?> fromEnum(
public static <E extends Enum<E>> InferredBasicValueResolution fromEnum(
EnumJavaType<E> enumJavaType, EnumJavaType<E> enumJavaType,
BasicJavaType explicitJavaType, BasicJavaType<?> explicitJavaType,
JdbcType explicitJdbcType, JdbcType explicitJdbcType,
JdbcTypeIndicators stdIndicators, JdbcTypeIndicators stdIndicators,
TypeConfiguration typeConfiguration) { TypeConfiguration typeConfiguration) {
@ -291,101 +297,21 @@ public class InferredBasicValueResolver {
switch ( enumStyle ) { switch ( enumStyle ) {
case STRING: { case STRING: {
final JavaType<?> relationalJtd; return stringEnumValueResolution(
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(
enumJavaType, enumJavaType,
jdbcType, explicitJavaType,
relationalJtd explicitJdbcType,
); stdIndicators,
final org.hibernate.type.EnumType<E> legacyEnumType = new org.hibernate.type.EnumType<>(
enumJavaType.getJavaTypeClass(),
valueConverter,
typeConfiguration typeConfiguration
); );
final CustomType<E> 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: { case ORDINAL: {
final JavaType<Integer> relationalJtd; return ordinalEnumValueResolution(
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(
enumJavaType, enumJavaType,
jdbcType, explicitJavaType,
relationalJtd explicitJdbcType,
);
final org.hibernate.type.EnumType<E> legacyEnumType = new org.hibernate.type.EnumType<>(
enumJavaType.getJavaTypeClass(),
valueConverter,
typeConfiguration typeConfiguration
); );
final CustomType<E> 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: { default: {
throw new MappingException( "Unknown enumeration-style (JPA EnumType) : " + enumStyle ); throw new MappingException( "Unknown enumeration-style (JPA EnumType) : " + enumStyle );
@ -393,10 +319,110 @@ public class InferredBasicValueResolver {
} }
} }
@SuppressWarnings({"rawtypes", "unchecked"}) private static <E extends Enum<E>> InferredBasicValueResolution<E, Integer> ordinalEnumValueResolution(
public static InferredBasicValueResolution fromTemporal( EnumJavaType<E> enumJavaType,
TemporalJavaType reflectedJtd, BasicJavaType<?> explicitJavaType,
BasicJavaType explicitJavaType, JdbcType explicitJdbcType,
TypeConfiguration typeConfiguration) {
final JavaType<Integer> 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<Integer>) explicitJavaType;
}
else {
relationalJtd = typeConfiguration.getJavaTypeRegistry().getDescriptor( Integer.class );
}
final JdbcType jdbcType = explicitJdbcType != null
? explicitJdbcType
: typeConfiguration.getJdbcTypeRegistry().getDescriptor( SqlTypes.TINYINT );
final OrdinalEnumValueConverter<E> 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 <E extends Enum<E>> InferredBasicValueResolution<E, String> stringEnumValueResolution(
EnumJavaType<E> enumJavaType,
BasicJavaType<?> explicitJavaType,
JdbcType explicitJdbcType,
JdbcTypeIndicators stdIndicators,
TypeConfiguration typeConfiguration) {
final JavaType<String> 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<String>) 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<E> 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 <T> InferredBasicValueResolution<T,T> fromTemporal(
TemporalJavaType<T> reflectedJtd,
BasicJavaType<?> explicitJavaType,
JdbcType explicitJdbcType, JdbcType explicitJdbcType,
Type resolvedJavaType, Type resolvedJavaType,
JdbcTypeIndicators stdIndicators, JdbcTypeIndicators stdIndicators,
@ -407,14 +433,15 @@ public class InferredBasicValueResolver {
// Case #1 - explicit JavaType // Case #1 - explicit JavaType
if ( explicitJavaType != null ) { if ( explicitJavaType != null ) {
if ( !TemporalJavaType.class.isInstance( explicitJavaType ) ) { if ( !(explicitJavaType instanceof TemporalJavaType) ) {
throw new MappingException( throw new MappingException(
"Explicit JavaType [" + explicitJavaType + "Explicit JavaType [" + explicitJavaType +
"] defined for temporal value must implement TemporalJavaType" "] defined for temporal value must implement TemporalJavaType"
); );
} }
final TemporalJavaType explicitTemporalJtd = (TemporalJavaType) explicitJavaType; @SuppressWarnings("unchecked")
final TemporalJavaType<T> explicitTemporalJtd = (TemporalJavaType<T>) explicitJavaType;
if ( requestedTemporalPrecision != null && explicitTemporalJtd.getPrecision() != requestedTemporalPrecision ) { if ( requestedTemporalPrecision != null && explicitTemporalJtd.getPrecision() != requestedTemporalPrecision ) {
throw new MappingException( 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<T> jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( explicitTemporalJtd, jdbcType );
return new InferredBasicValueResolution( return new InferredBasicValueResolution<>(
jdbcMapping, jdbcMapping,
explicitTemporalJtd, explicitTemporalJtd,
explicitTemporalJtd, explicitTemporalJtd,
jdbcType, jdbcType,
null, null,
jdbcMapping, jdbcMapping,
explicitJavaType.getMutabilityPlan() explicitTemporalJtd.getMutabilityPlan()
); );
} }
@ -446,7 +475,7 @@ public class InferredBasicValueResolver {
// due to the new annotations being used // due to the new annotations being used
if ( explicitJdbcType != null ) { if ( explicitJdbcType != null ) {
final TemporalJavaType jtd; final TemporalJavaType<T> jtd;
if ( requestedTemporalPrecision != null ) { if ( requestedTemporalPrecision != null ) {
jtd = reflectedJtd.resolveTypeForPrecision( jtd = reflectedJtd.resolveTypeForPrecision(
@ -458,9 +487,9 @@ public class InferredBasicValueResolver {
jtd = reflectedJtd; jtd = reflectedJtd;
} }
final BasicType jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( jtd, explicitJdbcType ); final BasicType<T> jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( jtd, explicitJdbcType );
return new InferredBasicValueResolution( return new InferredBasicValueResolution<>(
jdbcMapping, jdbcMapping,
jtd, jtd,
jtd, jtd,
@ -476,7 +505,7 @@ public class InferredBasicValueResolver {
// //
// - for the moment continue to use the legacy resolution to registered // - for the moment continue to use the legacy resolution to registered
// BasicType // BasicType
final BasicType basicType; final BasicType<T> basicType;
if ( requestedTemporalPrecision != null && requestedTemporalPrecision != reflectedJtd.getPrecision() ) { if ( requestedTemporalPrecision != null && requestedTemporalPrecision != reflectedJtd.getPrecision() ) {
basicType = typeConfiguration.getBasicTypeRegistry().resolve( basicType = typeConfiguration.getBasicTypeRegistry().resolve(
reflectedJtd.resolveTypeForPrecision( requestedTemporalPrecision, typeConfiguration ), reflectedJtd.resolveTypeForPrecision( requestedTemporalPrecision, typeConfiguration ),
@ -490,7 +519,7 @@ public class InferredBasicValueResolver {
); );
} }
return new InferredBasicValueResolution( return new InferredBasicValueResolution<>(
basicType, basicType,
basicType.getJavaTypeDescriptor(), basicType.getJavaTypeDescriptor(),
basicType.getJavaTypeDescriptor(), basicType.getJavaTypeDescriptor(),

View File

@ -32,10 +32,9 @@ import org.hibernate.type.spi.TypeConfiguration;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings("rawtypes")
public class NamedConverterResolution<J> implements BasicValue.Resolution<J> { public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
public static NamedConverterResolution from( public static <T> NamedConverterResolution<T> from(
ConverterDescriptor converterDescriptor, ConverterDescriptor converterDescriptor,
Function<TypeConfiguration, BasicJavaType> explicitJtdAccess, Function<TypeConfiguration, BasicJavaType> explicitJtdAccess,
Function<TypeConfiguration, JdbcType> explicitStdAccess, Function<TypeConfiguration, JdbcType> explicitStdAccess,
@ -47,13 +46,13 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
explicitJtdAccess, explicitJtdAccess,
explicitStdAccess, explicitStdAccess,
explicitMutabilityPlanAccess, explicitMutabilityPlanAccess,
converterDescriptor.createJpaAttributeConverter( converterCreationContext ), converter( converterCreationContext, converterDescriptor ),
sqlTypeIndicators, sqlTypeIndicators,
context context
); );
} }
public static NamedConverterResolution from( public static <T> NamedConverterResolution<T> from(
String name, String name,
Function<TypeConfiguration, BasicJavaType> explicitJtdAccess, Function<TypeConfiguration, BasicJavaType> explicitJtdAccess,
Function<TypeConfiguration, JdbcType> explicitStdAccess, Function<TypeConfiguration, JdbcType> explicitStdAccess,
@ -64,12 +63,10 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
assert name.startsWith( ConverterDescriptor.TYPE_NAME_PREFIX ); assert name.startsWith( ConverterDescriptor.TYPE_NAME_PREFIX );
final String converterClassName = name.substring( ConverterDescriptor.TYPE_NAME_PREFIX.length() ); 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<? extends AttributeConverter> converterClass = classLoaderService.classForName( converterClassName );
final ClassBasedConverterDescriptor converterDescriptor = new ClassBasedConverterDescriptor( final ClassBasedConverterDescriptor converterDescriptor = new ClassBasedConverterDescriptor(
converterClass, context.getBootstrapContext().getServiceRegistry()
.getService( ClassLoaderService.class )
.classForName( converterClassName ),
context.getBootstrapContext().getClassmateContext() context.getBootstrapContext().getClassmateContext()
); );
@ -77,25 +74,33 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
explicitJtdAccess, explicitJtdAccess,
explicitStdAccess, explicitStdAccess,
explicitMutabilityPlanAccess, explicitMutabilityPlanAccess,
converterDescriptor.createJpaAttributeConverter( converterCreationContext ), converter( converterCreationContext, converterDescriptor ),
sqlTypeIndicators, sqlTypeIndicators,
context context
); );
} }
private static NamedConverterResolution fromInternal( private static <T> JpaAttributeConverter<T, ?> converter(
JpaAttributeConverterCreationContext converterCreationContext,
ConverterDescriptor converterDescriptor) {
//noinspection unchecked
return (JpaAttributeConverter<T,?>) converterDescriptor.createJpaAttributeConverter(converterCreationContext);
}
private static <T> NamedConverterResolution<T> fromInternal(
Function<TypeConfiguration, BasicJavaType> explicitJtdAccess, Function<TypeConfiguration, BasicJavaType> explicitJtdAccess,
Function<TypeConfiguration, JdbcType> explicitStdAccess, Function<TypeConfiguration, JdbcType> explicitStdAccess,
Function<TypeConfiguration, MutabilityPlan> explicitMutabilityPlanAccess, Function<TypeConfiguration, MutabilityPlan> explicitMutabilityPlanAccess,
JpaAttributeConverter converter, JdbcTypeIndicators sqlTypeIndicators, JpaAttributeConverter<T,?> converter,
JdbcTypeIndicators sqlTypeIndicators,
MetadataBuildingContext context) { MetadataBuildingContext context) {
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration(); final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JavaType explicitJtd = explicitJtdAccess != null final JavaType<T> explicitJtd = explicitJtdAccess != null
? explicitJtdAccess.apply( typeConfiguration ) ? explicitJtdAccess.apply( typeConfiguration )
: null; : null;
final JavaType domainJtd = explicitJtd != null final JavaType<T> domainJtd = explicitJtd != null
? explicitJtd ? explicitJtd
: converter.getDomainJavaType(); : converter.getDomainJavaType();
@ -103,29 +108,29 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
? explicitStdAccess.apply( typeConfiguration ) ? explicitStdAccess.apply( typeConfiguration )
: null; : null;
final JavaType relationalJtd = converter.getRelationalJavaType(); final JavaType<?> relationalJtd = converter.getRelationalJavaType();
final JdbcType jdbcType = explicitJdbcType != null final JdbcType jdbcType = explicitJdbcType != null
? explicitJdbcType ? explicitJdbcType
: relationalJtd.getRecommendedJdbcType( sqlTypeIndicators ); : relationalJtd.getRecommendedJdbcType( sqlTypeIndicators );
final MutabilityPlan explicitMutabilityPlan = explicitMutabilityPlanAccess != null final MutabilityPlan<T> explicitMutabilityPlan = explicitMutabilityPlanAccess != null
? explicitMutabilityPlanAccess.apply( typeConfiguration ) ? explicitMutabilityPlanAccess.apply( typeConfiguration )
: null; : null;
final MutabilityPlan mutabilityPlan; final MutabilityPlan<T> mutabilityPlan;
if ( explicitMutabilityPlan != null ) { if ( explicitMutabilityPlan != null ) {
mutabilityPlan = explicitMutabilityPlan; mutabilityPlan = explicitMutabilityPlan;
} }
else if ( ! domainJtd.getMutabilityPlan().isMutable() ) { else if ( ! domainJtd.getMutabilityPlan().isMutable() ) {
mutabilityPlan = ImmutableMutabilityPlan.INSTANCE; mutabilityPlan = ImmutableMutabilityPlan.instance();
} }
else { else {
mutabilityPlan = new AttributeConverterMutabilityPlanImpl( converter, true ); mutabilityPlan = new AttributeConverterMutabilityPlanImpl<>( converter, true );
} }
return new NamedConverterResolution( return new NamedConverterResolution<T>(
domainJtd, domainJtd,
relationalJtd, relationalJtd,
jdbcType, jdbcType,
@ -136,24 +141,23 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
} }
private final JavaType domainJtd; private final JavaType<J> domainJtd;
private final JavaType relationalJtd; private final JavaType<?> relationalJtd;
private final JdbcType jdbcType; private final JdbcType jdbcType;
private final JpaAttributeConverter valueConverter; private final JpaAttributeConverter<J,?> valueConverter;
private final MutabilityPlan mutabilityPlan; private final MutabilityPlan<J> mutabilityPlan;
private final JdbcMapping jdbcMapping; private final JdbcMapping jdbcMapping;
private final BasicType legacyResolvedType; private final BasicType<J> legacyResolvedType;
@SuppressWarnings("unchecked")
public NamedConverterResolution( public NamedConverterResolution(
JavaType domainJtd, JavaType<J> domainJtd,
JavaType relationalJtd, JavaType<?> relationalJtd,
JdbcType jdbcType, JdbcType jdbcType,
JpaAttributeConverter valueConverter, JpaAttributeConverter<J,?> valueConverter,
MutabilityPlan mutabilityPlan, MutabilityPlan<J> mutabilityPlan,
TypeConfiguration typeConfiguration) { TypeConfiguration typeConfiguration) {
assert domainJtd != null; assert domainJtd != null;
this.domainJtd = domainJtd; this.domainJtd = domainJtd;
@ -208,8 +212,9 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
// typeConfiguration // typeConfiguration
// ); // );
this.legacyResolvedType = new AttributeConverterTypeAdapter( this.legacyResolvedType = new AttributeConverterTypeAdapter<>(
ConverterDescriptor.TYPE_NAME_PREFIX + valueConverter.getConverterJavaType().getJavaType().getTypeName(), ConverterDescriptor.TYPE_NAME_PREFIX
+ valueConverter.getConverterJavaType().getJavaType().getTypeName(),
String.format( String.format(
"BasicType adapter for AttributeConverter<%s,%s>", "BasicType adapter for AttributeConverter<%s,%s>",
domainJtd.getJavaType().getTypeName(), domainJtd.getJavaType().getTypeName(),
@ -225,13 +230,11 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
@Override @Override
public BasicType<J> getLegacyResolvedBasicType() { public BasicType<J> getLegacyResolvedBasicType() {
//noinspection unchecked
return legacyResolvedType; return legacyResolvedType;
} }
@Override @Override
public JavaType<J> getDomainJavaType() { public JavaType<J> getDomainJavaType() {
//noinspection unchecked
return domainJtd; return domainJtd;
} }
@ -251,13 +254,12 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
} }
@Override @Override
public JpaAttributeConverter getValueConverter() { public JpaAttributeConverter<J,?> getValueConverter() {
return valueConverter; return valueConverter;
} }
@Override @Override
public MutabilityPlan<J> getMutabilityPlan() { public MutabilityPlan<J> getMutabilityPlan() {
//noinspection unchecked
return mutabilityPlan; return mutabilityPlan;
} }

View File

@ -756,8 +756,11 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
// envers - grr // envers - grr
setTypeParameters( properties ); setTypeParameters( properties );
final CustomType<Object> customType = new CustomType<>( (UserType<Object>) typeInstance, typeConfiguration ); this.resolution = new UserTypeResolution(
this.resolution = new UserTypeResolution( customType, null, properties ); new CustomType<>( (UserType<Object>) typeInstance, typeConfiguration ),
null,
properties
);
} }
} }
@ -817,7 +820,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
* Converter, if any, to convert values between the * Converter, if any, to convert values between the
* domain and relational JavaType representations * domain and relational JavaType representations
*/ */
BasicValueConverter getValueConverter(); BasicValueConverter<J,?> getValueConverter();
/** /**
* The resolved MutabilityPlan * The resolved MutabilityPlan

View File

@ -52,7 +52,7 @@ import org.hibernate.type.Type;
import org.hibernate.type.descriptor.JdbcTypeNameMapper; import org.hibernate.type.descriptor.JdbcTypeNameMapper;
import org.hibernate.type.descriptor.converter.AttributeConverterJdbcTypeAdapter; import org.hibernate.type.descriptor.converter.AttributeConverterJdbcTypeAdapter;
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter; 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.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
import org.hibernate.type.descriptor.jdbc.LobTypeMappings; import org.hibernate.type.descriptor.jdbc.LobTypeMappings;
@ -728,8 +728,7 @@ public abstract class SimpleValue implements KeyValue {
*/ */
private Type buildAttributeConverterTypeAdapter() { private Type buildAttributeConverterTypeAdapter() {
// todo : validate the number of columns present here? // todo : validate the number of columns present here?
return buildAttributeConverterTypeAdapter( attributeConverterDescriptor.createJpaAttributeConverter(
final JpaAttributeConverter jpaAttributeConverter = attributeConverterDescriptor.createJpaAttributeConverter(
new JpaAttributeConverterCreationContext() { new JpaAttributeConverterCreationContext() {
@Override @Override
public ManagedBeanRegistry getManagedBeanRegistry() { public ManagedBeanRegistry getManagedBeanRegistry() {
@ -744,9 +743,13 @@ public abstract class SimpleValue implements KeyValue {
return getMetadata().getTypeConfiguration(); return getMetadata().getTypeConfiguration();
} }
} }
); ) );
}
final BasicJavaType<?> domainJtd = (BasicJavaType<?>) jpaAttributeConverter.getDomainJavaType(); private <T> AttributeConverterTypeAdapter<T> buildAttributeConverterTypeAdapter(
JpaAttributeConverter<T, ?> jpaAttributeConverter) {
JavaType<T> domainJavaType = jpaAttributeConverter.getDomainJavaType();
JavaType<?> relationalJavaType = jpaAttributeConverter.getRelationalJavaType();
// build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Going back to the illustration, this should be a SqlTypeDescriptor that handles the Integer <-> String // 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 // 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 // of ResultSets). See JdbcTypeJavaClassMappings for details. Again, given example, this should return
// VARCHAR/CHAR // VARCHAR/CHAR
final JdbcType recommendedJdbcType = jpaAttributeConverter.getRelationalJavaType().getRecommendedJdbcType( final JdbcType recommendedJdbcType = relationalJavaType.getRecommendedJdbcType(
// todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods // todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods
new JdbcTypeIndicators() { new JdbcTypeIndicators() {
@Override @Override
@ -774,7 +777,7 @@ public abstract class SimpleValue implements KeyValue {
jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode ); jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping( jdbcTypeCode );
} }
else { else {
if ( Serializable.class.isAssignableFrom( domainJtd.getJavaTypeClass() ) ) { if ( Serializable.class.isAssignableFrom( domainJavaType.getJavaTypeClass() ) ) {
jdbcTypeCode = Types.BLOB; jdbcTypeCode = Types.BLOB;
} }
else { else {
@ -793,33 +796,26 @@ public abstract class SimpleValue implements KeyValue {
jdbcTypeCode = NationalizedTypeMappings.toNationalizedTypeCode( jdbcTypeCode ); 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. // 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<>( return new AttributeConverterTypeAdapter<>(
name, ConverterDescriptor.TYPE_NAME_PREFIX
description, + jpaAttributeConverter.getConverterJavaType().getJavaType().getTypeName(),
String.format(
"BasicType adapter for AttributeConverter<%s,%s>",
domainJavaType.getJavaType().getTypeName(),
relationalJavaType.getJavaType().getTypeName()
),
jpaAttributeConverter, jpaAttributeConverter,
jdbcTypeAdapter, // and finally construct the adapter, which injects the AttributeConverter
jpaAttributeConverter.getRelationalJavaType(), // calls into the binding/extraction process...
jpaAttributeConverter.getDomainJavaType(), new AttributeConverterJdbcTypeAdapter(
jpaAttributeConverter,
metadata.getTypeConfiguration().getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ),
relationalJavaType
),
relationalJavaType,
domainJavaType,
null null
); );
} }

View File

@ -215,7 +215,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
final MutabilityPlan<?> mutabilityPlan; final MutabilityPlan<?> mutabilityPlan;
if ( updateable ) { if ( updateable ) {
mutabilityPlan = new MutabilityPlan<Object>() { mutabilityPlan = new MutabilityPlan<>() {
@Override @Override
public boolean isMutable() { public boolean isMutable() {
return true; return true;

View File

@ -184,7 +184,7 @@ public class MappingModelCreationHelper {
final Value value = bootProperty.getValue(); final Value value = bootProperty.getValue();
final BasicValue.Resolution<?> resolution = ( (Resolvable) value ).resolve(); final BasicValue.Resolution<?> resolution = ( (Resolvable) value ).resolve();
final BasicValueConverter valueConverter = resolution.getValueConverter(); final BasicValueConverter<?,?> valueConverter = resolution.getValueConverter();
final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() { final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() {
private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan(); 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 // we want to "decompose" the "type" into its various pieces as expected by the mapping
assert valueConverter.getRelationalJavaType() == resolution.getRelationalJavaType(); assert valueConverter.getRelationalJavaType() == resolution.getRelationalJavaType();
//noinspection unchecked
final BasicType<?> mappingBasicType = creationProcess.getCreationContext() final BasicType<?> mappingBasicType = creationProcess.getCreationContext()
.getDomainModel() .getDomainModel()
.getTypeConfiguration() .getTypeConfiguration()

View File

@ -4000,10 +4000,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
} }
else { else {
final MappingModelExpressible<?> elementExpressible = getElementExpressible( localExpressible ); final MappingModelExpressible<?> elementExpressible = getElementExpressible( localExpressible );
if ( elementExpressible instanceof BasicType<?> ) { if ( elementExpressible instanceof BasicType ) {
expressible = InferredBasicValueResolver.resolveSqlTypeIndicators( expressible = InferredBasicValueResolver.resolveSqlTypeIndicators(
this, this,
(BasicType<?>) elementExpressible, (BasicType) elementExpressible,
literal.getJavaTypeDescriptor() literal.getJavaTypeDescriptor()
); );
} }
@ -4080,21 +4080,16 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
} }
} }
else { else {
if ( literal instanceof SqmLiteral ) { return new QueryLiteral<>(
return new QueryLiteral<>( literal.getLiteralValue(),
literal.getLiteralValue(), creationContext.getSessionFactory()
creationContext.getSessionFactory() .getTypeConfiguration()
.getTypeConfiguration() .getBasicTypeRegistry()
.getBasicTypeRegistry() .getRegisteredType(
.getRegisteredType( ( (BasicSqmPathSource<?>) literal.getNodeType() ).getSqmPathType()
( (BasicSqmPathSource) literal.getNodeType() ).getSqmPathType() .getJavaType()
.getJavaType() .getName()
.getName() )
)
);
}
throw new NotYetImplementedFor6Exception(
expressible == null ? literal.getLiteralValue().getClass() : expressible.getClass()
); );
} }
} }
@ -4613,10 +4608,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override @Override
public Object visitCastTarget(SqmCastTarget<?> target) { public Object visitCastTarget(SqmCastTarget<?> target) {
BasicValuedMapping targetType = (BasicValuedMapping) target.getType(); BasicValuedMapping targetType = (BasicValuedMapping) target.getType();
if ( targetType instanceof BasicType<?> ) { if ( targetType instanceof BasicType ) {
targetType = InferredBasicValueResolver.resolveSqlTypeIndicators( targetType = InferredBasicValueResolver.resolveSqlTypeIndicators(
this, this,
(BasicType<?>) targetType, (BasicType) targetType,
target.getNodeJavaType() target.getNodeJavaType()
); );
} }
@ -5320,7 +5315,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
final BasicValuedMapping inferrableType = (BasicValuedMapping) resolveInferredType(); final BasicValuedMapping inferrableType = (BasicValuedMapping) resolveInferredType();
if ( inferrableType instanceof ConvertibleModelPart ) { if ( inferrableType instanceof ConvertibleModelPart ) {
final ConvertibleModelPart inferredPart = (ConvertibleModelPart) inferrableType; final ConvertibleModelPart inferredPart = (ConvertibleModelPart) inferrableType;
@SuppressWarnings("unchecked")
final BasicValueConverter<Enum<?>,?> valueConverter = inferredPart.getValueConverter(); final BasicValueConverter<Enum<?>,?> valueConverter = inferredPart.getValueConverter();
final Object jdbcValue = valueConverter.toRelationalValue( sqmEnumLiteral.getEnumValue() ); final Object jdbcValue = valueConverter.toRelationalValue( sqmEnumLiteral.getEnumValue() );
return new QueryLiteral<>( jdbcValue, inferredPart ); return new QueryLiteral<>( jdbcValue, inferredPart );
@ -5335,7 +5329,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
return new ConvertedQueryLiteral( return new ConvertedQueryLiteral(
sqmEnumLiteral.getEnumValue(), sqmEnumLiteral.getEnumValue(),
new OrdinalEnumValueConverter( enumJtd, jdbcType, relationalJtd ), new OrdinalEnumValueConverter<>( enumJtd, jdbcType, relationalJtd ),
jdbcMappingType jdbcMappingType
); );
} }

View File

@ -35,9 +35,8 @@ public abstract class AbstractClassJavaType<T> implements BasicJavaType<T>, Seri
* *
* @see #AbstractClassJavaType(Class, MutabilityPlan) * @see #AbstractClassJavaType(Class, MutabilityPlan)
*/ */
@SuppressWarnings({ "unchecked" })
protected AbstractClassJavaType(Class<? extends T> type) { protected AbstractClassJavaType(Class<? extends T> type) {
this( type, (MutabilityPlan<T>) ImmutableMutabilityPlan.INSTANCE ); this( type, ImmutableMutabilityPlan.instance() );
} }
/** /**

View File

@ -36,9 +36,8 @@ public abstract class AbstractJavaType<T> implements BasicJavaType<T>, Serializa
* *
* @see #AbstractJavaType(Type, MutabilityPlan) * @see #AbstractJavaType(Type, MutabilityPlan)
*/ */
@SuppressWarnings({ "unchecked" })
protected AbstractJavaType(Type type) { protected AbstractJavaType(Type type) {
this( type, (MutabilityPlan<T>) ImmutableMutabilityPlan.INSTANCE ); this( type, ImmutableMutabilityPlan.instance() );
} }
/** /**
@ -47,7 +46,7 @@ public abstract class AbstractJavaType<T> implements BasicJavaType<T>, Serializa
* @param type The Java type. * @param type The Java type.
* @param mutabilityPlan The plan for handling mutability aspects of the java type. * @param mutabilityPlan The plan for handling mutability aspects of the java type.
*/ */
@SuppressWarnings({ "unchecked" }) @SuppressWarnings("unchecked")
protected AbstractJavaType(Type type, MutabilityPlan<T> mutabilityPlan) { protected AbstractJavaType(Type type, MutabilityPlan<T> mutabilityPlan) {
this.type = type; this.type = type;
this.mutabilityPlan = mutabilityPlan; this.mutabilityPlan = mutabilityPlan;
@ -86,13 +85,13 @@ public abstract class AbstractJavaType<T> implements BasicJavaType<T>, Serializa
return (value == null) ? "null" : value.toString(); return (value == null) ? "null" : value.toString();
} }
protected HibernateException unknownUnwrap(Class conversionType) { protected HibernateException unknownUnwrap(Class<?> conversionType) {
throw new HibernateException( throw new HibernateException(
"Unknown unwrap conversion requested: " + type.getTypeName() + " to " + conversionType.getName() "Unknown unwrap conversion requested: " + type.getTypeName() + " to " + conversionType.getName()
); );
} }
protected HibernateException unknownWrap(Class conversionType) { protected HibernateException unknownWrap(Class<?> conversionType) {
throw new HibernateException( throw new HibernateException(
"Unknown wrap conversion requested: " + conversionType.getName() + " to " + type.getTypeName() "Unknown wrap conversion requested: " + conversionType.getName() + " to " + type.getTypeName()
); );

View File

@ -38,9 +38,8 @@ public class DurationJavaType extends AbstractClassJavaType<Duration> {
*/ */
public static final DurationJavaType INSTANCE = new DurationJavaType(); public static final DurationJavaType INSTANCE = new DurationJavaType();
@SuppressWarnings("unchecked")
public DurationJavaType() { public DurationJavaType() {
super( Duration.class, ImmutableMutabilityPlan.INSTANCE ); super( Duration.class, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -21,9 +21,8 @@ import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class EnumJavaType<T extends Enum<T>> extends AbstractClassJavaType<T> { public class EnumJavaType<T extends Enum<T>> extends AbstractClassJavaType<T> {
@SuppressWarnings("unchecked")
public EnumJavaType(Class<T> type) { public EnumJavaType(Class<T> type) {
super( type, ImmutableMutabilityPlan.INSTANCE ); super( type, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -38,9 +38,8 @@ public class InstantJavaType extends AbstractTemporalJavaType<Instant>
*/ */
public static final InstantJavaType INSTANCE = new InstantJavaType(); public static final InstantJavaType INSTANCE = new InstantJavaType();
@SuppressWarnings("unchecked")
public InstantJavaType() { public InstantJavaType() {
super( Instant.class, ImmutableMutabilityPlan.INSTANCE ); super( Instant.class, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -59,9 +59,8 @@ public interface JavaType<T> extends Serializable {
/** /**
* Retrieve the mutability plan for this Java type. * Retrieve the mutability plan for this Java type.
*/ */
@SuppressWarnings("unchecked")
default MutabilityPlan<T> getMutabilityPlan() { default MutabilityPlan<T> getMutabilityPlan() {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
default T getReplacement(T original, T target, SharedSessionContractImplementor session) { default T getReplacement(T original, T target, SharedSessionContractImplementor session) {

View File

@ -36,9 +36,8 @@ public class LocalDateJavaType extends AbstractTemporalJavaType<LocalDate> {
*/ */
public static final LocalDateJavaType INSTANCE = new LocalDateJavaType(); public static final LocalDateJavaType INSTANCE = new LocalDateJavaType();
@SuppressWarnings("unchecked")
public LocalDateJavaType() { public LocalDateJavaType() {
super( LocalDate.class, ImmutableMutabilityPlan.INSTANCE ); super( LocalDate.class, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -37,9 +37,8 @@ public class LocalDateTimeJavaType extends AbstractTemporalJavaType<LocalDateTim
*/ */
public static final LocalDateTimeJavaType INSTANCE = new LocalDateTimeJavaType(); public static final LocalDateTimeJavaType INSTANCE = new LocalDateTimeJavaType();
@SuppressWarnings("unchecked")
public LocalDateTimeJavaType() { public LocalDateTimeJavaType() {
super( LocalDateTime.class, ImmutableMutabilityPlan.INSTANCE ); super( LocalDateTime.class, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -39,9 +39,8 @@ public class LocalTimeJavaType extends AbstractTemporalJavaType<LocalTime> {
*/ */
public static final LocalTimeJavaType INSTANCE = new LocalTimeJavaType(); public static final LocalTimeJavaType INSTANCE = new LocalTimeJavaType();
@SuppressWarnings("unchecked")
public LocalTimeJavaType() { public LocalTimeJavaType() {
super( LocalTime.class, ImmutableMutabilityPlan.INSTANCE ); super( LocalTime.class, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -28,7 +28,7 @@ public class LocaleJavaType extends AbstractClassJavaType<Locale> {
} }
public LocaleJavaType() { public LocaleJavaType() {
super( Locale.class, ImmutableMutabilityPlan.INSTANCE, LocaleComparator.INSTANCE ); super( Locale.class, ImmutableMutabilityPlan.instance(), LocaleComparator.INSTANCE );
} }
public String toString(Locale value) { public String toString(Locale value) {

View File

@ -15,15 +15,15 @@ import org.hibernate.type.descriptor.WrapperOptions;
*/ */
public class ObjectArrayJavaType extends AbstractClassJavaType<Object[]> { public class ObjectArrayJavaType extends AbstractClassJavaType<Object[]> {
private final JavaType<Object>[] components; private final JavaType[] components;
public ObjectArrayJavaType(JavaType<?>[] components) { public ObjectArrayJavaType(JavaType[] components) {
super( super(
Object[].class, Object[].class,
ImmutableMutabilityPlan.INSTANCE, ImmutableMutabilityPlan.instance(),
new ComponentArrayComparator( (JavaType<Object>[]) components ) new ComponentArrayComparator( components )
); );
this.components = (JavaType<Object>[]) components; this.components = components;
} }
@Override @Override

View File

@ -40,9 +40,8 @@ public class OffsetDateTimeJavaType extends AbstractTemporalJavaType<OffsetDateT
*/ */
public static final OffsetDateTimeJavaType INSTANCE = new OffsetDateTimeJavaType(); public static final OffsetDateTimeJavaType INSTANCE = new OffsetDateTimeJavaType();
@SuppressWarnings("unchecked")
public OffsetDateTimeJavaType() { public OffsetDateTimeJavaType() {
super( OffsetDateTime.class, ImmutableMutabilityPlan.INSTANCE, OffsetDateTime.timeLineOrder() ); super( OffsetDateTime.class, ImmutableMutabilityPlan.instance(), OffsetDateTime.timeLineOrder() );
} }
@Override @Override

View File

@ -39,9 +39,8 @@ public class OffsetTimeJavaType extends AbstractTemporalJavaType<OffsetTime> {
*/ */
public static final OffsetTimeJavaType INSTANCE = new OffsetTimeJavaType(); public static final OffsetTimeJavaType INSTANCE = new OffsetTimeJavaType();
@SuppressWarnings("unchecked")
public OffsetTimeJavaType() { public OffsetTimeJavaType() {
super( OffsetTime.class, ImmutableMutabilityPlan.INSTANCE ); super( OffsetTime.class, ImmutableMutabilityPlan.instance() );
} }
@Override @Override

View File

@ -54,10 +54,9 @@ public class SerializableJavaType<T extends Serializable> extends AbstractClassJ
super( type, mutabilityPlan == null ? createMutabilityPlan( type ) : mutabilityPlan ); super( type, mutabilityPlan == null ? createMutabilityPlan( type ) : mutabilityPlan );
} }
@SuppressWarnings({ "unchecked" })
private static <T> MutabilityPlan<T> createMutabilityPlan(Class<T> type) { private static <T> MutabilityPlan<T> createMutabilityPlan(Class<T> type) {
if ( type.isAnnotationPresent( Immutable.class ) ) { if ( type.isAnnotationPresent( Immutable.class ) ) {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
return (MutabilityPlan<T>) SerializableMutabilityPlan.INSTANCE; return (MutabilityPlan<T>) SerializableMutabilityPlan.INSTANCE;
} }

View File

@ -28,7 +28,7 @@ public class TimeZoneJavaType extends AbstractClassJavaType<TimeZone> {
} }
public TimeZoneJavaType() { public TimeZoneJavaType() {
super( TimeZone.class, ImmutableMutabilityPlan.INSTANCE, TimeZoneComparator.INSTANCE ); super( TimeZone.class, ImmutableMutabilityPlan.instance(), TimeZoneComparator.INSTANCE );
} }
public String toString(TimeZone value) { public String toString(TimeZone value) {

View File

@ -31,7 +31,7 @@ public class ZoneOffsetJavaType extends AbstractClassJavaType<ZoneOffset> {
} }
public ZoneOffsetJavaType() { public ZoneOffsetJavaType() {
super( ZoneOffset.class, ImmutableMutabilityPlan.INSTANCE, ZoneOffsetComparator.INSTANCE ); super( ZoneOffset.class, ImmutableMutabilityPlan.instance(), ZoneOffsetComparator.INSTANCE );
} }
public String toString(ZoneOffset value) { public String toString(ZoneOffset value) {

View File

@ -40,9 +40,8 @@ public class ZonedDateTimeJavaType extends AbstractTemporalJavaType<ZonedDateTim
*/ */
public static final ZonedDateTimeJavaType INSTANCE = new ZonedDateTimeJavaType(); public static final ZonedDateTimeJavaType INSTANCE = new ZonedDateTimeJavaType();
@SuppressWarnings("unchecked")
public ZonedDateTimeJavaType() { public ZonedDateTimeJavaType() {
super( ZonedDateTime.class, ImmutableMutabilityPlan.INSTANCE, ZonedDateTimeComparator.INSTANCE ); super( ZonedDateTime.class, ImmutableMutabilityPlan.instance(), ZonedDateTimeComparator.INSTANCE );
} }
@Override @Override

View File

@ -52,12 +52,11 @@ public class RegistryHelper {
); );
} }
@SuppressWarnings("unchecked")
public <J> MutabilityPlan<J> determineMutabilityPlan(Type javaType, TypeConfiguration typeConfiguration) { public <J> MutabilityPlan<J> determineMutabilityPlan(Type javaType, TypeConfiguration typeConfiguration) {
final Class<J> javaTypeClass = determineJavaTypeClass( javaType ); final Class<J> javaTypeClass = determineJavaTypeClass( javaType );
if ( javaTypeClass.isAnnotationPresent( Immutable.class ) ) { if ( javaTypeClass.isAnnotationPresent( Immutable.class ) ) {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
if ( javaTypeClass.isAnnotationPresent( Mutability.class ) ) { if ( javaTypeClass.isAnnotationPresent( Mutability.class ) ) {
@ -71,11 +70,11 @@ public class RegistryHelper {
} }
if ( javaTypeClass.isEnum() ) { if ( javaTypeClass.isEnum() ) {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
if ( javaTypeClass.isPrimitive() ) { if ( javaTypeClass.isPrimitive() ) {
return ImmutableMutabilityPlan.INSTANCE; return ImmutableMutabilityPlan.instance();
} }
if ( Serializable.class.isAssignableFrom( javaTypeClass ) ) { if ( Serializable.class.isAssignableFrom( javaTypeClass ) ) {
@ -85,7 +84,6 @@ public class RegistryHelper {
return null; return null;
} }
@SuppressWarnings("unchecked")
private <J> JavaType<J> createTypeDescriptor( private <J> JavaType<J> createTypeDescriptor(
Type javaType, Type javaType,
Function<Class<J>,MutabilityPlan<J>> mutabilityPlanResolver) { Function<Class<J>,MutabilityPlan<J>> mutabilityPlanResolver) {
@ -93,14 +91,14 @@ public class RegistryHelper {
if ( javaTypeClass.isEnum() ) { if ( javaTypeClass.isEnum() ) {
// enums are unequivocally immutable // enums are unequivocally immutable
//noinspection rawtypes //noinspection rawtypes, unchecked
return new EnumJavaType( javaTypeClass ); return new EnumJavaType( javaTypeClass );
} }
final MutabilityPlan<J> plan = mutabilityPlanResolver.apply( javaTypeClass ); final MutabilityPlan<J> plan = mutabilityPlanResolver.apply( javaTypeClass );
if ( Serializable.class.isAssignableFrom( javaTypeClass ) ) { if ( Serializable.class.isAssignableFrom( javaTypeClass ) ) {
//noinspection rawtypes //noinspection rawtypes, unchecked
return new SerializableJavaType( javaTypeClass, plan ); return new SerializableJavaType( javaTypeClass, plan );
} }

View File

@ -27,7 +27,6 @@ public class ImmutableConvertedBasicTypeImpl<J> extends ConvertedBasicTypeImpl<J
@Override @Override
protected MutabilityPlan<J> getMutabilityPlan() { protected MutabilityPlan<J> getMutabilityPlan() {
//noinspection unchecked return ImmutableMutabilityPlan.instance();
return ImmutableMutabilityPlan.INSTANCE;
} }
} }

View File

@ -25,7 +25,6 @@ public class ImmutableNamedBasicTypeImpl<J> extends NamedBasicTypeImpl<J> {
@Override @Override
protected MutabilityPlan<J> getMutabilityPlan() { protected MutabilityPlan<J> getMutabilityPlan() {
//noinspection unchecked return ImmutableMutabilityPlan.instance();
return ImmutableMutabilityPlan.INSTANCE;
} }
} }

View File

@ -89,7 +89,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
@After @After
public void dropTestData() { public void dropTestData() {
inTransaction( inTransaction(
(session) -> session.createQuery( "delete TheEntity" ).executeUpdate() session -> session.createQuery( "delete TheEntity" ).executeUpdate()
); );
} }
@ -320,8 +320,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
@Override @Override
public MutabilityPlan<PseudoMutableState> getMutabilityPlan() { public MutabilityPlan<PseudoMutableState> getMutabilityPlan() {
//noinspection unchecked return ImmutableMutabilityPlan.instance();
return ImmutableMutabilityPlan.INSTANCE;
} }
@Override @Override