net.sf.jzeno.hibernate
Class PersistentEnum

java.lang.Object
  extended by net.sf.jzeno.model.AbstractEntity
      extended by net.sf.jzeno.hibernate.PersistentEnum
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, PersistentEnumItf, Entity, org.hibernate.usertype.UserType

public abstract class PersistentEnum
extends AbstractEntity
implements PersistentEnumItf

Provides a base class for implementations of persistable, type-safe, comparable and serializable enums with a custom persisted representation.

The subclass must provide a compareTo(Object) and getNullableType() implementation.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.jzeno.model.AbstractEntity
serialVersionUID
 
Constructor Summary
protected PersistentEnum()
           Default constructor.
 
Method Summary
 java.lang.Object assemble(java.io.Serializable cached, java.lang.Object owner)
           
 int compareTo(java.lang.Object other)
           define the natural ordering of abstract entities
 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)
           
 java.io.Serializable getEnumCode()
           Gets the persistable enum code of this enum.
protected  org.hibernate.type.NullableType getNullableType()
           
 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()
           
 int[] sqlTypes()
           
 
Methods inherited from class net.sf.jzeno.model.AbstractEntity
clone, equals, getChangedValue, getChangedValues, getId, getOriginalValue, getOriginalValues, hashCode, isChanged, isChanged, isUnsaved, onDelete, onFlushDirty, onLoad, onSave, postFlush, preFlush, setId, snapshot, superHashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistentEnum

protected PersistentEnum()

Default constructor. Hibernate need the default constructor to retrieve an instance of the enum from a JDBC resultset. The instance will be converted to the correct enum instance in nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object).

Method Detail

compareTo

public int compareTo(java.lang.Object other)
Description copied from class: AbstractEntity

define the natural ordering of abstract entities

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class AbstractEntity

getNullableType

protected org.hibernate.type.NullableType getNullableType()

sqlTypes

public int[] sqlTypes()
Specified by:
sqlTypes in interface PersistentEnumItf
Specified by:
sqlTypes in interface org.hibernate.usertype.UserType

deepCopy

public java.lang.Object deepCopy(java.lang.Object value)
                          throws org.hibernate.HibernateException
Specified by:
deepCopy in interface PersistentEnumItf
Specified by:
deepCopy in interface org.hibernate.usertype.UserType
Throws:
org.hibernate.HibernateException

isMutable

public boolean isMutable()
Specified by:
isMutable in interface PersistentEnumItf
Specified by:
isMutable in interface org.hibernate.usertype.UserType

returnedClass

public java.lang.Class returnedClass()
Specified by:
returnedClass in interface PersistentEnumItf
Specified by:
returnedClass in interface org.hibernate.usertype.UserType

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

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 PersistentEnumItf
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 PersistentEnumItf
Specified by:
nullSafeSet in interface org.hibernate.usertype.UserType
Throws:
org.hibernate.HibernateException
java.sql.SQLException

getEnumCode

public java.io.Serializable getEnumCode()
Description copied from interface: PersistentEnumItf

Gets the persistable enum code of this enum.

Specified by:
getEnumCode in interface PersistentEnumItf

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

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

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

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