1 10 11 package com.triactive.jdo.store; 12 13 import com.triactive.jdo.PersistenceManager; 14 import java.sql.PreparedStatement ; 15 import java.sql.ResultSet ; 16 import java.sql.SQLException ; 17 import java.sql.Types ; 18 import javax.jdo.JDODataStoreException; 19 20 21 public class OIDMapping extends ColumnMapping 22 { 23 private static final int LONG_MAX_DECIMAL_DIGITS = 19; 24 25 public OIDMapping(DatabaseAdapter dba, Class type) 26 { 27 super(dba, type); 28 29 initTypeInfo(); 30 } 31 32 public OIDMapping(Column col) 33 { 34 super(col); 35 36 col.checkPrimitive(); 37 38 initTypeInfo(); 39 } 40 41 public OIDMapping(ClassBaseTable table, int relativeFieldNumber) 42 { 43 this(table.newColumn(relativeFieldNumber)); 44 } 45 46 protected TypeInfo getTypeInfo() 47 { 48 return dba.getTypeInfo(new int[] { Types.BIGINT, Types.DECIMAL }); 49 } 50 51 protected void initTypeInfo() 52 { 53 super.initTypeInfo(); 54 55 59 if (col != null && typeInfo.dataType == Types.DECIMAL) 60 { 61 col.setMinimumPrecision(Math.min(typeInfo.precision, LONG_MAX_DECIMAL_DIGITS)); 62 col.checkDecimal(); 63 } 64 } 65 66 public void setObject(PersistenceManager pm, PreparedStatement ps, int param, Object value) 67 { 68 try 69 { 70 if (value == null) 71 ps.setNull(param, typeInfo.dataType); 72 else 73 ps.setLong(param, ((OID)value).longValue()); 74 } 75 catch (SQLException e) 76 { 77 throw dba.newDataStoreException("Can't set OID parameter: value = " + value, e); 78 } 79 } 80 81 public Object getObject(PersistenceManager pm, ResultSet rs, int param) 82 { 83 Object value; 84 85 try 86 { 87 long l = rs.getLong(param); 88 value = rs.wasNull() ? null : new OID(l); 89 } 90 catch (SQLException e) 91 { 92 throw dba.newDataStoreException("Can't get OID result: param = " + param, e); 93 } 94 95 return value; 96 } 97 98 public SQLExpression newSQLLiteral(QueryStatement qs, Object value) 99 { 100 return new ObjectLiteral(qs, this, value); 101 } 102 103 public SQLExpression newSQLExpression(QueryStatement qs, QueryStatement.QueryColumn qsc, String fieldName) 104 { 105 return new ObjectExpression(qs, qsc); 106 } 107 } 108 | Popular Tags |