1 10 11 package com.triactive.jdo.store; 12 13 import com.triactive.jdo.PersistenceManager; 14 import java.math.BigDecimal ; 15 import java.math.BigInteger ; 16 import java.sql.PreparedStatement ; 17 import java.sql.ResultSet ; 18 import java.sql.SQLException ; 19 import java.sql.Types ; 20 import javax.jdo.JDODataStoreException; 21 22 23 public class BigIntegerMapping extends ColumnMapping 24 { 25 public BigIntegerMapping(DatabaseAdapter dba, Class type) 26 { 27 super(dba, type); 28 29 initTypeInfo(); 30 } 31 32 public BigIntegerMapping(Column col) 33 { 34 super(col); 35 36 col.checkInteger(); 37 38 initTypeInfo(); 39 } 40 41 public BigIntegerMapping(ClassBaseTable table, int relativeFieldNumber) 42 { 43 this(table.newColumn(relativeFieldNumber)); 44 } 45 46 protected TypeInfo getTypeInfo() 47 { 48 if (col != null && col.isExactPrecision()) 49 return dba.getTypeInfo(new int[] { Types.NUMERIC, Types.DECIMAL }); 50 else 51 return dba.getTypeInfo(new int[] { Types.DECIMAL, Types.NUMERIC }); 52 } 53 54 public void setObject(PersistenceManager pm, PreparedStatement ps, int param, Object value) 55 { 56 try 57 { 58 if (value == null) 59 ps.setNull(param, typeInfo.dataType); 60 else 61 ps.setBigDecimal(param, new BigDecimal ((BigInteger )value)); 62 } 63 catch (SQLException e) 64 { 65 throw new JDODataStoreException("Can't set BigInteger parameter: value = " + value, e); 66 } 67 } 68 69 public Object getObject(PersistenceManager pm, ResultSet rs, int param) 70 { 71 try 72 { 73 BigDecimal value = rs.getBigDecimal(param); 74 75 if (value == null) 76 return null; 77 else 78 return value.toBigInteger(); 79 } 80 catch (SQLException e) 81 { 82 throw new JDODataStoreException("Can't get BigInteger result: param = " + param, e); 83 } 84 } 85 86 public SQLExpression newSQLLiteral(QueryStatement qs, Object value) 87 { 88 return new IntegerLiteral(qs, (BigInteger )value); 89 } 90 91 public SQLExpression newSQLExpression(QueryStatement qs, QueryStatement.QueryColumn qsc, String fieldName) 92 { 93 return new NumericExpression(qs, qsc); 94 } 95 } 96 | Popular Tags |