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 ShortType extends AbstractType { 36 37 protected boolean widenShorts; 38 39 public ShortType(boolean widenShorts) { 40 this.widenShorts = widenShorts; 41 } 42 43 public String getClassName() { 44 return Short .class.getName(); 45 } 46 47 public Object materializeObject(ResultSet rs, int index, int type) throws Exception { 48 short s = rs.getShort(index); 49 return (rs.wasNull()) ? null : new Short (s); 50 } 51 52 public Object materializeObject(CallableStatement st, int index, int type) 53 throws Exception { 54 short s = st.getShort(index); 55 return (st.wasNull()) ? null : new Short (s); 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 (widenShorts && (val instanceof Short )) { 66 val = new Integer (((Short ) val).intValue()); 67 } 68 69 super.setJdbcObject(st, val, pos, type, precision); 70 } 71 } 72 | Popular Tags |