public class GenericEnumUserType extends Object implements org.hibernate.usertype.EnhancedUserType, org.hibernate.usertype.ParameterizedType, Serializable
package com.atlassian.demo;
public enum SimpleNumber {
UNKNOWN(-1),
ZERO(0),
ONE(1),
TWO(2),
THREE(3);
public int getId() {
return value;
}
public SimpleNumber fromId(int value) {
switch(value) {
case 0: return ZERO;
case 1: return ONE;
case 2: return TWO;
case 3: return THREE;
default: return UNKNOWN;
}
}
}
Using JPA, the mapping would look like this:
@Type(type = "com.atlassian.stash.internal.hibernate.GenericEnumUserType", parameters = {
@Parameter(name = "enumClass", value = "com.atlassian.demo.SimpleNumber"),
@Parameter(name = "identifierMethod", value = "getId"),
@Parameter(name = "valueOfMethod", value = "fromId")})
private SimpleNumber randomNumber;
In this example, the properties for the GenericEnumUserType are fully specified to make the example more
clear on the type's usage. However, because the identifier and valueOf methods follow standard naming, properties
for them may be omitted from the mapping to reduce configuration.| 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) |
Object |
fromXMLString(String xmlValue) |
int |
hashCode(Object x) |
boolean |
isMutable() |
Object |
nullSafeGet(ResultSet rs,
String[] names,
Object owner) |
void |
nullSafeSet(PreparedStatement st,
Object value,
int index) |
String |
objectToSQLString(Object value) |
Object |
replace(Object original,
Object target,
Object owner) |
Class |
returnedClass() |
void |
setParameterValues(Properties parameters) |
int[] |
sqlTypes() |
String |
toXMLString(Object value) |
public Object assemble(Serializable cached, Object owner) throws org.hibernate.HibernateException
assemble in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic Object deepCopy(Object value) throws org.hibernate.HibernateException
deepCopy in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic Serializable disassemble(Object value) throws org.hibernate.HibernateException
disassemble in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic boolean equals(Object x, Object y) throws org.hibernate.HibernateException
equals in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic Object fromXMLString(String xmlValue)
fromXMLString in interface org.hibernate.usertype.EnhancedUserTypepublic int hashCode(Object x) throws org.hibernate.HibernateException
hashCode in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic boolean isMutable()
isMutable in interface org.hibernate.usertype.UserTypepublic Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws org.hibernate.HibernateException, SQLException
nullSafeGet in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionSQLExceptionpublic void nullSafeSet(PreparedStatement st, Object value, int index) throws org.hibernate.HibernateException, SQLException
nullSafeSet in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionSQLExceptionpublic String objectToSQLString(Object value)
objectToSQLString in interface org.hibernate.usertype.EnhancedUserTypepublic Object replace(Object original, Object target, Object owner) throws org.hibernate.HibernateException
replace in interface org.hibernate.usertype.UserTypeorg.hibernate.HibernateExceptionpublic Class returnedClass()
returnedClass in interface org.hibernate.usertype.UserTypepublic void setParameterValues(Properties parameters)
setParameterValues in interface org.hibernate.usertype.ParameterizedTypepublic int[] sqlTypes()
sqlTypes in interface org.hibernate.usertype.UserTypeCopyright © 2014 Atlassian. All rights reserved.