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