Package org.hibernate.type
Class EnumType<T extends Enum<T>>
- java.lang.Object
-
- org.hibernate.type.EnumType<T>
-
- All Implemented Interfaces:
Serializable
,TypeConfigurationAware
,DynamicParameterizedType
,EnhancedUserType<T>
,LoggableUserType
,ParameterizedType
,UserType<T>
public class EnumType<T extends Enum<T>> extends Object implements EnhancedUserType<T>, DynamicParameterizedType, LoggableUserType, TypeConfigurationAware, Serializable
Value type mapper for enumerations. Provides 2 distinct forms of "configuration" - one for hbm.xml mapping and another for annotation/orm.xml mapping triggered within thesetParameterValues(java.util.Properties)
method Annotation based config relies on aDynamicParameterizedType.ParameterType
reference passed as an entry in the parameter values under the keyDynamicParameterizedType.PARAMETER_TYPE
hbm.xml based config relies on a number of values from the parameters:- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.hibernate.usertype.DynamicParameterizedType
DynamicParameterizedType.ParameterType
-
-
Field Summary
Fields Modifier and Type Field Description static String
ENUM
static String
NAMED
static String
TYPE
-
Fields inherited from interface org.hibernate.usertype.DynamicParameterizedType
ACCESS_TYPE, ENTITY, IS_DYNAMIC, IS_PRIMARY_KEY, PARAMETER_TYPE, PROPERTY, RETURNED_CLASS, XPROPERTY
-
-
Constructor Summary
Constructors Constructor Description EnumType()
EnumType(Class<T> enumClass, EnumValueConverter enumValueConverter, TypeConfiguration typeConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
assemble(Serializable cached, Object owner)
Reconstruct an object from the cacheable representation.T
deepCopy(T value)
Return a deep copy of the persistent state, stopping at entities and at collections.Serializable
disassemble(T value)
Transform the object into its cacheable representation.boolean
equals(T x, T y)
Compare two instances of the class mapped by this type for persistence "equality".T
fromStringValue(CharSequence sequence)
Consume the given string representation back into this types java form.EnumValueConverter
getEnumValueConverter()
JdbcType
getJdbcType(TypeConfiguration typeConfiguration)
int
getSqlType()
Return the SQL type code for the column mapped by this type.TypeConfiguration
getTypeConfiguration()
BasicValueConverter<T,Object>
getValueConverter()
Returns the converter that this user type uses for transforming from the domain type, to the relational type, ornull
if there is no conversion.int
hashCode(T x)
Get a hashcode for the instance, consistent with persistence "equality"boolean
isMutable()
Are objects of this type mutable?boolean
isOrdinal()
T
nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.void
nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session)
Write an instance of the mapped class to a prepared statement.T
replace(T original, T target, Object owner)
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging.Class<T>
returnedClass()
The class returned bynullSafeGet()
.void
setParameterValues(Properties parameters)
Gets called by Hibernate to pass the configured type parameters to the implementation.void
setTypeConfiguration(TypeConfiguration typeConfiguration)
String
toLoggableString(Object value, SessionFactoryImplementor factory)
Generate a loggable string representation of the collection (value).String
toSqlLiteral(T value)
Return an SQL literal representation of the valueString
toString(T value)
Render the value to the string representation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.usertype.UserType
getDefaultSqlLength, getDefaultSqlPrecision, getDefaultSqlScale
-
-
-
-
Field Detail
-
ENUM
public static final String ENUM
- See Also:
- Constant Field Values
-
NAMED
public static final String NAMED
- See Also:
- Constant Field Values
-
TYPE
public static final String TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EnumType
public EnumType()
-
EnumType
public EnumType(Class<T> enumClass, EnumValueConverter enumValueConverter, TypeConfiguration typeConfiguration)
-
-
Method Detail
-
getEnumValueConverter
public EnumValueConverter getEnumValueConverter()
-
getJdbcType
public JdbcType getJdbcType(TypeConfiguration typeConfiguration)
- Specified by:
getJdbcType
in interfaceUserType<T extends Enum<T>>
-
getValueConverter
public BasicValueConverter<T,Object> getValueConverter()
Description copied from interface:UserType
Returns the converter that this user type uses for transforming from the domain type, to the relational type, ornull
if there is no conversion. Note that it is vital to provide a converter if a column should be mapped to multiple domain types, as Hibernate will only select a column once and materialize values asJdbcMapping.getJdbcJavaType()
. Support for multiple domain type representations works by converting objects of that type to the domain type.- Specified by:
getValueConverter
in interfaceUserType<T extends Enum<T>>
-
setParameterValues
public void setParameterValues(Properties parameters)
Description copied from interface:ParameterizedType
Gets called by Hibernate to pass the configured type parameters to the implementation.- Specified by:
setParameterValues
in interfaceParameterizedType
-
getSqlType
public int getSqlType()
Description copied from interface:UserType
Return the SQL type code for the column mapped by this type. The codes are generally defined onorg.hibernate.type.SqlTypes
, but could be database-specific codes
-
returnedClass
public Class<T> returnedClass()
Description copied from interface:UserType
The class returned bynullSafeGet()
.- Specified by:
returnedClass
in interfaceUserType<T extends Enum<T>>
- Returns:
- Class
-
equals
public boolean equals(T x, T y) throws HibernateException
Description copied from interface:UserType
Compare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.
-
hashCode
public int hashCode(T x) throws HibernateException
Description copied from interface:UserType
Get a hashcode for the instance, consistent with persistence "equality"
-
nullSafeGet
public T nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException
Description copied from interface:UserType
Retrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.- Specified by:
nullSafeGet
in interfaceUserType<T extends Enum<T>>
- Throws:
SQLException
-
nullSafeSet
public void nullSafeSet(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException
Description copied from interface:UserType
Write an instance of the mapped class to a prepared statement. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting fromindex
.- Specified by:
nullSafeSet
in interfaceUserType<T extends Enum<T>>
- Throws:
HibernateException
SQLException
-
deepCopy
public T deepCopy(T value) throws HibernateException
Description copied from interface:UserType
Return a deep copy of the persistent state, stopping at entities and at collections. It is not necessary to copy immutable objects, or null values, in which case it is safe to simply return the argument.
-
isMutable
public boolean isMutable()
Description copied from interface:UserType
Are objects of this type mutable?
-
disassemble
public Serializable disassemble(T value) throws HibernateException
Description copied from interface:UserType
Transform the object into its cacheable representation. At the very least this method should perform a deep copy if the type is mutable. That may not be enough for some implementations, however; for example, associations must be cached as identifier values. (optional operation)- Specified by:
disassemble
in interfaceUserType<T extends Enum<T>>
- Parameters:
value
- the object to be cached- Returns:
- a cacheable representation of the object
- Throws:
HibernateException
-
assemble
public T assemble(Serializable cached, Object owner) throws HibernateException
Description copied from interface:UserType
Reconstruct an object from the cacheable representation. At the very least this method should perform a deep copy if the type is mutable. (optional operation)
-
replace
public T replace(T original, T target, Object owner) throws HibernateException
Description copied from interface:UserType
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.
-
getTypeConfiguration
public TypeConfiguration getTypeConfiguration()
- Specified by:
getTypeConfiguration
in interfaceTypeConfigurationAware
-
setTypeConfiguration
public void setTypeConfiguration(TypeConfiguration typeConfiguration)
- Specified by:
setTypeConfiguration
in interfaceTypeConfigurationAware
-
toSqlLiteral
public String toSqlLiteral(T value)
Description copied from interface:EnhancedUserType
Return an SQL literal representation of the value- Specified by:
toSqlLiteral
in interfaceEnhancedUserType<T extends Enum<T>>
-
toString
public String toString(T value)
Description copied from interface:EnhancedUserType
Render the value to the string representation.- Specified by:
toString
in interfaceEnhancedUserType<T extends Enum<T>>
- Parameters:
value
- The value to render to string.- Returns:
- The string representation
-
fromStringValue
public T fromStringValue(CharSequence sequence)
Description copied from interface:EnhancedUserType
Consume the given string representation back into this types java form.- Specified by:
fromStringValue
in interfaceEnhancedUserType<T extends Enum<T>>
- Parameters:
sequence
- The string representation to be consumed.- Returns:
- The java type representation
-
toLoggableString
public String toLoggableString(Object value, SessionFactoryImplementor factory)
Description copied from interface:LoggableUserType
Generate a loggable string representation of the collection (value).- Specified by:
toLoggableString
in interfaceLoggableUserType
- Parameters:
value
- The collection to be logged; guaranteed to be non-null and initialized.factory
- The factory.- Returns:
- The loggable string representation.
-
isOrdinal
public boolean isOrdinal()
-
-