1 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 14 public class BooleanType extends PrimitiveType implements DiscriminatorType { 15 16 private static final String TRUE = "1"; 17 private static final String FALSE = "0"; 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() { return "boolean"; } 45 46 public String objectToSQLString(Object value) throws Exception { 47 return ( ( (Boolean ) value ).booleanValue() ) ? TRUE : FALSE; 48 } 49 50 public Object stringToObject(String xml) throws Exception { 51 return fromStringValue(xml); 52 } 53 54 public Object fromStringValue(String xml) { 55 return Boolean.valueOf(xml); 56 } 57 58 } 59 60 61 62 63 64 | Popular Tags |