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