~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/legacy/DoubleStringType.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: DoubleStringType.java 4599 2004-09-26 05:18:27Z oneovthafew $
 
2
package org.hibernate.test.legacy;
 
3
 
 
4
import java.io.Serializable;
 
5
import java.sql.PreparedStatement;
 
6
import java.sql.ResultSet;
 
7
import java.sql.SQLException;
 
8
import java.sql.Types;
 
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 returnedClass() {
 
25
                return String[].class;
 
26
        }
 
27
 
 
28
        public boolean equals(Object x, Object y) {
 
29
                if (x==y) return true;
 
30
                if (x==null || y==null) return false;
 
31
                return ( (String[]) x )[0].equals( ( (String[]) y )[0] ) && ( (String[]) x )[1].equals( ( (String[]) y )[1] );
 
32
        }
 
33
 
 
34
        public int hashCode(Object x) throws HibernateException {
 
35
                String[] a = (String[]) x;
 
36
                return a[0].hashCode() + 31 * a[1].hashCode(); 
 
37
        }
 
38
 
 
39
        public Object deepCopy(Object x) {
 
40
                if (x==null) return null;
 
41
                String[] result = new String[2];
 
42
                String[] input = (String[]) 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 nullSafeGet(ResultSet rs, String[] names, SessionImplementor session,     Object owner)
 
51
        throws HibernateException, SQLException {
 
52
 
 
53
                String first = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
 
54
                String second = (String) Hibernate.STRING.nullSafeGet(rs, names[1]);
 
55
 
 
56
                return ( first==null && second==null ) ? null : new String[] { first, second };
 
57
        }
 
58
 
 
59
        public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
 
60
        throws HibernateException, SQLException {
 
61
 
 
62
                String[] strings = (value==null) ? new String[2] : (String[]) value;
 
63
 
 
64
                Hibernate.STRING.nullSafeSet(st, strings[0], index);
 
65
                Hibernate.STRING.nullSafeSet(st, strings[1], index+1);
 
66
        }
 
67
 
 
68
        public String[] getPropertyNames() {
 
69
                return new String[] { "s1", "s2" };
 
70
        }
 
71
 
 
72
        public Type[] getPropertyTypes() {
 
73
                return new Type[] { Hibernate.STRING, Hibernate.STRING };
 
74
        }
 
75
 
 
76
        public Object getPropertyValue(Object component, int property) {
 
77
                return ( (String[]) component )[property];
 
78
        }
 
79
 
 
80
        public void setPropertyValue(
 
81
                Object component,
 
82
                int property,
 
83
                Object value) {
 
84
 
 
85
                ( (String[]) component )[property] = (String) value;
 
86
        }
 
87
 
 
88
        public Object assemble(
 
89
                Serializable cached,
 
90
                SessionImplementor session,
 
91
                Object owner) {
 
92
 
 
93
                return deepCopy(cached);
 
94
        }
 
95
 
 
96
        public Serializable disassemble(Object value, SessionImplementor session) {
 
97
                return (Serializable) deepCopy(value);
 
98
        }
 
99
        
 
100
        public Object replace(Object original, Object target, SessionImplementor session, Object owner) 
 
101
        throws HibernateException {
 
102
                return original;
 
103
        }
 
104
 
 
105
}
 
106
 
 
107
 
 
108
 
 
109
 
 
110
 
 
111
 
 
112