1 21 package oracle.toplink.essentials.internal.expressions; 23 24 import java.io.*; 25 import java.util.Vector ; 26 import java.util.Collection ; 27 28 import oracle.toplink.essentials.exceptions.*; 29 import oracle.toplink.essentials.queryframework.*; 30 import oracle.toplink.essentials.internal.sessions.AbstractSession; 31 import oracle.toplink.essentials.internal.databaseaccess.DatabaseCall; 32 33 37 public abstract class SQLModifyAllStatementForTempTable extends SQLModifyStatement { 38 public static final int CREATE_TEMP_TABLE = 0; 39 public static final int INSERT_INTO_TEMP_TABLE = 1; 40 public static final int UPDATE_ORIGINAL_TABLE = 2; 41 public static final int CLEANUP_TEMP_TABLE = 3; 42 43 protected Collection allFields; 44 protected Collection primaryKeyFields; 45 protected SQLCall selectCall; 46 protected int mode; 47 48 abstract protected Collection getUsedFields(); 49 abstract protected void writeUpdateOriginalTable(AbstractSession session, Writer writer) throws IOException; 50 51 public void setAllFields(Collection allFields) { 52 this.allFields = allFields; 53 } 54 public Collection getAllFields() { 55 return allFields; 56 } 57 public void setSelectCall(SQLCall selectCall) { 58 this.selectCall = selectCall; 59 } 60 public SQLCall getSelectCall() { 61 return selectCall; 62 } 63 public void setPrimaryKeyFields(Collection primaryKeyFields) { 64 this.primaryKeyFields = primaryKeyFields; 65 } 66 public Collection getPrimaryKeyFields() { 67 return primaryKeyFields; 68 } 69 public void setMode(int mode) { 70 this.mode = mode; 71 } 72 public int getMode() { 73 return mode; 74 } 75 76 79 public DatabaseCall buildCall(AbstractSession session) { 80 SQLCall call = new SQLCall(); 81 call.returnNothing(); 82 83 Writer writer = new CharArrayWriter(100); 84 85 try { 86 if(mode == CREATE_TEMP_TABLE) { 87 session.getPlatform().writeCreateTempTableSql(writer, table, session, 88 new Vector (getPrimaryKeyFields()), 89 getUsedFields(), 90 new Vector (getAllFields())); 91 } else if(mode == INSERT_INTO_TEMP_TABLE) { 92 session.getPlatform().writeInsertIntoTableSql(writer, table, getUsedFields()); 93 94 call.getParameters().addAll(selectCall.getParameters()); 95 call.getParameterTypes().addAll(selectCall.getParameterTypes()); 96 97 String selectStr = selectCall.getSQLString(); 98 writer.write(selectStr); 99 100 } else if(mode == UPDATE_ORIGINAL_TABLE) { 101 writeUpdateOriginalTable(session, writer); 102 } else if(mode == CLEANUP_TEMP_TABLE) { 103 session.getPlatform().writeCleanUpTempTableSql(writer, table); 104 } else { 105 } 107 108 call.setSQLString(writer.toString()); 109 110 } catch (IOException exception) { 111 throw ValidationException.fileError(exception); 112 } 113 114 return call; 115 } 116 } 117 | Popular Tags |