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