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 26 35 public class ByteType extends AbstractType { 36 37 protected boolean widenBytes; 38 39 public ByteType(boolean widenBytes) { 40 this.widenBytes = widenBytes; 41 } 42 43 public String getClassName() { 44 return Byte .class.getName(); 45 } 46 47 public Object materializeObject(ResultSet rs, int index, int type) throws Exception { 48 byte b = rs.getByte(index); 49 return (rs.wasNull()) ? null : new Byte (b); 50 } 51 52 public Object materializeObject(CallableStatement st, int index, int type) 53 throws Exception { 54 byte b = st.getByte(index); 55 return (st.wasNull()) ? null : new Byte (b); 56 } 57 58 public void setJdbcObject( 59 PreparedStatement st, 60 Object val, 61 int pos, 62 int type, 63 int precision) throws Exception { 64 65 if (widenBytes && (val instanceof Byte )) { 66 val = new Integer (((Byte ) val).intValue()); 67 } 68 69 super.setJdbcObject(st, val, pos, type, precision); 70 } 71 } 72 | Popular Tags |