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