1 56 package org.objectstyle.cayenne.access.types; 57 58 import java.sql.CallableStatement ; 59 import java.sql.PreparedStatement ; 60 import java.sql.ResultSet ; 61 62 71 public class ByteType extends AbstractType { 72 73 protected boolean widenBytes; 74 75 public ByteType(boolean widenBytes) { 76 this.widenBytes = widenBytes; 77 } 78 79 public String getClassName() { 80 return Byte .class.getName(); 81 } 82 83 public Object materializeObject(ResultSet rs, int index, int type) throws Exception { 84 byte b = rs.getByte(index); 85 return (rs.wasNull()) ? null : new Byte (b); 86 } 87 88 public Object materializeObject(CallableStatement st, int index, int type) 89 throws Exception { 90 byte b = st.getByte(index); 91 return (st.wasNull()) ? null : new Byte (b); 92 } 93 94 public void setJdbcObject( 95 PreparedStatement st, 96 Object val, 97 int pos, 98 int type, 99 int precision) throws Exception { 100 101 if (widenBytes && (val instanceof Byte )) { 102 val = new Integer (((Byte ) val).intValue()); 103 } 104 105 super.setJdbcObject(st, val, pos, type, precision); 106 } 107 } 108 | Popular Tags |