Package org.hibernate.type
Class EnumType<T extends java.lang.Enum>
- java.lang.Object
-
- org.hibernate.type.EnumType<T>
-
- All Implemented Interfaces:
java.io.Serializable
,TypeConfigurationAware
,DynamicParameterizedType
,EnhancedUserType
,LoggableUserType
,ParameterizedType
,UserType
public class EnumType<T extends java.lang.Enum> extends java.lang.Object implements EnhancedUserType, DynamicParameterizedType, LoggableUserType, TypeConfigurationAware, java.io.Serializable
Value type mapper for enumerations. Generally speaking, the proper configuration is picked up from the annotations associated with the mapped attribute. There are a few configuration parameters understood by this type mapper:- enumClass - Names the enumeration class.
-
useNamed - Should enum be mapped via name. Default is to map as ordinal. Used when
annotations are not used (otherwise
EnumType
is used). - type - Identifies the JDBC type (via type code) to be used for the column.
- 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 java.lang.String
ENUM
static java.lang.String
NAMED
static java.lang.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()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
assemble(java.io.Serializable cached, java.lang.Object owner)
Reconstruct an object from the cacheable representation.java.lang.Object
deepCopy(java.lang.Object value)
Return a deep copy of the persistent state, stopping at entities and at collections.java.io.Serializable
disassemble(java.lang.Object value)
Transform the object into its cacheable representation.boolean
equals(java.lang.Object x, java.lang.Object y)
Compare two instances of the class mapped by this type for persistence "equality".java.lang.Object
fromXMLString(java.lang.String xmlValue)
Parse a string representation of this value, as it appears in an XML documentTypeConfiguration
getTypeConfiguration()
int
hashCode(java.lang.Object x)
Get a hashcode for the instance, consistent with persistence "equality"boolean
isMutable()
Are objects of this type mutable?boolean
isOrdinal()
java.lang.Object
nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, SharedSessionContractImplementor session, java.lang.Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.void
nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, SharedSessionContractImplementor session)
Write an instance of the mapped class to a prepared statement.java.lang.String
objectToSQLString(java.lang.Object value)
Return an SQL literal representation of the valuejava.lang.Object
replace(java.lang.Object original, java.lang.Object target, java.lang.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.java.lang.Class<? extends java.lang.Enum>
returnedClass()
The class returned by nullSafeGet().void
setParameterValues(java.util.Properties parameters)
Gets called by Hibernate to pass the configured type parameters to the implementation.void
setTypeConfiguration(TypeConfiguration typeConfiguration)
int[]
sqlTypes()
Return the SQL type codes for the columns mapped by this type.java.lang.String
toLoggableString(java.lang.Object value, SessionFactoryImplementor factory)
Generate a loggable string representation of the collection (value).java.lang.String
toXMLString(java.lang.Object value)
Return a string representation of this value, as it should appear in an XML document
-
-
-
Field Detail
-
ENUM
public static final java.lang.String ENUM
- See Also:
- Constant Field Values
-
NAMED
public static final java.lang.String NAMED
- See Also:
- Constant Field Values
-
TYPE
public static final java.lang.String TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
setParameterValues
public void setParameterValues(java.util.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
-
sqlTypes
public int[] sqlTypes()
Description copied from interface:UserType
Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.
-
returnedClass
public java.lang.Class<? extends java.lang.Enum> returnedClass()
Description copied from interface:UserType
The class returned by nullSafeGet().- Specified by:
returnedClass
in interfaceUserType
- Returns:
- Class
-
equals
public boolean equals(java.lang.Object x, java.lang.Object 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.- Specified by:
equals
in interfaceUserType
- Returns:
- boolean
- Throws:
HibernateException
-
hashCode
public int hashCode(java.lang.Object x) throws HibernateException
Description copied from interface:UserType
Get a hashcode for the instance, consistent with persistence "equality"- Specified by:
hashCode
in interfaceUserType
- Throws:
HibernateException
-
nullSafeGet
public java.lang.Object nullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, SharedSessionContractImplementor session, java.lang.Object owner) throws java.sql.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
- Parameters:
rs
- a JDBC result setnames
- the column namesowner
- the containing entity @return Object- Throws:
java.sql.SQLException
-
nullSafeSet
public void nullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, SharedSessionContractImplementor session) throws HibernateException, java.sql.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 from index.- Specified by:
nullSafeSet
in interfaceUserType
- Parameters:
st
- a JDBC prepared statementvalue
- the object to writeindex
- statement parameter index- Throws:
HibernateException
java.sql.SQLException
-
deepCopy
public java.lang.Object deepCopy(java.lang.Object 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.- Specified by:
deepCopy
in interfaceUserType
- Parameters:
value
- the object to be cloned, which may be null- Returns:
- Object a copy
- Throws:
HibernateException
-
isMutable
public boolean isMutable()
Description copied from interface:UserType
Are objects of this type mutable?
-
disassemble
public java.io.Serializable disassemble(java.lang.Object 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
- Parameters:
value
- the object to be cached- Returns:
- a cachable representation of the object
- Throws:
HibernateException
-
assemble
public java.lang.Object assemble(java.io.Serializable cached, java.lang.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)- Specified by:
assemble
in interfaceUserType
- Parameters:
cached
- the object to be cachedowner
- the owner of the cached object- Returns:
- a reconstructed object from the cachable representation
- Throws:
HibernateException
-
replace
public java.lang.Object replace(java.lang.Object original, java.lang.Object target, java.lang.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.- Specified by:
replace
in interfaceUserType
- Parameters:
original
- the value from the detached entity being mergedtarget
- the value in the managed entity- Returns:
- the value to be merged
- Throws:
HibernateException
-
getTypeConfiguration
public TypeConfiguration getTypeConfiguration()
- Specified by:
getTypeConfiguration
in interfaceTypeConfigurationAware
-
setTypeConfiguration
public void setTypeConfiguration(TypeConfiguration typeConfiguration)
- Specified by:
setTypeConfiguration
in interfaceTypeConfigurationAware
-
objectToSQLString
public java.lang.String objectToSQLString(java.lang.Object value)
Description copied from interface:EnhancedUserType
Return an SQL literal representation of the value- Specified by:
objectToSQLString
in interfaceEnhancedUserType
-
toXMLString
public java.lang.String toXMLString(java.lang.Object value)
Description copied from interface:EnhancedUserType
Return a string representation of this value, as it should appear in an XML document- Specified by:
toXMLString
in interfaceEnhancedUserType
-
fromXMLString
public java.lang.Object fromXMLString(java.lang.String xmlValue)
Description copied from interface:EnhancedUserType
Parse a string representation of this value, as it appears in an XML document- Specified by:
fromXMLString
in interfaceEnhancedUserType
-
toLoggableString
public java.lang.String toLoggableString(java.lang.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; guarenteed to be non-null and initialized.factory
- The factory.- Returns:
- The loggable string representation.
-
isOrdinal
public boolean isOrdinal()
-
-