1 2 12 package com.versant.core.jdbc.metadata; 13 14 import com.versant.core.metadata.FieldMetaData; 15 import com.versant.core.metadata.parser.JdoField; 16 import com.versant.core.jdbc.sql.JdbcNameGenerator; 17 import com.versant.core.jdbc.sql.SqlDriver; 18 import com.versant.core.jdbc.sql.exp.ColumnExp; 19 import com.versant.core.jdbc.sql.exp.SelectExp; 20 import com.versant.core.jdbc.sql.exp.SqlExp; 21 import com.versant.core.jdbc.query.JdbcJDOQLCompiler; 22 import com.versant.core.jdbc.fetch.FetchOp; 23 import com.versant.core.jdbc.fetch.FetchSpec; 24 import com.versant.core.jdbc.fetch.FetchOptions; 25 import com.versant.core.server.PersistGraph; 26 import com.versant.core.util.CharBuf; 27 import com.versant.core.jdo.query.Node; 28 import com.versant.core.common.State; 29 30 import java.io.Serializable ; 31 import java.io.PrintStream ; 32 import java.util.ArrayList ; 33 import java.util.HashSet ; 34 import java.sql.PreparedStatement ; 35 import java.sql.SQLException ; 36 import java.sql.Connection ; 37 38 import com.versant.core.common.*; 39 40 45 public abstract class JdbcField implements Serializable { 46 47 50 public static final int USE_JOIN_NO = 1; 51 54 public static final int USE_JOIN_OUTER = 2; 55 58 public static final int USE_JOIN_INNER = 3; 59 60 63 public FieldMetaData fmd; 64 67 public int stateFieldNo; 68 71 public JdbcColumn[] mainTableCols; 72 75 public JdbcColumn[] mainTableColsForUpdate; 76 79 public JdbcTable mainTable; 80 84 public boolean fake; 85 90 public int useJoin; 91 96 public boolean includeForChangedLocking; 97 98 101 public void nameColumns(String tableName, JdbcNameGenerator nameGen) { 102 } 103 104 107 public void addConstraints(ArrayList cons) { 108 } 109 110 113 public void initMainTableCols() { 114 } 115 116 120 public void initMainTableColsForUpdate() { 121 if (mainTableCols == null) return; 122 123 mainTableColsForUpdate = new JdbcColumn[mainTableCols.length]; 126 int c = 0; 127 for (int i = 0; i < mainTableCols.length; i++) { 128 JdbcColumn col = mainTableCols[i]; 129 if (col.isForUpdate()) mainTableColsForUpdate[c++] = col; 130 } 131 if (c == 0) { 132 mainTableColsForUpdate = null; 133 } else if (c < mainTableCols.length) { 134 JdbcColumn[] a = new JdbcColumn[c]; 135 System.arraycopy(mainTableColsForUpdate, 0, a, 0, c); 136 mainTableColsForUpdate = a; 137 } 138 } 139 140 143 public void addMainTableCols(ArrayList a) { 144 } 145 146 149 public void setMainTable(JdbcTable table) { 150 mainTable = table; 151 } 152 153 public String toString() { 154 String n = getClass().getName(); 155 n = n.substring(n.lastIndexOf('.') + 1); 156 return n + " " + fmd.type.getName() + " " + fmd.classMetaData.getShortName() + 157 "." + fmd.name + (fake ? " FAKE" : ""); 158 } 159 160 163 public static String toUseJoinString(int useJoin) { 164 switch (useJoin) { 165 case USE_JOIN_NO: 166 return "NO"; 167 case USE_JOIN_INNER: 168 return "INNER"; 169 case USE_JOIN_OUTER: 170 return "OUTER"; 171 } 172 return "unknown(" + useJoin + ")"; 173 } 174 175 179 public String getContext() { 180 JdoField jf = fmd.jdoField; 181 if (jf != null) return jf.getContext(); 182 return fmd.classMetaData.jdoClass.getContext(); 183 } 184 185 188 public void getTables(HashSet tables) { 189 } 191 192 195 public int getUseKeyJoin() { 196 return 0; 197 } 198 199 public void dump() { 200 dump(Debug.OUT, ""); 201 } 202 203 public void dump(PrintStream out, String indent) { 204 out.println(indent + this); 205 String is = indent + " "; 206 out.println(is + "useJoin " + toUseJoinString(useJoin)); 207 out.println(is + "stateFieldNo " + stateFieldNo); 208 if (mainTableCols != null) { 209 out.println(is + mainTableCols.length + " mainTableCols(s)"); 210 for (int i = 0; i < mainTableCols.length; i++) { 211 out.println(is + "[" + i + "] " + mainTableCols[i]); 212 } 213 } 214 if (mainTableColsForUpdate != null) { 215 out.println( 216 is + mainTableColsForUpdate.length + " mainTableColsForUpdate(s)"); 217 for (int i = 0; i < mainTableColsForUpdate.length; i++) { 218 out.println(is + "[" + i + "] " + mainTableColsForUpdate[i]); 219 } 220 } 221 } 222 223 228 public boolean appendUpdate(CharBuf s, State state) { 229 return false; 230 } 231 232 236 public void appendWhere(CharBuf s, SqlDriver sqlDriver) { 237 } 238 239 244 public void appendWhereIsNull(CharBuf s, SqlDriver sqlDriver) { 245 } 246 247 250 public void appendInsertColumnList(CharBuf s) { 251 } 252 253 258 public boolean appendInsertValueList(CharBuf s, State state) { 259 return false; 260 } 261 262 266 public ColumnExp toColumnExp(SelectExp se, boolean joinToSuper) { 267 return null; 268 } 269 270 276 public ColumnExp toColumnExpForNullLiteralCompare(SelectExp se) { 277 return toColumnExp(se, true); 278 } 279 280 283 public SqlExp toIsEmptySqlExp(JdbcJDOQLCompiler comp, SelectExp root) { 284 throw BindingSupportImpl.getInstance().runtime("isEmpty() may not be called on " + 285 fmd.getQName()); 286 } 287 288 291 public SqlExp toContainsSqlExp(JdbcJDOQLCompiler comp, SelectExp root, 292 Node args) { 293 throw BindingSupportImpl.getInstance().runtime("contains(...) may not be called on " + 294 fmd.getQName()); 295 } 296 297 300 public SqlExp toContainsKeySqlExp(JdbcJDOQLCompiler comp, SelectExp root, 301 Node args) { 302 throw BindingSupportImpl.getInstance().runtime("containsKey(...) may not be called on " + 303 fmd.getQName()); 304 } 305 306 312 public int setQueryParam(PreparedStatement ps, int firstParam, 313 Object value) 314 throws SQLException { 315 throw BindingSupportImpl.getInstance().internal( 316 "set called on " + this); 317 } 318 319 323 public void persistPass2Block(PersistGraph graph, int blockStart, 324 int blockEnd, CharBuf s, Connection con, boolean batchInserts, 325 boolean batchUpdates) 326 throws SQLException { 327 throw BindingSupportImpl.getInstance().internal( 328 "persistPass2Block called on " + this); 329 } 330 331 335 public void deletePass2Block(DeletePacket graph, int blockStart, 336 int blockEnd, CharBuf s, Connection con, boolean batch) 337 throws SQLException { 338 throw BindingSupportImpl.getInstance().internal( 339 "deletePass2Block called on " + this); 340 } 341 342 345 public boolean isOracleStyleLOB() { 346 return false; 347 } 348 349 352 public void nameLinkTableIndexes(JdbcNameGenerator namegen) { 353 } 354 355 359 public JdbcColumn findMainTableColumn(String columnName) { 360 if (mainTableCols == null) return null; 361 for (int i = mainTableCols.length - 1; i >= 0; i--) { 362 JdbcColumn c = mainTableCols[i]; 363 if (c.name.equals(columnName)) return c; 364 } 365 return null; 366 } 367 368 371 public SqlDriver getSqlDriver() { 372 return ((JdbcClass)fmd.classMetaData.storeClass).sqlDriver; 373 } 374 375 378 public RuntimeException mapException(Throwable cause, 379 String message) { 380 return getSqlDriver().mapException(cause, message, true); 381 } 382 383 387 public ColumnExp createOwningTableColumnExpList(SelectExp se) { 388 return null; 389 } 390 391 394 public void prepareFetch(FetchSpec spec, FetchOptions options) { 395 } 396 397 } 398 399 400 | Popular Tags |