public class EnumType<T extends Enum> extends Object implements EnhancedUserType, DynamicParameterizedType, LoggableUserType, TypeConfigurationAware, 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:<ul>
<li>
<strong>enumClass</strong> - Names the enumeration class.
</li>
<li>
<strong>useNamed</strong> - Should enum be mapped via name. Default is to map as ordinal. Used when
annotations are not used (otherwise EnumType is used).
</li>
<li>
<strong>type</strong> - Identifies the JDBC type (via type code) to be used for the column.
</li>
</ul>
DynamicParameterizedType.ParameterType| Modifier and Type | Field and Description |
|---|---|
static String |
ENUM |
static String |
NAMED |
static String |
TYPE |
ACCESS_TYPE, ENTITY, IS_DYNAMIC, IS_PRIMARY_KEY, PARAMETER_TYPE, PROPERTY, RETURNED_CLASS, XPROPERTY| Constructor and Description |
|---|
EnumType() |
| Modifier and Type | Method and Description |
|---|---|
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
|
TypeConfiguration |
getTypeConfiguration() |
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,
SharedSessionContractImplementor session,
Object owner)
Retrieve an instance of the mapped class from a JDBC resultset.
|
void |
nullSafeSet(PreparedStatement st,
Object value,
int index,
SharedSessionContractImplementor 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 <tt>nullSafeGet()</tt>.
|
void |
setParameterValues(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.
|
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
|
public static final String ENUM
public static final String NAMED
public static final String TYPE
public void setParameterValues(Properties parameters)
ParameterizedTypeGets called by Hibernate to pass the configured type parameters to the implementation.
setParameterValues in interface ParameterizedTypepublic int[] sqlTypes()
UserTypeReturn the SQL type codes for the columns mapped by this type. The codes are defined on <tt>java.sql.Types</tt>.
public Class<? extends Enum> returnedClass()
UserTypeThe class returned by <tt>nullSafeGet()</tt>.
returnedClass in interface UserTypepublic boolean equals(Object x, Object y) throws HibernateException
UserTypeCompare two instances of the class mapped by this type for persistence "equality". Equality of the persistent state.
equals in interface UserTypeHibernateExceptionpublic int hashCode(Object x) throws HibernateException
UserTypeGet a hashcode for the instance, consistent with persistence "equality"
hashCode in interface UserTypeHibernateExceptionpublic Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws SQLException
UserTypeRetrieve an instance of the mapped class from a JDBC resultset. Implementors should handle possibility of null values.
nullSafeGet in interface UserTypers - a JDBC result setnames - the column namesowner - the containing entity @return ObjectSQLExceptionpublic void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException
UserTypeWrite 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 <tt>index</tt>.
nullSafeSet in interface UserTypest - a JDBC prepared statementvalue - the object to writeindex - statement parameter indexHibernateExceptionSQLExceptionpublic Object deepCopy(Object value) throws HibernateException
UserTypeReturn 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.
deepCopy in interface UserTypevalue - the object to be cloned, which may be nullHibernateExceptionpublic boolean isMutable()
UserTypeAre objects of this type mutable?
public Serializable disassemble(Object value) throws HibernateException
UserTypeTransform 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)
disassemble in interface UserTypevalue - the object to be cachedHibernateExceptionpublic Object assemble(Serializable cached, Object owner) throws HibernateException
UserTypeReconstruct an object from the cacheable representation. At the very least this method should perform a deep copy if the type is mutable. (optional operation)
assemble in interface UserTypecached - the object to be cachedowner - the owner of the cached objectHibernateExceptionpublic Object replace(Object original, Object target, Object owner) throws HibernateException
UserTypeDuring 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.
replace in interface UserTypeoriginal - the value from the detached entity being mergedtarget - the value in the managed entityHibernateExceptionpublic TypeConfiguration getTypeConfiguration()
getTypeConfiguration in interface TypeConfigurationAwarepublic void setTypeConfiguration(TypeConfiguration typeConfiguration)
setTypeConfiguration in interface TypeConfigurationAwarepublic String objectToSQLString(Object value)
EnhancedUserTypeReturn an SQL literal representation of the value
objectToSQLString in interface EnhancedUserTypepublic String toXMLString(Object value)
EnhancedUserTypeReturn a string representation of this value, as it should appear in an XML document
toXMLString in interface EnhancedUserTypepublic Object fromXMLString(String xmlValue)
EnhancedUserTypeParse a string representation of this value, as it appears in an XML document
fromXMLString in interface EnhancedUserTypepublic String toLoggableString(Object value, SessionFactoryImplementor factory)
LoggableUserTypeGenerate a loggable string representation of the collection (value).
toLoggableString in interface LoggableUserTypevalue - The collection to be logged; guarenteed to be non-null and initialized.factory - The factory.public boolean isOrdinal()
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.