KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > legacy > DoubleStringType


1 //$Id: DoubleStringType.java,v 1.1 2004/09/26 05:18:25 oneovthafew Exp $
2
package org.hibernate.test.legacy;
3
4 import java.io.Serializable JavaDoc;
5 import java.sql.PreparedStatement JavaDoc;
6 import java.sql.ResultSet JavaDoc;
7 import java.sql.SQLException JavaDoc;
8 import java.sql.Types JavaDoc;
9
10 import org.hibernate.Hibernate;
11 import org.hibernate.HibernateException;
12 import org.hibernate.engine.SessionImplementor;
13 import org.hibernate.type.Type;
14 import org.hibernate.usertype.CompositeUserType;
15
16 public class DoubleStringType implements CompositeUserType {
17
18     private static final int[] TYPES = { Types.VARCHAR, Types.VARCHAR };
19
20     public int[] sqlTypes() {
21         return TYPES;
22     }
23
24     public Class JavaDoc returnedClass() {
25         return String JavaDoc[].class;
26     }
27
28     public boolean equals(Object JavaDoc x, Object JavaDoc y) {
29         if (x==y) return true;
30         if (x==null || y==null) return false;
31         return ( (String JavaDoc[]) x )[0].equals( ( (String JavaDoc[]) y )[0] ) && ( (String JavaDoc[]) x )[1].equals( ( (String JavaDoc[]) y )[1] );
32     }
33
34     public int hashCode(Object JavaDoc x) throws HibernateException {
35         String JavaDoc[] a = (String JavaDoc[]) x;
36         return a[0].hashCode() + 31 * a[1].hashCode();
37     }
38
39     public Object JavaDoc deepCopy(Object JavaDoc x) {
40         if (x==null) return null;
41         String JavaDoc[] result = new String JavaDoc[2];
42         String JavaDoc[] input = (String JavaDoc[]) x;
43         result[0] = input[0];
44         result[1] = input[1];
45         return result;
46     }
47
48     public boolean isMutable() { return true; }
49
50     public Object JavaDoc nullSafeGet(ResultSet JavaDoc rs, String JavaDoc[] names, SessionImplementor session, Object JavaDoc owner)
51     throws HibernateException, SQLException JavaDoc {
52
53         String JavaDoc first = (String JavaDoc) Hibernate.STRING.nullSafeGet(rs, names[0]);
54         String JavaDoc second = (String JavaDoc) Hibernate.STRING.nullSafeGet(rs, names[1]);
55
56         return ( first==null && second==null ) ? null : new String JavaDoc[] { first, second };
57     }
58
59     public void nullSafeSet(PreparedStatement JavaDoc st, Object JavaDoc value, int index, SessionImplementor session)
60     throws HibernateException, SQLException JavaDoc {
61
62         String JavaDoc[] strings = (value==null) ? new String JavaDoc[2] : (String JavaDoc[]) value;
63
64         Hibernate.STRING.nullSafeSet(st, strings[0], index);
65         Hibernate.STRING.nullSafeSet(st, strings[1], index+1);
66     }
67
68     public String JavaDoc[] getPropertyNames() {
69         return new String JavaDoc[] { "s1", "s2" };
70     }
71
72     public Type[] getPropertyTypes() {
73         return new Type[] { Hibernate.STRING, Hibernate.STRING };
74     }
75
76     public Object JavaDoc getPropertyValue(Object JavaDoc component, int property) {
77         return ( (String JavaDoc[]) component )[property];
78     }
79
80     public void setPropertyValue(
81         Object JavaDoc component,
82         int property,
83         Object JavaDoc value) {
84
85         ( (String JavaDoc[]) component )[property] = (String JavaDoc) value;
86     }
87
88     public Object JavaDoc assemble(
89         Serializable JavaDoc cached,
90         SessionImplementor session,
91         Object JavaDoc owner) {
92
93         return deepCopy(cached);
94     }
95
96     public Serializable JavaDoc disassemble(Object JavaDoc value, SessionImplementor session) {
97         return (Serializable JavaDoc) deepCopy(value);
98     }
99     
100     public Object JavaDoc replace(Object JavaDoc original, Object JavaDoc target, SessionImplementor session, Object JavaDoc owner)
101     throws HibernateException {
102         return original;
103     }
104
105 }
106
107
108
109
110
111
112
113
Popular Tags