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 ByteMapping extends ColumnMapping 23 { 24 public ByteMapping(DatabaseAdapter dba, Class type) 25 { 26 super(dba, type); 27 28 initTypeInfo(); 29 } 30 31 public ByteMapping(Column col) 32 { 33 super(col); 34 35 col.checkPrimitive(); 36 37 initTypeInfo(); 38 } 39 40 public ByteMapping(ClassBaseTable table, int relativeFieldNumber) 41 { 42 this(table.newColumn(relativeFieldNumber)); 43 } 44 45 protected TypeInfo getTypeInfo() 46 { 47 return dba.getTypeInfo(new int[] { Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.DECIMAL }); 48 } 49 50 public void setByte(PersistenceManager pm, PreparedStatement ps, int param, byte value) 51 { 52 try 53 { 54 ps.setByte(param, value); 55 } 56 catch (SQLException e) 57 { 58 throw dba.newDataStoreException("Can't set byte parameter: value = " + value, e); 59 } 60 } 61 62 public byte getByte(PersistenceManager pm, ResultSet rs, int param) 63 { 64 byte value; 65 66 try 67 { 68 value = rs.getByte(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 byte 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.setByte(param, ((Byte )value).byteValue()); 89 } 90 catch (SQLException e) 91 { 92 throw dba.newDataStoreException("Can't set Byte 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 byte b = rs.getByte(param); 103 value = rs.wasNull() ? null : new Byte (b); 104 } 105 catch (SQLException e) 106 { 107 throw dba.newDataStoreException("Can't get Byte 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(((Byte )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 |