~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/type/BooleanType.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: BooleanType.java 7825 2005-08-10 20:23:55Z oneovthafew $
 
2
package org.hibernate.type;
 
3
 
 
4
import java.io.Serializable;
 
5
import java.sql.PreparedStatement;
 
6
import java.sql.ResultSet;
 
7
import java.sql.SQLException;
 
8
import java.sql.Types;
 
9
 
 
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 DiscriminatorType {
 
17
 
 
18
        public Serializable getDefaultValue() {
 
19
                return Boolean.FALSE;
 
20
        }
 
21
        
 
22
        public Object get(ResultSet rs, String name) throws SQLException {
 
23
                return rs.getBoolean(name) ? Boolean.TRUE : Boolean.FALSE;
 
24
        }
 
25
 
 
26
        public Class getPrimitiveClass() {
 
27
                return boolean.class;
 
28
        }
 
29
 
 
30
        public Class getReturnedClass() {
 
31
                return Boolean.class;
 
32
        }
 
33
 
 
34
        public void set(PreparedStatement st, Object value, int index)
 
35
        throws SQLException {
 
36
                st.setBoolean( index, ( (Boolean) value ).booleanValue() );
 
37
        }
 
38
 
 
39
        public int sqlType() {
 
40
                return Types.BIT;
 
41
        }
 
42
 
 
43
        public String getName() { return "boolean"; }
 
44
 
 
45
        public String objectToSQLString(Object value, Dialect dialect) throws Exception {
 
46
                return dialect.toBooleanValueString( ( (Boolean) value ).booleanValue() );
 
47
        }
 
48
 
 
49
        public Object stringToObject(String xml) throws Exception {
 
50
                return fromStringValue(xml);
 
51
        }
 
52
 
 
53
        public Object fromStringValue(String xml) {
 
54
                return Boolean.valueOf(xml);
 
55
        }
 
56
 
 
57
}
 
58
 
 
59
 
 
60
 
 
61
 
 
62