1 19 20 package org.apache.cayenne.access.types; 21 22 import java.sql.CallableStatement ; 23 import java.sql.PreparedStatement ; 24 import java.sql.ResultSet ; 25 import java.sql.Types ; 26 27 import org.apache.cayenne.map.DbAttribute; 28 import org.apache.cayenne.validation.ValidationResult; 29 30 39 public class BooleanType implements ExtendedType { 40 41 public String getClassName() { 42 return Boolean .class.getName(); 43 } 44 45 48 public boolean validateProperty( 49 Object source, 50 String property, 51 Object value, 52 DbAttribute dbAttribute, 53 ValidationResult validationResult) { 54 return AbstractType.validateNull( 55 source, 56 property, 57 value, 58 dbAttribute, 59 validationResult); 60 } 61 62 public void setJdbcObject( 63 PreparedStatement st, 64 Object val, 65 int pos, 66 int type, 67 int precision) throws Exception { 68 69 if (val == null) { 70 st.setNull(pos, type); 71 } 72 else if (type == Types.BIT || type == Types.BOOLEAN) { 73 boolean flag = Boolean.TRUE.equals(val); 74 st.setBoolean(pos, flag); 75 } 76 else { 77 st.setObject(pos, val, type); 78 } 79 } 80 81 public Object materializeObject(ResultSet rs, int index, int type) throws Exception { 82 boolean b = rs.getBoolean(index); 83 return (rs.wasNull()) ? null : b ? Boolean.TRUE : Boolean.FALSE; 84 } 85 86 public Object materializeObject(CallableStatement st, int index, int type) 87 throws Exception { 88 boolean b = st.getBoolean(index); 89 return (st.wasNull()) ? null : b ? Boolean.TRUE : Boolean.FALSE; 90 } 91 } 92 | Popular Tags |