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