KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > type > BooleanType


1 //$Id: BooleanType.java,v 1.4 2005/06/08 03:51:55 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.io.Serializable JavaDoc;
5 import java.sql.PreparedStatement JavaDoc;
6 import java.sql.ResultSet JavaDoc;
7 import java.sql.SQLException JavaDoc;
8 import java.sql.Types JavaDoc;
9
10 /**
11  * <tt>boolean</tt>: A type that maps an SQL BIT to a Java Boolean.
12  * @author Gavin King
13  */

14 public class BooleanType extends PrimitiveType implements DiscriminatorType {
15
16     private static final String JavaDoc TRUE = "1";
17     private static final String JavaDoc FALSE = "0";
18
19     public Serializable JavaDoc getDefaultValue() {
20         return Boolean.FALSE;
21     }
22     
23     public Object JavaDoc get(ResultSet JavaDoc rs, String JavaDoc name) throws SQLException JavaDoc {
24         return rs.getBoolean(name) ? Boolean.TRUE : Boolean.FALSE;
25     }
26
27     public Class JavaDoc getPrimitiveClass() {
28         return boolean.class;
29     }
30
31     public Class JavaDoc getReturnedClass() {
32         return Boolean JavaDoc.class;
33     }
34
35     public void set(PreparedStatement JavaDoc st, Object JavaDoc value, int index)
36     throws SQLException JavaDoc {
37         st.setBoolean( index, ( (Boolean JavaDoc) value ).booleanValue() );
38     }
39
40     public int sqlType() {
41         return Types.BIT;
42     }
43
44     public String JavaDoc getName() { return "boolean"; }
45
46     public String JavaDoc objectToSQLString(Object JavaDoc value) throws Exception JavaDoc {
47         return ( ( (Boolean JavaDoc) value ).booleanValue() ) ? TRUE : FALSE;
48     }
49
50     public Object JavaDoc stringToObject(String JavaDoc xml) throws Exception JavaDoc {
51         return fromStringValue(xml);
52     }
53
54     public Object JavaDoc fromStringValue(String JavaDoc xml) {
55         return Boolean.valueOf(xml);
56     }
57
58 }
59
60
61
62
63
64
Popular Tags