1 2 26 27 package org.webdocwf.util.loader; 28 29 import java.sql.Connection ; 30 import java.sql.PreparedStatement ; 31 import java.sql.SQLException ; 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.Vector ; 35 36 import org.webdocwf.util.loader.transformation.Transformation; 37 import org.webdocwf.util.loader.transformation.Transformations; 38 39 45 public class InsertRowQuerySet { 46 private String strQuery=null; 47 private String tableName=null; 48 private String tableID=null; 49 private Vector vecRelationColumnTargetTableName=null; 50 private Vector vecRelationColumnTargetTableID=null; 51 private Vector vecRelationColumnTargetColumnName=null; 52 private Vector indexDummyInsertNull=new Vector (); 53 private Vector indexDummyInsertRelation=new Vector (); 54 private Vector indexDummyIsNotRelationsColumn=new Vector (); 55 private Vector columnNamesPstmt=new Vector (); 56 private Connection conn; 58 private String oidColumnName="oid"; 59 private String versionColumnName="version"; 60 62 63 89 public InsertRowQuerySet(Connection c, 90 Vector vecColumnNames, Vector vecColumnMode, String tableName, 91 String tableID, int iTableInt,Vector vecTempConstantColumns, 92 Vector vecVariableTimesTableName, Vector vecVariableTimesTableID, 93 Vector vecVariableTimesColumnName, Vector vecVariableColumnTargetTableName, 94 Vector vecVariableColumnTargetTableID,Vector vecVariableColumnTargetColumnName, 95 Vector vecRelationColumnTargetColumnName, Vector vecRelationColumnTargetTableName, 96 Vector vecRelationColumnTargetTableID, Vector vecRelationColumnRelationMode, 97 CounterColumns counterColumns, Transformations transformations, boolean bOidLogicValue, 98 boolean isTOS, String oidColumnName, String versionColumnName) 99 throws SQLException , NullPointerException , Exception { 100 101 this.conn=c; 102 106 this.oidColumnName=oidColumnName; 107 this.versionColumnName=versionColumnName; 108 this.tableName=tableName; 109 this.tableID=tableID; 110 this.vecRelationColumnTargetTableName=vecRelationColumnTargetTableName; 111 this.vecRelationColumnTargetTableID=vecRelationColumnTargetTableID; 112 this.vecRelationColumnTargetColumnName=vecRelationColumnTargetColumnName; 113 strQuery = "insert into " + tableName; 114 115 if(bOidLogicValue){ 116 if(isTOS){ 117 strQuery+="("+this.oidColumnName+", "; 118 columnNamesPstmt.add(this.oidColumnName); 119 120 }else{ 121 strQuery +="("+this.oidColumnName+","+this.versionColumnName+", "; 122 columnNamesPstmt.add(this.oidColumnName); 123 columnNamesPstmt.add(this.versionColumnName); 124 125 } 126 }else 127 strQuery+="("; 128 129 for (int j = 0; j < vecColumnNames.size(); j++) { 130 if (!this.isRelationColumn(vecColumnNames.get(j).toString(),iTableInt)) { 131 strQuery += vecColumnNames.get(j).toString() + ", "; 132 columnNamesPstmt.add(vecColumnNames.get(j).toString()); 133 indexDummyIsNotRelationsColumn.add(String.valueOf(j)); 134 } 135 } 136 137 for (int p = 0; p < vecTempConstantColumns.size(); p++){ 138 strQuery += vecTempConstantColumns.get(p).toString() + ", "; 139 columnNamesPstmt.add(vecTempConstantColumns.get(p).toString()); 140 } 141 142 for (int i = 0; i < vecVariableTimesTableName.size(); i++) { 143 if (vecVariableTimesTableName.get(i).toString().equalsIgnoreCase(tableName) 144 && vecVariableTimesTableID.get(i).toString().equalsIgnoreCase(tableID)) { 145 strQuery += vecVariableTimesColumnName.get(i).toString() 146 + ", "; 147 columnNamesPstmt.add(vecVariableTimesColumnName.get(i).toString()); 148 } 149 } 150 for (int i = 0; i < vecVariableColumnTargetTableName.size(); i++) { 151 if (vecVariableColumnTargetTableName.get(i).toString().equalsIgnoreCase(tableName) 152 && vecVariableColumnTargetTableID.get(i).toString().equalsIgnoreCase(tableID)) { 153 strQuery += vecVariableColumnTargetColumnName.get(i).toString() 154 + ", "; 155 columnNamesPstmt.add(vecVariableColumnTargetColumnName.get(i).toString()); 156 } 157 } 158 for (int i = 0; i < vecRelationColumnTargetColumnName.size(); i++) { 159 if (vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(tableName) 160 && vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(tableID)) { 161 strQuery += vecRelationColumnTargetColumnName.get(i).toString()+ ", "; 162 columnNamesPstmt.add(vecRelationColumnTargetColumnName.get(i).toString()); 163 } 164 } 165 166 Vector counterColNames = counterColumns.getTargetColumnName(tableName,tableID); 167 168 for (int i = 0; i < counterColNames.size(); i++) { 169 if(counterColNames.get(i)!=null) 170 strQuery += counterColNames.get(i).toString() + ", "; 171 columnNamesPstmt.add(counterColNames.get(i).toString()); 172 } 173 Vector subCounterColNames = counterColumns.getSubTargetColumnName(tableName,tableID); 174 for (int i = 0; i < subCounterColNames.size(); i++) { 175 if(subCounterColNames.get(i)!=null) 176 strQuery += subCounterColNames.get(i).toString() + ", "; 177 columnNamesPstmt.add(subCounterColNames.get(i).toString()); 178 } 179 ArrayList trans = transformations.getTransformations(); 181 Iterator iTrans = trans.iterator(); 182 183 while(iTrans.hasNext()) { 184 Transformation transformation = (Transformation)iTrans.next(); 185 Vector transColNames = transformation.getTargetColumnNames(Integer.parseInt(tableID)); 189 for (int i = 0; i < transColNames.size(); i++) { 190 if(transColNames.get(i)!=null) 191 strQuery += transColNames.get(i).toString() + ", "; 192 columnNamesPstmt.add(transColNames.get(i).toString()); 193 } 194 } 195 196 } 197 198 202 public String getStrQuery(){ 203 strQuery = strQuery.substring(0, strQuery.length() - 2); 204 return strQuery; 205 } 206 207 211 public Vector getIndexDummyIsNotRelationsColumn(){ 212 return indexDummyIsNotRelationsColumn; 213 } 214 215 220 public PreparedStatement getPreparedStatementForInsert() throws Exception { 221 222 String strPstmt="insert into "+this.tableName+" ("; 223 int count=columnNamesPstmt.size(); 224 for (int i = 0; i < count; i++) { 225 if(i!=count-1) 226 strPstmt+=columnNamesPstmt.get(i).toString()+","; 227 else 228 strPstmt+=columnNamesPstmt.get(i).toString()+")"; 229 } 230 strPstmt+=" VALUES ("; 231 for (int i = 0; i < count; i++) { 232 if(i!=count-1) 233 strPstmt+="?,"; 234 else 235 strPstmt+="?)"; 236 } 237 PreparedStatement pstmt; 238 try{ 239 pstmt = this.conn.prepareStatement(strPstmt); 240 }catch(Exception e){ 241 throw e; 242 } 243 return pstmt; 244 } 245 246 268 272 public Vector getColumnNames(){ 273 return this.columnNamesPstmt; 274 } 275 276 277 private boolean isRelationColumn (String strColumnName, int iTable) { 278 boolean bFind = false; 279 endFor: for (int i = 0; i < this.vecRelationColumnTargetTableName.size(); i++) { 280 if (this.vecRelationColumnTargetTableName.get(i).toString().equalsIgnoreCase(tableName) 281 && this.vecRelationColumnTargetTableID.get(i).toString().equalsIgnoreCase(tableID) 282 && this.vecRelationColumnTargetColumnName.get(i).toString().equalsIgnoreCase(strColumnName)) { 283 bFind = true; 284 break endFor; 285 } 286 } 287 return bFind; 288 } 289 } | Popular Tags |