org.hibernate.type
Class EnumType

java.lang.Object
  extended by org.hibernate.type.EnumType
All Implemented Interfaces:
Serializable, DynamicParameterizedType, EnhancedUserType, LoggableUserType, ParameterizedType, UserType

public class EnumType
extends Object
implements EnhancedUserType, DynamicParameterizedType, LoggableUserType, 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:

See Also:
Serialized Form

Nested Class Summary
 class EnumType.EnumValueMapperSupport
           
 
Nested classes/interfaces inherited from interface org.hibernate.usertype.DynamicParameterizedType
DynamicParameterizedType.ParameterType
 
Field Summary
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
EnumType()
           
 
Method Summary
 Object assemble(Serializable cached, Object owner)
          Reconstruct an object from the cacheable representation.
 Object deepCopy(Object value)
          Return a deep copy of the persistent state, stopping at entities and at collections.
 Serializable disassemble(Object value)
          Transform the object into its cacheable representation.
 boolean equals(Object x, Object y)
          Compare two instances of the class mapped by this type for persistence "equality".
 Object fromXMLString(String xmlValue)
          Parse a string representation of this value, as it appears in an XML document
 int hashCode(Object x)
          Get a hashcode for the instance, consistent with persistence "equality"
 boolean isMutable()
          Are objects of this type mutable?
 boolean isOrdinal()
           
 Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
          Retrieve an instance of the mapped class from a JDBC resultset.
 void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
          Write an instance of the mapped class to a prepared statement.
 String objectToSQLString(Object value)
          Return an SQL literal representation of the value
 Object replace(Object original, Object 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<? extends Enum> returnedClass()
          The class returned by nullSafeGet().
 void setParameterValues(Properties parameters)
          Gets called by Hibernate to pass the configured type parameters to the implementation.
 int[] sqlTypes()
          Return the SQL type codes for the columns mapped by this type.
 String toLoggableString(Object value, SessionFactoryImplementor factory)
          Generate a loggable string representation of the collection (value).
 String toXMLString(Object value)
          Return a string representation of this value, as it should appear in an XML document
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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()
Method Detail

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.

Specified by:
sqlTypes in interface UserType
Returns:
int[] the typecodes
See Also:
Types

returnedClass

public Class<? extends Enum> returnedClass()
Description copied from interface: UserType
The class returned by nullSafeGet().

Specified by:
returnedClass in interface UserType
Returns:
Class

equals

public boolean equals(Object x,
                      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 interface UserType
Returns:
boolean
Throws:
HibernateException

hashCode

public int hashCode(Object x)
             throws HibernateException
Description copied from interface: UserType
Get a hashcode for the instance, consistent with persistence "equality"

Specified by:
hashCode in interface UserType
Throws:
HibernateException

nullSafeGet

public Object nullSafeGet(ResultSet rs,
                          String[] names,
                          SessionImplementor 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 interface UserType
Parameters:
rs - a JDBC result set
names - the column names
owner - the containing entity @return Object
Throws:
SQLException

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index,
                        SessionImplementor 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 from index.

Specified by:
nullSafeSet in interface UserType
Parameters:
st - a JDBC prepared statement
value - the object to write
index - statement parameter index
Throws:
HibernateException
SQLException

deepCopy

public Object deepCopy(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 interface UserType
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?

Specified by:
isMutable in interface UserType
Returns:
boolean

disassemble

public Serializable disassemble(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 interface UserType
Parameters:
value - the object to be cached
Returns:
a cachable representation of the object
Throws:
HibernateException

assemble

public Object 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)

Specified by:
assemble in interface UserType
Parameters:
cached - the object to be cached
owner - the owner of the cached object
Returns:
a reconstructed object from the cachable representation
Throws:
HibernateException

replace

public Object replace(Object original,
                      Object 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.

Specified by:
replace in interface UserType
Parameters:
original - the value from the detached entity being merged
target - the value in the managed entity
Returns:
the value to be merged
Throws:
HibernateException

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 interface ParameterizedType

objectToSQLString

public String objectToSQLString(Object value)
Description copied from interface: EnhancedUserType
Return an SQL literal representation of the value

Specified by:
objectToSQLString in interface EnhancedUserType

toXMLString

public String toXMLString(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 interface EnhancedUserType

fromXMLString

public Object fromXMLString(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 interface EnhancedUserType

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 interface LoggableUserType
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()


Copyright © 2001-2015 Red Hat, Inc. All Rights Reserved.