1 21 22 package org.webdocwf.util.loader.wizard; 23 24 import javax.swing.JTextArea ; 25 26 import org.webdocwf.util.loader.BufferOctopusClass; 27 import org.webdocwf.util.loader.LoaderException; 28 import org.webdocwf.util.loader.generator.LoaderGenerator; 29 30 36 public class OctopusGeneratorThread extends Thread { 37 private OctopusGeneratorData initData; 38 private JTextArea td; 40 private String errorMsg = null; 41 42 private OctopusGenerator generator; 43 44 50 public OctopusGeneratorThread(OctopusGeneratorData initData, String errorMsg, JTextArea traceArea) { 51 this.initData = initData; 52 this.errorMsg = errorMsg; 53 td = traceArea; 54 } 56 57 61 public void appendLine(String s) { 62 td.append(s); 63 td.getCaret().setDot(td.getText().length() - 1); 64 } 65 66 69 public void run() { 70 71 td.setVisible(true); 72 if (errorMsg != null) { 74 appendLine(errorMsg + "\n"); 75 78 } else { 79 try { 80 OctopusGenerator generator = new OctopusGenerator(initData); 81 String [] process = generator.generateAll(); 82 GeneratorThread generatorThread = null; 83 if (process.length != 0) { 84 BufferOctopusClass.getInstance(); 85 BufferOctopusClass.getInstance().setUsed(); 86 87 generatorThread = new GeneratorThread(process); 88 generatorThread.start(); 89 90 while (generatorThread.isAlive()) { 91 String value = BufferOctopusClass.getInstance().readFromBuffer(); 92 if (value.indexOf("***TogetherGroop***") == -1) 93 appendLine(value + "\n"); 94 else 95 break; 96 } 97 } else { 99 appendLine("Some error is occur!" + "\n"); 100 } 101 generator = null; 104 105 } catch (Exception e) { 106 appendLine(e.getMessage()); 107 try { 108 Thread.sleep(100); 109 } catch (Exception ex) { 110 appendLine(ex.getMessage()); 111 } 112 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 116 BufferOctopusClass.getInstance().empty(); 117 System.out.println(e.getMessage()); 118 } 119 BufferOctopusClass.getInstance().empty(); 120 } 121 } 122 123 126 class GeneratorThread extends Thread { 127 private String [] args; 128 129 133 public GeneratorThread(String [] args) { 134 this.args = args; 135 } 136 137 140 public void run() { 141 142 String generatorOutput = null; 143 String valueMode = null; 144 String domlUrl = null; 145 String packageName = null; 146 147 String sourceType = null; 148 String sourceDataBase = null; 149 String sourceDriverName = null; 150 String sourceUser = null; 151 String sourcePassword = null; 152 153 String targetType = null; 154 String targetDataBase = null; 155 String targetDriverName = null; 156 String targetUser = null; 157 String targetPassword = null; 158 String logDirName = null; 160 String logFileName = null; 161 String logMode = null; 162 String generateXml = null; 165 String generateDoml = null; 166 String generateDropTableStmt = null; 168 String generateDropIntegrityStmt = null; 169 String generateCreateTableStmt = null; 170 String generateCreatePKStmt = null; 171 String generateCreateFKStmt = null; 172 String generateCreateIndexStmt = null; 173 174 String generateSqlForAllVendors = null; 176 String fullMode = null; 178 179 String includeTableList = null; 180 String confJarStructure = null; 181 182 if (args.length > 8 && args.length < 53) { 183 for (int i = 0; i < args.length - 1; i = i + 1) { 184 if (args[i].equalsIgnoreCase("-st")) 185 sourceType = args[++i]; 186 else if (args[i].equalsIgnoreCase("-sdb")) 187 sourceDataBase = args[++i]; 188 else if (args[i].equalsIgnoreCase("-m")) 189 valueMode = args[++i]; 190 else if (args[i].equalsIgnoreCase("-o")) 191 generatorOutput = args[++i]; 192 else if (args[i].equalsIgnoreCase("-sdn")) 193 sourceDriverName = args[++i]; 194 else if (args[i].equalsIgnoreCase("-tdn")) 195 targetDriverName = args[++i]; 196 else if (args[i].equalsIgnoreCase("-tdb")) 197 targetDataBase = args[++i]; 198 if (args[i].equalsIgnoreCase("-tt")) 199 targetType = args[++i]; 200 if (args[i].equalsIgnoreCase("-su")) 201 sourceUser = args[++i]; 202 if (args[i].equalsIgnoreCase("-sp")) 203 sourcePassword = args[++i]; 204 if (args[i].equalsIgnoreCase("-tu")) 205 targetUser = args[++i]; 206 if (args[i].equalsIgnoreCase("-tp")) 207 targetPassword = args[++i]; 208 if (args[i].equalsIgnoreCase("-doml")) 209 domlUrl = args[++i]; 210 if (args[i].equalsIgnoreCase("-pack")) 211 packageName = args[++i]; 212 if (args[i].equalsIgnoreCase("-xml")) 213 generateXml = args[++i]; 214 if (args[i].equalsIgnoreCase("-gdoml")) 215 generateDoml = args[++i]; 216 if (args[i].equalsIgnoreCase("-sqlCT")) 217 generateCreateTableStmt = args[++i]; 218 if (args[i].equalsIgnoreCase("-sqlDT")) 219 generateDropTableStmt = args[++i]; 220 if (args[i].equalsIgnoreCase("-sqlDI")) 221 generateDropIntegrityStmt = args[++i]; 222 if (args[i].equalsIgnoreCase("-sqlCPK")) 223 generateCreatePKStmt = args[++i]; 224 if (args[i].equalsIgnoreCase("-sqlCFK")) 225 generateCreateFKStmt = args[++i]; 226 if (args[i].equalsIgnoreCase("-sqlCI")) 227 generateCreateIndexStmt = args[++i]; 228 if (args[i].equalsIgnoreCase("-sqlAll")) 229 generateSqlForAllVendors = args[++i]; 230 if (args[i].equalsIgnoreCase("-fm")) 231 fullMode = args[++i]; 232 if (args[i].equalsIgnoreCase("-it")) 233 includeTableList = args[++i]; 234 if (args[i].equalsIgnoreCase("-cjs")) 235 confJarStructure = args[++i]; 236 if (args[i].equalsIgnoreCase("-lm")) 238 logMode = args[++i]; 239 else if (args[i].equalsIgnoreCase("-l")) 240 logDirName = args[++i]; 241 else if (args[i].equalsIgnoreCase("-f")) 242 logFileName = args[++i]; 243 } 244 } else { 245 System.out.println("You didn't enter all required parameters, for running the application!"); 246 BufferOctopusClass.getInstance().writeToBuffer("You didn't enter all required parameters, for running the application!"); 247 printUsage(); 248 } 249 try { 250 251 LoaderGenerator generator = new LoaderGenerator(sourceType, 252 sourceDataBase, valueMode, generatorOutput, sourceDriverName, 253 targetDriverName, targetDataBase, targetType, sourceUser, 254 sourcePassword, targetUser, targetPassword, domlUrl, packageName, 255 generateDropTableStmt, generateDropIntegrityStmt, generateCreateTableStmt, 256 generateCreatePKStmt, generateCreateFKStmt, generateCreateIndexStmt, 257 generateSqlForAllVendors, generateXml, generateDoml, fullMode, "false", 258 includeTableList, confJarStructure, logMode, logDirName, logFileName); 259 260 generator.generate(); 261 262 } catch (LoaderException le) { 263 le.printStackTrace(); 265 System.out.println(le.getMessage()); 267 String message = le.getMessage(); 268 if (message == null || message.indexOf(-1) != -1 || message.indexOf(0) != -1) 269 message = "Application build fails!"; 270 BufferOctopusClass.getInstance().writeToBuffer(message + "\n"); 271 BufferOctopusClass.getInstance().writeToBuffer("Check input parameters!" + "\n"); 272 try { 273 Thread.sleep(100); 274 } catch (Exception ex) { 275 appendLine(ex.getMessage()); 276 } 277 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 281 return; 282 } catch (Throwable th) { 283 BufferOctopusClass.getInstance().writeToBuffer(th.getMessage()); 284 try { 285 Thread.sleep(100); 286 } catch (Exception ex) { 287 appendLine(ex.getMessage()); 288 } 289 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 293 th.printStackTrace(System.out); 294 return; 295 } 296 try { 297 Thread.sleep(1000); 298 } catch (Exception ex) { 299 appendLine(ex.getMessage()); 300 } 301 BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***"); 302 } 303 304 307 public void printUsage() { 308 System.out.println("Usage: java org.webdocwf.util.loader.generator.Generator [options] "); 309 BufferOctopusClass.getInstance().writeToBuffer("Usage: java org.webdocwf.util.loader.generator.Generator [options] "); 310 System.out.println(" Options:"); 311 BufferOctopusClass.getInstance().writeToBuffer(" Options:"); 312 System.out.println(" -st sourceType, defines the type of the source database."); 313 BufferOctopusClass.getInstance().writeToBuffer(" -st sourceType, defines the type of the source database."); 314 System.out.println(" -tt targetType, defines the type of the target database."); 315 BufferOctopusClass.getInstance().writeToBuffer(" -tt targetType, defines the type of the target database."); 316 System.out.println(" -sdn sourceDriverName, represents driver of defined source database."); 317 BufferOctopusClass.getInstance().writeToBuffer(" -sdn sourceDriverName, represents driver of defined source database."); 318 System.out.println(" -tdn targetDriverName, represents driver of defined target database."); 319 BufferOctopusClass.getInstance().writeToBuffer(" -tdn targetDriverName, represents driver of defined target database."); 320 System.out.println(" -sdb sourceDatabase, defines the place where you're put the database tables"); 321 BufferOctopusClass.getInstance().writeToBuffer(" -sdb sourceDatabase, defines the place where you're put the database tables"); 322 System.out.println(" -tdb targetDataBase defines the place where the target database tables are."); 323 BufferOctopusClass.getInstance().writeToBuffer(" -tdb targetDataBase defines the place where the target database tables are."); 324 System.out.println(" -m valueMode, is the difference from overwrite and update attribute"); 325 BufferOctopusClass.getInstance().writeToBuffer(" -m valueMode, is the difference from overwrite and update attribute"); 326 System.out.println(" -su sourceUser, defines the user of the source database."); 327 BufferOctopusClass.getInstance().writeToBuffer(" -su sourceUser, defines the user of the source database."); 328 System.out.println(" -sp sourcePassword, defines user password for the source database."); 329 BufferOctopusClass.getInstance().writeToBuffer(" -sp sourcePassword, defines user password for the source database."); 330 System.out.println(" -tu targetUser, defines the user of the target database."); 331 BufferOctopusClass.getInstance().writeToBuffer(" -tu targetUser, defines the user of the target database."); 332 System.out.println(" -tp targetPassword, defines user password for the target database."); 333 BufferOctopusClass.getInstance().writeToBuffer(" -tp targetPassword, defines user password for the target database."); 334 System.out.println(" -doml domlUrl, defines the place where the doml file is placed."); 335 BufferOctopusClass.getInstance().writeToBuffer(" -doml domlUrl, defines the place where the doml file is placed."); 336 System.out.println(" -o generatorOutput, is optional. That represent the directory, where the Octopus place" + " created files. If this argument dont exists, Octopus place created files in to current direcory!"); 337 BufferOctopusClass.getInstance().writeToBuffer(" -o generatorOutput, is optional. That represent the directory, where the Octopus place" + " created files. If this argument dont exists, Octopus place created files in to current direcory!"); 338 System.out.println(" -pack packageName, defines the package name for the generated doml file."); 339 BufferOctopusClass.getInstance().writeToBuffer(" -pack packageName, defines the package name for the generated doml file."); 340 341 System.out.println(" -xml generateXml, defines if you want to generate xml files as output files. " + " Possible values are true and false."); 342 BufferOctopusClass.getInstance().writeToBuffer(" -xml generateXml, defines if you want to generate xml files as output files. " + " Possible values are true and false."); 343 System.out.println(" -gdoml generateDoml, defines if you want to generate doml file as output file. " + " Possible values are true and false."); 344 BufferOctopusClass.getInstance().writeToBuffer(" -gdoml generateDoml, defines if you want to generate doml file as output file. " + " Possible values are true and false."); 345 System.out.println(" -sqlCT generateCreateTables, defines if you want to generate only Sql statement for CREATE TABLE."); 346 BufferOctopusClass.getInstance().writeToBuffer(" -sqlCT generateCreateTables, defines if you want to generate only Sql statement for CREATE TABLE."); 347 348 System.out.println(" -sqlDT generateDropTableStmt, defines if you want to generate only Sql statement for DROP TABLE."); 349 BufferOctopusClass.getInstance().writeToBuffer(" -sqlDT generateDropTableStmt, defines if you want to generate only Sql statement for DROP TABLE."); 350 351 System.out.println(" -sqlCPK generateCreatePrimaryKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (PRIMARY KEY)."); 352 BufferOctopusClass.getInstance().writeToBuffer(" -sqlCPK generateCreatePrimaryKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (PRIMARY KEY)."); 353 354 System.out.println(" -sqlCFK generateCreateForeigKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (FOREIGN KEY)."); 355 BufferOctopusClass.getInstance().writeToBuffer(" -sqlCFK generateCreateForeigKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (FOREIGN KEY)."); 356 357 System.out.println(" -sqlCI generateCreateIndex, defines if you want to generate only Sql statement for CREATE INDEX."); 358 BufferOctopusClass.getInstance().writeToBuffer(" -sqlCI generateCreateIndex, defines if you want to generate only Sql statement for CREATE INDEX."); 359 360 System.out.println(" -fm fullMode, defines the mode of output xml files. Possible values are true and false."); 361 BufferOctopusClass.getInstance().writeToBuffer(" -fm fullMode, defines the mode of output xml files. Possible values are true and false."); 362 363 System.out.println(" -it includeTableList, defines tables which you want to incude into Generator process."); 364 BufferOctopusClass.getInstance().writeToBuffer(" -it includeTableList, defines tables which you want to incude into Generator process."); 365 366 System.out.println(" -lm defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'."); 367 BufferOctopusClass.getInstance().writeToBuffer(" -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'."); 368 369 System.out.println(" -l defines the logfile directory. The default is the current working directory. \n"); 370 BufferOctopusClass.getInstance().writeToBuffer(" -v defines variables used in variable columns. \n"); 371 372 System.out.println(" -f defines the logfile name. The default is 'GeneratorLog-YYYY-MM-DD-HH-mm-SS.txt'. \n"); 373 BufferOctopusClass.getInstance().writeToBuffer(" -f defines the logfile name. The default is 'GeneratorLog-YYYY-MM-DD-HH-mm-SS.txt'. \n"); 374 375 System.out.println("For more details, see documentation."); 376 BufferOctopusClass.getInstance().writeToBuffer("For more details, see documentation."); 377 } 378 } 379 } 380 | Popular Tags |