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="BooleanType.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class BooleanType implements UserType {
041:
042: public final static boolean DEFAULT_VALUE = false;
043:
044: public final static int[] SQL_TYPES = new int[] { Types.BIT };
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: Boolean value = (Boolean) Hibernate.BOOLEAN.nullSafeGet(rs,
080: names[0]);
081:
082: if (value == null) {
083: return Boolean.valueOf(DEFAULT_VALUE);
084: } else {
085: return value;
086: }
087: }
088:
089: public void nullSafeSet(PreparedStatement ps, Object obj, int index)
090: throws HibernateException, SQLException {
091:
092: if (obj == null) {
093: obj = Boolean.valueOf(DEFAULT_VALUE);
094: }
095:
096: Hibernate.BOOLEAN.nullSafeSet(ps, obj, index);
097: }
098:
099: public Object replace(Object original, Object target, Object owner) {
100: return original;
101: }
102:
103: public Class returnedClass() {
104: return Boolean.class;
105: }
106:
107: public int[] sqlTypes() {
108: return SQL_TYPES;
109: }
110:
111: }
|