001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.dao.hibernate;
022:
023: import java.io.Serializable;
024:
025: import java.sql.PreparedStatement;
026: import java.sql.ResultSet;
027: import java.sql.SQLException;
028: import java.sql.Types;
029:
030: import org.hibernate.Hibernate;
031: import org.hibernate.HibernateException;
032: import org.hibernate.usertype.UserType;
033:
034: /**
035: * <a href="FloatType.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class FloatType implements UserType {
041:
042: public final static float DEFAULT_VALUE = 0.0F;
043:
044: public final static int[] SQL_TYPES = new int[] { Types.FLOAT };
045:
046: public Object assemble(Serializable cached, Object owner) {
047: return cached;
048: }
049:
050: public Object deepCopy(Object obj) {
051: return obj;
052: }
053:
054: public Serializable disassemble(Object value) {
055: return (Serializable) value;
056: }
057:
058: public boolean equals(Object x, Object y) {
059: if (x == y) {
060: return true;
061: } else if (x == null || y == null) {
062: return false;
063: } else {
064: return x.equals(y);
065: }
066: }
067:
068: public int hashCode(Object x) {
069: return x.hashCode();
070: }
071:
072: public boolean isMutable() {
073: return false;
074: }
075:
076: public Object nullSafeGet(ResultSet rs, String[] names, Object obj)
077: throws HibernateException, SQLException {
078:
079: Float value = (Float) Hibernate.FLOAT.nullSafeGet(rs, names[0]);
080:
081: if (value == null) {
082: return new Float(DEFAULT_VALUE);
083: } else {
084: return value;
085: }
086: }
087:
088: public void nullSafeSet(PreparedStatement ps, Object obj, int index)
089: throws HibernateException, SQLException {
090:
091: if (obj == null) {
092: obj = new Float(DEFAULT_VALUE);
093: }
094:
095: Hibernate.FLOAT.nullSafeSet(ps, obj, index);
096: }
097:
098: public Object replace(Object original, Object target, Object owner) {
099: return original;
100: }
101:
102: public Class returnedClass() {
103: return Float.class;
104: }
105:
106: public int[] sqlTypes() {
107: return SQL_TYPES;
108: }
109:
110: }
|