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 javax.jdo.JDOFatalInternalException; 17 18 19 30 31 public abstract class ColumnMapping extends Mapping 32 { 33 protected final Column col; 34 35 protected TypeInfo typeInfo; 36 37 public ColumnMapping(DatabaseAdapter dba, Class type) 38 { 39 super(dba, type); 40 this.col = null; 41 } 42 43 public ColumnMapping(Column col) 44 { 45 super(col.getStoreManager().getDatabaseAdapter(), col.getType()); 46 this.col = col; 47 } 48 49 protected abstract TypeInfo getTypeInfo(); 50 51 protected void initTypeInfo() 52 { 53 TypeInfo typeInfo = getTypeInfo(); 54 55 if (typeInfo == null) 56 throw new UnsupportedDataTypeException("No suitable JDBC type found for column " + col); 57 58 if (this.typeInfo != null) 59 throw new IllegalStateException ("JDBC type already selected for column " + col); 60 61 this.typeInfo = typeInfo; 62 63 if (col != null) 64 col.setTypeInfo(typeInfo); 65 } 66 67 public Column getColumn() 68 { 69 return col; 70 } 71 72 public String getSQLInsertionValue() 73 { 74 return "?"; 75 } 76 77 public String getSQLUpdateValue() 78 { 79 return "?"; 80 } 81 82 public SQLExpression newSQLExpression(QueryStatement qs, TableExpression te, String fieldName) 83 { 84 if (col == null) 85 throw new JDOFatalInternalException("Mapping has no specific column: " + this); 86 87 return newSQLExpression(qs, qs.getColumn(te, col), fieldName); 88 } 89 90 protected String failureMessage(String method) 91 { 92 return "Somehow " + getClass().getName() + "." + method + "() was called, which should not have been possible"; 93 } 94 95 public void setBoolean(PersistenceManager pm, PreparedStatement ps, int param, boolean value) 96 { 97 throw new JDOFatalInternalException(failureMessage("setBoolean")); 98 } 99 100 public boolean getBoolean(PersistenceManager pm, ResultSet rs, int column) 101 { 102 throw new JDOFatalInternalException(failureMessage("setBoolean")); 103 } 104 105 public void setChar(PersistenceManager pm, PreparedStatement ps, int param, char value) 106 { 107 throw new JDOFatalInternalException(failureMessage("setChar")); 108 } 109 110 public char getChar(PersistenceManager pm, ResultSet rs, int column) 111 { 112 throw new JDOFatalInternalException(failureMessage("getChar")); 113 } 114 115 public void setByte(PersistenceManager pm, PreparedStatement ps, int param, byte value) 116 { 117 throw new JDOFatalInternalException(failureMessage("setByte")); 118 } 119 120 public byte getByte(PersistenceManager pm, ResultSet rs, int column) 121 { 122 throw new JDOFatalInternalException(failureMessage("getByte")); 123 } 124 125 public void setShort(PersistenceManager pm, PreparedStatement ps, int param, short value) 126 { 127 throw new JDOFatalInternalException(failureMessage("setShort")); 128 } 129 130 public short getShort(PersistenceManager pm, ResultSet rs, int column) 131 { 132 throw new JDOFatalInternalException(failureMessage("getShort")); 133 } 134 135 public void setInt(PersistenceManager pm, PreparedStatement ps, int param, int value) 136 { 137 throw new JDOFatalInternalException(failureMessage("setInt")); 138 } 139 140 public int getInt(PersistenceManager pm, ResultSet rs, int column) 141 { 142 throw new JDOFatalInternalException(failureMessage("getInt")); 143 } 144 145 public void setLong(PersistenceManager pm, PreparedStatement ps, int param, long value) 146 { 147 throw new JDOFatalInternalException(failureMessage("setLong")); 148 } 149 150 public long getLong(PersistenceManager pm, ResultSet rs, int column) 151 { 152 throw new JDOFatalInternalException(failureMessage("getLong")); 153 } 154 155 public void setFloat(PersistenceManager pm, PreparedStatement ps, int param, float value) 156 { 157 throw new JDOFatalInternalException(failureMessage("setFloat")); 158 } 159 160 public float getFloat(PersistenceManager pm, ResultSet rs, int column) 161 { 162 throw new JDOFatalInternalException(failureMessage("getFloat")); 163 } 164 165 public void setDouble(PersistenceManager pm, PreparedStatement ps, int param, double value) 166 { 167 throw new JDOFatalInternalException(failureMessage("setDouble")); 168 } 169 170 public double getDouble(PersistenceManager pm, ResultSet rs, int column) 171 { 172 throw new JDOFatalInternalException(failureMessage("getDouble")); 173 } 174 175 public void setString(PersistenceManager pm, PreparedStatement ps, int param, String value) 176 { 177 throw new JDOFatalInternalException(failureMessage("setString")); 178 } 179 180 public String getString(PersistenceManager pm, ResultSet rs, int column) 181 { 182 throw new JDOFatalInternalException(failureMessage("getString")); 183 } 184 185 public void setObject(PersistenceManager pm, PreparedStatement ps, int param, Object value) 186 { 187 throw new JDOFatalInternalException(failureMessage("setObject")); 188 } 189 190 public Object getObject(PersistenceManager pm, ResultSet rs, int column) 191 { 192 throw new JDOFatalInternalException(failureMessage("getObject")); 193 } 194 195 public boolean equals(Object obj) 196 { 197 if (this == obj) 198 return true; 199 200 if (!(obj instanceof ColumnMapping)) 201 return false; 202 203 ColumnMapping cm = (ColumnMapping)obj; 204 205 return getClass().equals(cm.getClass()) 206 && dba.equals(cm.dba) 207 && (col == null ? cm.col == null : col.equals(cm.col)) 208 && (typeInfo == null ? cm.typeInfo == null : typeInfo.equals(cm.typeInfo)); 209 } 210 211 public int hashCode() 212 { 213 return dba.hashCode() 214 ^ (col == null ? 0 : col.hashCode()) 215 ^ (typeInfo == null ? 0 : typeInfo.hashCode()); 216 } 217 } 218 | Popular Tags |