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