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