KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > db > hibernate > ConverterEnumType


1 package org.jbpm.db.hibernate;
2
3 import java.io.*;
4 import java.sql.*;
5
6 import org.hibernate.*;
7 import org.hibernate.usertype.*;
8 import org.jbpm.context.exe.*;
9
10 /**
11  * is the hibernate UserType for storing converters as a char in the database.
12  * The conversion can be found (and customized) in the file jbpm.converter.properties.
13  */

14 public class ConverterEnumType implements UserType {
15
16   static final int[] SQLTYPES = new int[]{Types.CHAR};
17
18   public boolean equals(Object JavaDoc o1, Object JavaDoc o2) { return (o1==o2); }
19   public int hashCode(Object JavaDoc o) throws HibernateException { return o.hashCode(); }
20   public Object JavaDoc deepCopy(Object JavaDoc o) throws HibernateException { return o; }
21   public boolean isMutable() { return false; }
22   public Serializable disassemble(Object JavaDoc o) throws HibernateException { return (Serializable) o; }
23   public Object JavaDoc assemble(Serializable s, Object JavaDoc o) throws HibernateException { return s; }
24   public Object JavaDoc replace(Object JavaDoc original, Object JavaDoc target, Object JavaDoc owner) { return target; }
25   public int[] sqlTypes() { return SQLTYPES; }
26   public Class JavaDoc returnedClass() { return Converter.class; }
27
28   public Object JavaDoc nullSafeGet(ResultSet resultSet, String JavaDoc[] names, Object JavaDoc owner) throws HibernateException, SQLException {
29     String JavaDoc converterDatabaseId = resultSet.getString(names[0]);
30     return Converters.getConverterByDatabaseId(converterDatabaseId);
31   }
32
33   public void nullSafeSet(PreparedStatement preparedStatement, Object JavaDoc value, int index) throws HibernateException, SQLException {
34     String JavaDoc converterDatabaseId = Converters.getConverterId((Converter) value);
35     preparedStatement.setString(index, converterDatabaseId);
36   }
37 }
38
Popular Tags