1 package org.jbpm.bpel.hibernate; 2 3 import java.io.Serializable ; 4 import java.sql.PreparedStatement ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 import java.sql.Types ; 8 9 import org.hibernate.Hibernate; 10 import org.hibernate.HibernateException; 11 import org.hibernate.usertype.UserType; 12 13 import org.jbpm.bpel.exe.state.ScopeState; 14 15 20 public class ScopeStateType implements UserType { 21 22 static final int[] SQLTYPES = new int[]{Types.SMALLINT}; 23 24 public ScopeStateType() { 25 } 26 27 public boolean equals(Object o1, Object o2) { return (o1==o2); } 28 public int hashCode(Object o) throws HibernateException { return o.hashCode(); } 29 public Object deepCopy(Object o) throws HibernateException { return o; } 30 public boolean isMutable() { return false; } 31 public Serializable disassemble(Object o) throws HibernateException { return (Serializable ) o; } 32 public Object assemble(Serializable s, Object o) throws HibernateException { return s; } 33 public Object replace(Object original, Object target, Object owner) { return target; } 34 public int[] sqlTypes() { return SQLTYPES; } 35 36 37 public Object nullSafeGet(ResultSet rs, String [] names, Object owner) 38 throws HibernateException, SQLException { 39 int enumCode = ((Integer ) Hibernate.INTEGER.nullSafeGet(rs, names[0])).intValue(); 40 41 return fromInt(enumCode); 42 } 43 44 45 public void nullSafeSet(PreparedStatement st, Object value, int index) 46 throws HibernateException, SQLException { 47 if ((value != null) && !returnedClass().isAssignableFrom(value.getClass())) { 49 throw new IllegalArgumentException ("Received value is not a[" + 50 returnedClass().getName() + "] but [" + value.getClass() + "]"); 51 } 52 53 st.setInt(index, toInt(value)); 55 } 56 57 58 public Class returnedClass() { 59 return ScopeState.class; 60 } 61 62 public int toInt(Object object) { 63 return ((ScopeState) object).toInt(); 64 } 65 66 public Object fromInt(int code) { 67 return ScopeState.fromInt(code); 68 } 69 } 70 | Popular Tags |