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