1
//$Id: DoubleStringType.java 4599 2004-09-26 05:18:27Z oneovthafew $
2
package org.hibernate.test.legacy;
4
import java.io.Serializable;
5
import java.sql.PreparedStatement;
6
import java.sql.ResultSet;
7
import java.sql.SQLException;
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;
16
public class DoubleStringType implements CompositeUserType {
18
private static final int[] TYPES = { Types.VARCHAR, Types.VARCHAR };
20
public int[] sqlTypes() {
24
public Class returnedClass() {
25
return String[].class;
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] );
34
public int hashCode(Object x) throws HibernateException {
35
String[] a = (String[]) x;
36
return a[0].hashCode() + 31 * a[1].hashCode();
39
public Object deepCopy(Object x) {
40
if (x==null) return null;
41
String[] result = new String[2];
42
String[] input = (String[]) x;
48
public boolean isMutable() { return true; }
50
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
51
throws HibernateException, SQLException {
53
String first = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
54
String second = (String) Hibernate.STRING.nullSafeGet(rs, names[1]);
56
return ( first==null && second==null ) ? null : new String[] { first, second };
59
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
60
throws HibernateException, SQLException {
62
String[] strings = (value==null) ? new String[2] : (String[]) value;
64
Hibernate.STRING.nullSafeSet(st, strings[0], index);
65
Hibernate.STRING.nullSafeSet(st, strings[1], index+1);
68
public String[] getPropertyNames() {
69
return new String[] { "s1", "s2" };
72
public Type[] getPropertyTypes() {
73
return new Type[] { Hibernate.STRING, Hibernate.STRING };
76
public Object getPropertyValue(Object component, int property) {
77
return ( (String[]) component )[property];
80
public void setPropertyValue(
85
( (String[]) component )[property] = (String) value;
88
public Object assemble(
90
SessionImplementor session,
93
return deepCopy(cached);
96
public Serializable disassemble(Object value, SessionImplementor session) {
97
return (Serializable) deepCopy(value);
100
public Object replace(Object original, Object target, SessionImplementor session, Object owner)
101
throws HibernateException {