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
43 public class LongType implements Serializable, UserType {
44
45 public final static long DEFAULT_VALUE = 0;
46
47 public final static int[] SQL_TYPES = new int[] {Types.BIGINT};
48
49 public Object assemble(Serializable cached, Object owner) {
50 return cached;
51 }
52
53 public Object deepCopy(Object obj) {
54 return obj;
55 }
56
57 public Serializable disassemble(Object value) {
58 return (Serializable)value;
59 }
60
61 public boolean equals(Object x, Object y) {
62 if (x == y) {
63 return true;
64 }
65 else if (x == null || y == null) {
66 return false;
67 }
68 else {
69 return x.equals(y);
70 }
71 }
72
73 public int hashCode(Object x) {
74 return x.hashCode();
75 }
76
77 public boolean isMutable() {
78 return false;
79 }
80
81 public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
82 throws HibernateException, SQLException {
83
84 Object value = null;
85
86 try {
87 value = Hibernate.LONG.nullSafeGet(rs, names[0]);
88 }
89 catch (SQLException sqle1) {
90
91
94 try {
95 value = new Long(GetterUtil.getLong(
96 (String)Hibernate.STRING.nullSafeGet(rs, names[0])));
97 }
98 catch (SQLException sqle2) {
99 throw sqle1;
100 }
101 }
102
103 if (value == null) {
104 return new Long(DEFAULT_VALUE);
105 }
106 else {
107 return value;
108 }
109 }
110
111 public void nullSafeSet(PreparedStatement ps, Object obj, int index)
112 throws HibernateException, SQLException {
113
114 if (obj == null) {
115 obj = new Long(DEFAULT_VALUE);
116 }
117
118 Hibernate.LONG.nullSafeSet(ps, obj, index);
119 }
120
121 public Object replace(Object original, Object target, Object owner) {
122 return original;
123 }
124
125 public Class<Long> returnedClass() {
126 return Long.class;
127 }
128
129 public int[] sqlTypes() {
130 return SQL_TYPES;
131 }
132
133 }