01: //$Id: BooleanType.java 7825 2005-08-10 20:23:55Z oneovthafew $
02: package org.hibernate.type;
03:
04: import java.io.Serializable;
05: import java.sql.PreparedStatement;
06: import java.sql.ResultSet;
07: import java.sql.SQLException;
08: import java.sql.Types;
09:
10: import org.hibernate.dialect.Dialect;
11:
12: /**
13: * <tt>boolean</tt>: A type that maps an SQL BIT to a Java Boolean.
14: * @author Gavin King
15: */
16: public class BooleanType extends PrimitiveType implements
17: DiscriminatorType {
18:
19: public Serializable getDefaultValue() {
20: return Boolean.FALSE;
21: }
22:
23: public Object get(ResultSet rs, String name) throws SQLException {
24: return rs.getBoolean(name) ? Boolean.TRUE : Boolean.FALSE;
25: }
26:
27: public Class getPrimitiveClass() {
28: return boolean.class;
29: }
30:
31: public Class getReturnedClass() {
32: return Boolean.class;
33: }
34:
35: public void set(PreparedStatement st, Object value, int index)
36: throws SQLException {
37: st.setBoolean(index, ((Boolean) value).booleanValue());
38: }
39:
40: public int sqlType() {
41: return Types.BIT;
42: }
43:
44: public String getName() {
45: return "boolean";
46: }
47:
48: public String objectToSQLString(Object value, Dialect dialect)
49: throws Exception {
50: return dialect.toBooleanValueString(((Boolean) value)
51: .booleanValue());
52: }
53:
54: public Object stringToObject(String xml) throws Exception {
55: return fromStringValue(xml);
56: }
57:
58: public Object fromStringValue(String xml) {
59: return Boolean.valueOf(xml);
60: }
61:
62: }
|