public class GenericEnumUserType extends Object implements org.hibernate.usertype.UserType, org.hibernate.usertype.ParameterizedType, Serializable
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
...
Constructor and Description |
---|
GenericEnumUserType() |
Modifier and Type | Method and Description |
---|---|
Object |
assemble(Serializable cached,
Object owner) |
Object |
deepCopy(Object value) |
Serializable |
disassemble(Object value) |
boolean |
equals(Object x,
Object y) |
int |
hashCode(Object x) |
boolean |
isMutable() |
Object |
nullSafeGet(ResultSet rs,
String[] names,
Object owner) |
void |
nullSafeSet(PreparedStatement st,
Object value,
int index) |
Object |
replace(Object original,
Object target,
Object owner) |
Class |
returnedClass() |
void |
setParameterValues(Properties parameters) |
int[] |
sqlTypes() |
public void setParameterValues(Properties parameters)
setParameterValues
in interface org.hibernate.usertype.ParameterizedType
public Class returnedClass()
returnedClass
in interface org.hibernate.usertype.UserType
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws org.hibernate.HibernateException, SQLException
org.hibernate.HibernateException
SQLException
public void nullSafeSet(PreparedStatement st, Object value, int index) throws org.hibernate.HibernateException, SQLException
org.hibernate.HibernateException
SQLException
public int[] sqlTypes()
sqlTypes
in interface org.hibernate.usertype.UserType
public Object assemble(Serializable cached, Object owner) throws org.hibernate.HibernateException
assemble
in interface org.hibernate.usertype.UserType
org.hibernate.HibernateException
public Object deepCopy(Object value) throws org.hibernate.HibernateException
deepCopy
in interface org.hibernate.usertype.UserType
org.hibernate.HibernateException
public Serializable disassemble(Object value) throws org.hibernate.HibernateException
disassemble
in interface org.hibernate.usertype.UserType
org.hibernate.HibernateException
public boolean equals(Object x, Object y) throws org.hibernate.HibernateException
equals
in interface org.hibernate.usertype.UserType
org.hibernate.HibernateException
public int hashCode(Object x) throws org.hibernate.HibernateException
hashCode
in interface org.hibernate.usertype.UserType
org.hibernate.HibernateException
public boolean isMutable()
isMutable
in interface org.hibernate.usertype.UserType
Copyright © 2013 Atlassian. All Rights Reserved.