Interface JavaType<T>
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
BasicJavaType<T>,PrimitiveJavaType<J>,TemporalJavaType<T>,VersionJavaType<T>
- All Known Implementing Classes:
AbstractArrayJavaType,AbstractClassJavaType,AbstractJavaType,AbstractTemporalJavaType,ArrayJavaType,BasicCollectionJavaType,BigDecimalJavaType,BigIntegerJavaType,BlobJavaType,BooleanJavaType,BooleanPrimitiveArrayJavaType,ByteArrayJavaType,ByteJavaType,CalendarDateJavaType,CalendarJavaType,CalendarTimeJavaType,CharacterArrayJavaType,CharacterJavaType,ClassJavaType,ClobJavaType,CollectionJavaType,CompositeUserTypeJavaTypeWrapper,CurrencyJavaType,DateJavaType,DoubleJavaType,DoublePrimitiveArrayJavaType,DurationJavaType,DynamicModelJavaType,EmbeddableAggregateJavaType,EntityJavaType,EnumJavaType,FloatJavaType,FloatPrimitiveArrayJavaType,FormatMapperBasedJavaType,GeolatteGeometryJavaType,InetAddressJavaType,InstantJavaType,IntegerJavaType,IntegerPrimitiveArrayJavaType,JavaTypeBasicAdaptor,JdbcDateJavaType,JdbcTimeJavaType,JdbcTimestampJavaType,JsonJavaType,JTSGeometryJavaType,LocalDateJavaType,LocalDateTimeJavaType,LocaleJavaType,LocalTimeJavaType,LongJavaType,LongPrimitiveArrayJavaType,MapEntryJavaType,NClobJavaType,ObjectArrayJavaType,ObjectJavaType,OffsetDateTimeJavaType,OffsetTimeJavaType,PrimitiveByteArrayJavaType,PrimitiveCharacterArrayJavaType,RowVersionJavaType,SerializableJavaType,ShortJavaType,ShortPrimitiveArrayJavaType,StringJavaType,TimeZoneJavaType,UnknownBasicJavaType,UrlJavaType,UserTypeJavaTypeWrapper,UserTypeVersionJavaTypeWrapper,UUIDJavaType,XmlJavaType,YearJavaType,ZonedDateTimeJavaType,ZoneIdJavaType,ZoneOffsetJavaType
public interfaceJavaType<T>extendsSerializable
Descriptor for the Java side of a value mapping. AJavaTypeis always coupled with aJdbcTypeto describe the typing aspects of an attribute mapping from Java to JDBC.An instance of this interface represents a certainJava class or interface which may occur as the type of a persistent property or field of an entity class.
A
JavaTypedecides how instances of the Java type are compared forequality andorder, and it knows how to convertto andfrom various different representations that might be requested by its partnerJdbcType.Every
JavaTypehas aMutabilityPlanwhich defines how instances of the type arecloned, and how they aredisassembled to andassembled from their representation in thesecond-level cache.Even though it's strictly only responsible for Java aspects of the mapping, a
JavaTypeusually does come with arecommendation for a friendlyJdbcTypeit works particularly well with, along with a defaultlength,precision, andscale for mapped columns.A Java type may be selected when mapping an entity attribute using the
JavaTypeannotation, though this is typically unnecessary.Custom implementations should be registered with the
JavaTypeRegistryat startup. The built-in implementations are registered automatically.- See Also:
JdbcType
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceJavaType.CoercionContext
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default voidappendEncodedString(SqlAppender sb,T value)Appends the value to the SqlAppender in an encoded format that can be decoded again byfromEncodedString(CharSequence, int, int).default booleanareEqual(T one,T another)Determine if two instances are equaldefault <X> Tcoerce(X value,JavaType.CoercionContext coercionContext)defaultJavaType<T>createJavaType(ParameterizedType parameterizedType)Deprecated.defaultJavaType<T>createJavaType(ParameterizedType parameterizedType,TypeConfiguration typeConfiguration)Creates theJavaTypefor the givenParameterizedTypebased on thisJavaTyperegistered for the raw type.default intextractHashCode(T value)Extract a proper hash code for the given value.defaultStringextractLoggableRepresentation(@NullableT value)Extract a loggable representation of the given value.defaultTfromEncodedString(CharSequence charSequence, int start, int end)Reads the encoded value from the char sequence start index until the end index and returns the decoded value.TfromString(CharSequence string)defaultStringgetCheckCondition(String columnName,JdbcType jdbcType,BasicValueConverter<?,?> converter,Dialect dialect)The check constraint that should be added to the column definition in generated DDL.defaultComparator<T>getComparator()Retrieve the natural comparator for this type.default longgetDefaultSqlLength(Dialect dialect,JdbcType jdbcType)The default column length when this Java type is mapped to a SQL data type which is parametrized by length, for exampleTypes.VARCHAR.default intgetDefaultSqlPrecision(Dialect dialect,JdbcType jdbcType)The default column precision when this Java type is mapped to a SQL data type which is parametrized by precision, for exampleTypes.DECIMAL.default intgetDefaultSqlScale(Dialect dialect,JdbcType jdbcType)The default column scale when this Java type is mapped to a SQL data type which is parametrized by scale, for exampleTypes.DECIMAL.defaultTgetDefaultValue()Get this Java type's default value.defaultTypegetJavaType()Get the Java type (aTypeobject) described by thisJavaType.defaultClass<T>getJavaTypeClass()Get the Java type (theClassobject) described by thisJavaType.default longgetLongSqlLength()The default column length when this Java type is mapped to a column of typeTypes.LONGVARCHARorTypes.LONGVARBINARY.defaultMutabilityPlan<T>getMutabilityPlan()Retrieve themutability plan for this Java type.JdbcTypegetRecommendedJdbcType(JdbcTypeIndicators context)Obtain the "recommended"SQL type descriptorfor this Java type.defaultTgetReplacement(T original,T target,SharedSessionContractImplementor session)defaultStringgetTypeName()Get the name of the Java type.default booleanisInstance(Object value)Is the given value an instance of the described type?default booleanisTemporalType()Return true if the implementation is an instance ofTemporalJavaTypedefault booleanisWider(JavaType<?> javaType)Determines if this Java type is wider than the given Java type, that is, if the given type can be safely widened to this type.defaultStringtoString(T value)<X> Xunwrap(T value,Class<X> type,WrapperOptions options)Unwrap an instance of our handled Java type into the requested type.default booleanuseObjectEqualsHashCode()Whether to useObject.equals(Object)andObject.hashCode()orareEqual(Object, Object)andextractHashCode(Object)for objects of this java type.<X> Twrap(X value,WrapperOptions options)Wrap a value as our handled Java type.
Method Detail
getJavaType
default Type getJavaType()
Get the Java type (aTypeobject) described by thisJavaType.- See Also:
getJavaTypeClass()
getJavaTypeClass
default Class<T> getJavaTypeClass()
Get the Java type (theClassobject) described by thisJavaType.- See Also:
getJavaType()
getTypeName
default String getTypeName()
Get the name of the Java type.
isInstance
default boolean isInstance(Object value)
Is the given value an instance of the described type?Usually just
getJavaTypeClass().isInstance(value), but some descriptors need specialized semantics, for example, the descriptors forjava.sql.Date,java.sql.Time, andjava.sql.Timestamp.
getMutabilityPlan
default MutabilityPlan<T> getMutabilityPlan()
Retrieve themutability plan for this Java type.
getReplacement
default T getReplacement(T original,T target,SharedSessionContractImplementor session)
getDefaultValue
default T getDefaultValue()
Get this Java type's default value.- Returns:
- The default value.
getRecommendedJdbcType
JdbcType getRecommendedJdbcType(JdbcTypeIndicators context)
Obtain the "recommended"SQL type descriptorfor this Java type. Often, but not always, the source of this recommendation is the JDBC specification.- Parameters:
context- Contextual information- Returns:
- The recommended SQL type descriptor
getDefaultSqlLength
default long getDefaultSqlLength(Dialect dialect,JdbcType jdbcType)
The default column length when this Java type is mapped to a SQL data type which is parametrized by length, for exampleTypes.VARCHAR.- Returns:
Size.DEFAULT_LENGTHunless overridden
getLongSqlLength
default long getLongSqlLength()
The default column length when this Java type is mapped to a column of typeTypes.LONGVARCHARorTypes.LONGVARBINARY.- Returns:
Size.LONG_LENGTHunless overridden
getDefaultSqlPrecision
default int getDefaultSqlPrecision(Dialect dialect,JdbcType jdbcType)
The default column precision when this Java type is mapped to a SQL data type which is parametrized by precision, for exampleTypes.DECIMAL.- Returns:
Size.DEFAULT_PRECISIONunless overridden
getDefaultSqlScale
default int getDefaultSqlScale(Dialect dialect,JdbcType jdbcType)
The default column scale when this Java type is mapped to a SQL data type which is parametrized by scale, for exampleTypes.DECIMAL.- Returns:
Size.DEFAULT_SCALEunless overridden
getComparator
default Comparator<T> getComparator()
Retrieve the natural comparator for this type.
extractHashCode
default int extractHashCode(T value)
Extract a proper hash code for the given value.- Parameters:
value- The value for which to extract a hash code.- Returns:
- The extracted hash code.
areEqual
default boolean areEqual(T one,T another)
Determine if two instances are equal- Parameters:
one- One instanceanother- The other instance- Returns:
- True if the two are considered equal; false otherwise.
useObjectEqualsHashCode
default boolean useObjectEqualsHashCode()
Whether to useObject.equals(Object)andObject.hashCode()orareEqual(Object, Object)andextractHashCode(Object)for objects of this java type. This is useful to avoid mega-morphic callsites.
extractLoggableRepresentation
default String extractLoggableRepresentation(@NullableT value)
Extract a loggable representation of the given value.- Parameters:
value- The value for which to extract a loggable representation.- Returns:
- The loggable representation
fromString
T fromString(CharSequence string)
appendEncodedString
default void appendEncodedString(SqlAppender sb,T value)
Appends the value to the SqlAppender in an encoded format that can be decoded again byfromEncodedString(CharSequence, int, int). Implementers do not need to care about escaping. This is similar totoString(Object), with the difference that the aim of this method is encoding to the appender.- Since:
- 6.2
fromEncodedString
default T fromEncodedString(CharSequence charSequence, int start, int end)
Reads the encoded value from the char sequence start index until the end index and returns the decoded value. Implementers do not need to care about escaping. This is similar tofromString(CharSequence), with the difference that the aim of this method is decoding from a range within an existing char sequence.- Since:
- 6.2
unwrap
<X> X unwrap(T value,Class<X> type,WrapperOptions options)
Unwrap an instance of our handled Java type into the requested type.As an example, if this is a
JavaType<Integer>and we are asked to unwrap theInteger valueas aLong, we would return something likeLong.valueOf( value.longValue() ).Intended use is during
PreparedStatementbinding.- Type Parameters:
X- The conversion type.- Parameters:
value- The value to unwraptype- The type as which to unwrapoptions- The options- Returns:
- The unwrapped value.
wrap
<X> T wrap(X value,WrapperOptions options)
Wrap a value as our handled Java type.Intended use is during
ResultSetextraction.- Type Parameters:
X- The conversion type.- Parameters:
value- The value to wrap.options- The options- Returns:
- The wrapped value.
isWider
default boolean isWider(JavaType<?> javaType)
Determines if this Java type is wider than the given Java type, that is, if the given type can be safely widened to this type.
coerce
default <X> T coerce(X value,JavaType.CoercionContext coercionContext)
createJavaType
@Deprecated(since="6.1")default JavaType<T> createJavaType(ParameterizedType parameterizedType)
Deprecated.Creates theJavaTypefor the givenParameterizedTypebased on thisJavaTyperegistered for the raw type.
createJavaType
@Incubatingdefault JavaType<T> createJavaType(ParameterizedType parameterizedType,TypeConfiguration typeConfiguration)
Creates theJavaTypefor the givenParameterizedTypebased on thisJavaTyperegistered for the raw type.- Since:
- 6.1
isTemporalType
default boolean isTemporalType()
Return true if the implementation is an instance ofTemporalJavaType- Returns:
- true if it is an instance of
TemporalJavaType; false otherwise
getCheckCondition
@Incubatingdefault String getCheckCondition(String columnName,JdbcType jdbcType,BasicValueConverter<?,?> converter,Dialect dialect)
The check constraint that should be added to the column definition in generated DDL.