1
19
20 package com.liferay.portal.dao.orm.hibernate;
21
22 import com.liferay.portal.kernel.util.GetterUtil;
23
24 import java.io.Serializable;
25
26 import java.sql.PreparedStatement;
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.sql.Types;
30
31 import org.hibernate.Hibernate;
32 import org.hibernate.HibernateException;
33 import org.hibernate.usertype.UserType;
34
35
41 public class LongType implements UserType {
42
43 public final static long DEFAULT_VALUE = 0;
44
45 public final static int[] SQL_TYPES = new int[] {Types.BIGINT};
46
47 public Object assemble(Serializable cached, Object owner) {
48 return cached;
49 }
50
51 public Object deepCopy(Object obj) {
52 return obj;
53 }
54
55 public Serializable disassemble(Object value) {
56 return (Serializable)value;
57 }
58
59 public boolean equals(Object x, Object y) {
60 if (x == y) {
61 return true;
62 }
63 else if (x == null || y == null) {
64 return false;
65 }
66 else {
67 return x.equals(y);
68 }
69 }
70
71 public int hashCode(Object x) {
72 return x.hashCode();
73 }
74
75 public boolean isMutable() {
76 return false;
77 }
78
79 public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
80 throws HibernateException, SQLException {
81
82 Object value = null;
83
84 try {
85 value = Hibernate.LONG.nullSafeGet(rs, names[0]);
86 }
87 catch (SQLException sqle1) {
88
89
92 try {
93 value = new Long(GetterUtil.getLong(
94 (String)Hibernate.STRING.nullSafeGet(rs, names[0])));
95 }
96 catch (SQLException sqle2) {
97 throw sqle1;
98 }
99 }
100
101 if (value == null) {
102 return new Long(DEFAULT_VALUE);
103 }
104 else {
105 return value;
106 }
107 }
108
109 public void nullSafeSet(PreparedStatement ps, Object obj, int index)
110 throws HibernateException, SQLException {
111
112 if (obj == null) {
113 obj = new Long(DEFAULT_VALUE);
114 }
115
116 Hibernate.LONG.nullSafeSet(ps, obj, index);
117 }
118
119 public Object replace(Object original, Object target, Object owner) {
120 return original;
121 }
122
123 public Class<Long> returnedClass() {
124 return Long.class;
125 }
126
127 public int[] sqlTypes() {
128 return SQL_TYPES;
129 }
130
131 }