1
14
15 package com.liferay.portal.dao.orm.hibernate;
16
17 import java.io.Serializable;
18
19 import java.sql.PreparedStatement;
20 import java.sql.ResultSet;
21 import java.sql.SQLException;
22 import java.sql.Types;
23
24 import org.hibernate.Hibernate;
25 import org.hibernate.HibernateException;
26 import org.hibernate.usertype.UserType;
27
28
33 public class FloatType implements Serializable, UserType {
34
35 public final static float DEFAULT_VALUE = 0.0F;
36
37 public final static int[] SQL_TYPES = new int[] {Types.FLOAT};
38
39 public Object assemble(Serializable cached, Object owner) {
40 return cached;
41 }
42
43 public Object deepCopy(Object obj) {
44 return obj;
45 }
46
47 public Serializable disassemble(Object value) {
48 return (Serializable)value;
49 }
50
51 public boolean equals(Object x, Object y) {
52 if (x == y) {
53 return true;
54 }
55 else if (x == null || y == null) {
56 return false;
57 }
58 else {
59 return x.equals(y);
60 }
61 }
62
63 public int hashCode(Object x) {
64 return x.hashCode();
65 }
66
67 public boolean isMutable() {
68 return false;
69 }
70
71 public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
72 throws HibernateException, SQLException {
73
74 Float value = (Float)Hibernate.FLOAT.nullSafeGet(rs, names[0]);
75
76 if (value == null) {
77 return new Float(DEFAULT_VALUE);
78 }
79 else {
80 return value;
81 }
82 }
83
84 public void nullSafeSet(PreparedStatement ps, Object obj, int index)
85 throws HibernateException, SQLException {
86
87 if (obj == null) {
88 obj = new Float(DEFAULT_VALUE);
89 }
90
91 Hibernate.FLOAT.nullSafeSet(ps, obj, index);
92 }
93
94 public Object replace(Object original, Object target, Object owner) {
95 return original;
96 }
97
98 public Class<Float> returnedClass() {
99 return Float.class;
100 }
101
102 public int[] sqlTypes() {
103 return SQL_TYPES;
104 }
105
106 }