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
41 public class FloatType implements Serializable, UserType {
42
43 public final static float DEFAULT_VALUE = 0.0F;
44
45 public final static int[] SQL_TYPES = new int[] {Types.FLOAT};
46
47 public Object assemble(Serializable cached, Object owner) {
48 return cached;
49 }
50
51 public Object deepCopy(Object obj) {
52 return obj;
53 }
54
55 public Serializable disassemble(Object value) {
56 return (Serializable)value;
57 }
58
59 public boolean equals(Object x, Object y) {
60 if (x == y) {
61 return true;
62 }
63 else if (x == null || y == null) {
64 return false;
65 }
66 else {
67 return x.equals(y);
68 }
69 }
70
71 public int hashCode(Object x) {
72 return x.hashCode();
73 }
74
75 public boolean isMutable() {
76 return false;
77 }
78
79 public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
80 throws HibernateException, SQLException {
81
82 Float value = (Float)Hibernate.FLOAT.nullSafeGet(rs, names[0]);
83
84 if (value == null) {
85 return new Float(DEFAULT_VALUE);
86 }
87 else {
88 return value;
89 }
90 }
91
92 public void nullSafeSet(PreparedStatement ps, Object obj, int index)
93 throws HibernateException, SQLException {
94
95 if (obj == null) {
96 obj = new Float(DEFAULT_VALUE);
97 }
98
99 Hibernate.FLOAT.nullSafeSet(ps, obj, index);
100 }
101
102 public Object replace(Object original, Object target, Object owner) {
103 return original;
104 }
105
106 public Class<Float> returnedClass() {
107 return Float.class;
108 }
109
110 public int[] sqlTypes() {
111 return SQL_TYPES;
112 }
113
114 }