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 ShortType extends AbstractType { 72 protected boolean widenShorts; 73 74 public ShortType(boolean widenShorts) { 75 this.widenShorts = widenShorts; 76 } 77 78 public String getClassName() { 79 return Short .class.getName(); 80 } 81 82 public Object materializeObject(ResultSet rs, int index, int type) throws Exception { 83 short s = rs.getShort(index); 84 return (rs.wasNull()) ? null : new Short (s); 85 } 86 87 public Object materializeObject(CallableStatement st, int index, int type) 88 throws Exception { 89 short s = st.getShort(index); 90 return (st.wasNull()) ? null : new Short (s); 91 } 92 93 public void setJdbcObject( 94 PreparedStatement st, 95 Object val, 96 int pos, 97 int type, 98 int precision) 99 throws Exception { 100 101 if (widenShorts && (val instanceof Short )) { 102 val = new Integer (((Short ) val).intValue()); 103 } 104 105 super.setJdbcObject(st, val, pos, type, precision); 106 } 107 } 108 | Popular Tags |