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
43 public class IntegerType implements UserType {
44
45 public final static int DEFAULT_VALUE = 0;
46
47 public final static int[] SQL_TYPES = new int[] {Types.INTEGER};
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 {
83
84 Integer value = null;
85
86 try {
87 value = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[0]);
88 }
89 catch (SQLException sqle) {
90 }
91
92 if (value == null) {
93 return new Integer(DEFAULT_VALUE);
94 }
95 else {
96 return value;
97 }
98 }
99
100 public void nullSafeSet(PreparedStatement ps, Object obj, int index)
101 throws HibernateException, SQLException {
102
103 if (obj == null) {
104 obj = new Integer(DEFAULT_VALUE);
105 }
106
107 Hibernate.INTEGER.nullSafeSet(ps, obj, index);
108 }
109
110 public Object replace(Object original, Object target, Object owner) {
111 return original;
112 }
113
114 public Class<Integer> returnedClass() {
115 return Integer.class;
116 }
117
118 public int[] sqlTypes() {
119 return SQL_TYPES;
120 }
121
122 }