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 FloatMapping extends ColumnMapping 23 { 24 public FloatMapping(DatabaseAdapter dba, Class type) 25 { 26 super(dba, type); 27 28 initTypeInfo(); 29 } 30 31 public FloatMapping(Column col) 32 { 33 super(col); 34 35 col.checkPrimitive(); 36 37 initTypeInfo(); 38 } 39 40 public FloatMapping(ClassBaseTable table, int relativeFieldNumber) 41 { 42 this(table.newColumn(relativeFieldNumber)); 43 } 44 45 protected TypeInfo getTypeInfo() 46 { 47 return dba.getTypeInfo(new int[] { Types.REAL, Types.FLOAT }); 48 } 49 50 public void setFloat(PersistenceManager pm, PreparedStatement ps, int param, float value) 51 { 52 try 53 { 54 ps.setFloat(param, value); 55 } 56 catch (SQLException e) 57 { 58 throw dba.newDataStoreException("Can't set float parameter: value = " + value, e); 59 } 60 } 61 62 public float getFloat(PersistenceManager pm, ResultSet rs, int param) 63 { 64 float value; 65 66 try 67 { 68 value = rs.getFloat(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 float 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.setFloat(param, ((Float )value).floatValue()); 89 } 90 catch (SQLException e) 91 { 92 throw dba.newDataStoreException("Can't set Float 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 float f = rs.getFloat(param); 103 value = rs.wasNull() ? null : new Float (f); 104 } 105 catch (SQLException e) 106 { 107 throw dba.newDataStoreException("Can't get Float result: param = " + param, e); 108 } 109 110 return value; 111 } 112 113 public SQLExpression newSQLLiteral(QueryStatement qs, Object value) 114 { 115 return new FloatingPointLiteral(qs, (Float )value); 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 |