1 10 11 package com.triactive.jdo.store; 12 13 import com.triactive.jdo.PersistenceManager; 14 import java.math.BigInteger ; 15 import java.sql.PreparedStatement ; 16 import java.sql.ResultSet ; 17 import java.sql.SQLException ; 18 import java.sql.Types ; 19 import javax.jdo.JDODataStoreException; 20 21 22 public class ShortMapping extends ColumnMapping 23 { 24 public ShortMapping(DatabaseAdapter dba, Class type) 25 { 26 super(dba, type); 27 28 initTypeInfo(); 29 } 30 31 public ShortMapping(Column col) 32 { 33 super(col); 34 35 col.checkPrimitive(); 36 37 initTypeInfo(); 38 } 39 40 public ShortMapping(ClassBaseTable table, int relativeFieldNumber) 41 { 42 this(table.newColumn(relativeFieldNumber)); 43 } 44 45 protected TypeInfo getTypeInfo() 46 { 47 return dba.getTypeInfo(new int[] { Types.SMALLINT, Types.DECIMAL }); 48 } 49 50 public void setShort(PersistenceManager pm, PreparedStatement ps, int param, short value) 51 { 52 try 53 { 54 ps.setShort(param, value); 55 } 56 catch (SQLException e) 57 { 58 throw dba.newDataStoreException("Can't set short parameter: value = " + value, e); 59 } 60 } 61 62 public short getShort(PersistenceManager pm, ResultSet rs, int param) 63 { 64 short value; 65 66 try 67 { 68 value = rs.getShort(param); 69 70 if (rs.wasNull()) 71 throw new NullValueException("Illegal null value in column " + col); 72 } 73 catch (SQLException e) 74 { 75 throw dba.newDataStoreException("Can't get short result: param = " + param, e); 76 } 77 78 return value; 79 } 80 81 public void setObject(PersistenceManager pm, PreparedStatement ps, int param, Object value) 82 { 83 try 84 { 85 if (value == null) 86 ps.setNull(param, typeInfo.dataType); 87 else 88 ps.setShort(param, ((Short )value).shortValue()); 89 } 90 catch (SQLException e) 91 { 92 throw dba.newDataStoreException("Can't set Short parameter: value = " + value, e); 93 } 94 } 95 96 public Object getObject(PersistenceManager pm, ResultSet rs, int param) 97 { 98 Object value; 99 100 try 101 { 102 short s = rs.getShort(param); 103 value = rs.wasNull() ? null : new Short (s); 104 } 105 catch (SQLException e) 106 { 107 throw dba.newDataStoreException("Can't get Short result: param = " + param, e); 108 } 109 110 return value; 111 } 112 113 public SQLExpression newSQLLiteral(QueryStatement qs, Object value) 114 { 115 return new IntegerLiteral(qs, BigInteger.valueOf(((Short )value).longValue())); 116 } 117 118 public SQLExpression newSQLExpression(QueryStatement qs, QueryStatement.QueryColumn qsc, String fieldName) 119 { 120 return new NumericExpression(qs, qsc); 121 } 122 } 123 | Popular Tags |