org.company.thesandbox.data
Class GenericEnumUserType
java.lang.Object
org.company.thesandbox.data.GenericEnumUserType
- All Implemented Interfaces:
- org.hibernate.usertype.ParameterizedType, org.hibernate.usertype.UserType
public class GenericEnumUserType
- extends java.lang.Object
- implements org.hibernate.usertype.UserType, org.hibernate.usertype.ParameterizedType
Implements a generic enum user type identified / represented by a single identifier / column.
- The enum type being represented by the certain user type must be set by using the 'enumClass'
property.
- The identifier representing a enum value is retrieved by the identifierMethod. The name of
the identifier method can be specified by the 'identifierMethod' property and by default the
name() method is used.
- The identifier type is automatically determined by the return-type of theidentifierMethod.d34
- The valueOfMethod is the name of the static factory method returning the enumeration object
being represented by the given indentifier. The valueOfMethod's name can be specified by setting
the 'valueOfMethod' property. The default valueOfMethod's name is 'valueOf'.
Example of an enum type represented by an int value:
public enum SimpleNumber {
Unknown(-1), Zero(0), One(1), Two(2), Three(3);
int value;
protected SimpleNumber(int value) {
this.value = value;
}
public int toInt() { return value; }
public SimpleNumber fromInt(int value) {
switch(value) {
case 0: return Zero;
case 1: return One;
case 2: return Two;
case 3: return Three;
default:
return Unknown;
}
}
}
The Mapping would look like this:
SimpleNumber
toInt
fromInt
...
- Since:
- 05.05.2005
- Author:
- Martin Kersten
|
Method Summary |
java.lang.Object |
assemble(java.io.Serializable cached,
java.lang.Object owner)
|
java.lang.Object |
deepCopy(java.lang.Object value)
|
java.io.Serializable |
disassemble(java.lang.Object value)
|
boolean |
equals(java.lang.Object x,
java.lang.Object y)
|
int |
hashCode(java.lang.Object x)
|
boolean |
isMutable()
|
java.lang.Object |
nullSafeGet(java.sql.ResultSet rs,
java.lang.String[] names,
java.lang.Object owner)
|
void |
nullSafeSet(java.sql.PreparedStatement st,
java.lang.Object value,
int index)
|
java.lang.Object |
replace(java.lang.Object original,
java.lang.Object target,
java.lang.Object owner)
|
java.lang.Class |
returnedClass()
|
void |
setParameterValues(java.util.Properties parameters)
|
int[] |
sqlTypes()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GenericEnumUserType
public GenericEnumUserType()
setParameterValues
public void setParameterValues(java.util.Properties parameters)
- Specified by:
setParameterValues in interface org.hibernate.usertype.ParameterizedType
returnedClass
public java.lang.Class returnedClass()
- Specified by:
returnedClass in interface org.hibernate.usertype.UserType
nullSafeGet
public java.lang.Object nullSafeGet(java.sql.ResultSet rs,
java.lang.String[] names,
java.lang.Object owner)
throws org.hibernate.HibernateException,
java.sql.SQLException
- Specified by:
nullSafeGet in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
nullSafeSet
public void nullSafeSet(java.sql.PreparedStatement st,
java.lang.Object value,
int index)
throws org.hibernate.HibernateException,
java.sql.SQLException
- Specified by:
nullSafeSet in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
sqlTypes
public int[] sqlTypes()
- Specified by:
sqlTypes in interface org.hibernate.usertype.UserType
assemble
public java.lang.Object assemble(java.io.Serializable cached,
java.lang.Object owner)
throws org.hibernate.HibernateException
- Specified by:
assemble in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
deepCopy
public java.lang.Object deepCopy(java.lang.Object value)
throws org.hibernate.HibernateException
- Specified by:
deepCopy in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
disassemble
public java.io.Serializable disassemble(java.lang.Object value)
throws org.hibernate.HibernateException
- Specified by:
disassemble in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
equals
public boolean equals(java.lang.Object x,
java.lang.Object y)
throws org.hibernate.HibernateException
- Specified by:
equals in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
hashCode
public int hashCode(java.lang.Object x)
throws org.hibernate.HibernateException
- Specified by:
hashCode in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
isMutable
public boolean isMutable()
- Specified by:
isMutable in interface org.hibernate.usertype.UserType
replace
public java.lang.Object replace(java.lang.Object original,
java.lang.Object target,
java.lang.Object owner)
throws org.hibernate.HibernateException
- Specified by:
replace in interface org.hibernate.usertype.UserType
- Throws:
org.hibernate.HibernateException
Copyright © 2010. All Rights Reserved.