001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader.wizard;
023:
024: import javax.swing.JTextArea;
025:
026: import org.webdocwf.util.loader.BufferOctopusClass;
027: import org.webdocwf.util.loader.LoaderException;
028: import org.webdocwf.util.loader.generator.LoaderGenerator;
029:
030: /**
031: *
032: * ExecThread class execute thread which control LoaderGenerator application
033: * @author Radoslav Dutina
034: * @version 1.0
035: */
036: public class OctopusGeneratorThread extends Thread {
037: private OctopusGeneratorData initData;
038: // TraceDialog td = null; //trace dialog of this Thread
039: private JTextArea td;
040: private String errorMsg = null;
041:
042: private OctopusGenerator generator;
043:
044: /**
045: * Construct object ExecThread with associated parameters.
046: * @param traceArea
047: * @param initData is object which contain input parameters of wizard application
048: * @param errorMsg is error message
049: */
050: public OctopusGeneratorThread(OctopusGeneratorData initData,
051: String errorMsg, JTextArea traceArea) {
052: this .initData = initData;
053: this .errorMsg = errorMsg;
054: td = traceArea;
055: // desktop.add(td);
056: }
057:
058: /**
059: * This method append line in to trace area
060: * @param s is value which to be set
061: */
062: public void appendLine(String s) {
063: td.append(s);
064: td.getCaret().setDot(td.getText().length() - 1);
065: }
066:
067: /**
068: * Run the thread
069: */
070: public void run() {
071:
072: td.setVisible(true);
073: // td.setDefaultFocus();
074: if (errorMsg != null) {
075: appendLine(errorMsg + "\n");
076: // td.setButtonEnabled();
077: // td.setButtonName("Open");
078:
079: } else {
080: try {
081: OctopusGenerator generator = new OctopusGenerator(
082: initData);
083: String[] process = generator.generateAll();
084: GeneratorThread generatorThread = null;
085: if (process.length != 0) {
086: BufferOctopusClass.getInstance();
087: BufferOctopusClass.getInstance().setUsed();
088:
089: generatorThread = new GeneratorThread(process);
090: generatorThread.start();
091:
092: while (generatorThread.isAlive()) {
093: String value = BufferOctopusClass.getInstance()
094: .readFromBuffer();
095: if (value.indexOf("***TogetherGroop***") == -1)
096: appendLine(value + "\n");
097: else
098: break;
099: }
100: // td.setButtonEnabled();
101: } else {
102: appendLine("Some error is occur!" + "\n");
103: }
104: // td.setButtonName("Open");
105: // setTitle("Building OctopusGenerator Application (Done)");
106: generator = null;
107:
108: } catch (Exception e) {
109: appendLine(e.getMessage());
110: try {
111: Thread.sleep(100);
112: } catch (Exception ex) {
113: appendLine(ex.getMessage());
114: }
115: // td.setButtonEnabled();
116: // td.setTitle("Building OctopusGenerator Application (ERROR)");
117: // td.setButtonName("Open");
118: BufferOctopusClass.getInstance().writeToBuffer(
119: "***TogetherGroop***");
120: BufferOctopusClass.getInstance().empty();
121: System.out.println(e.getMessage());
122: }
123: BufferOctopusClass.getInstance().empty();
124: }
125: }
126:
127: /**
128: * This class creates new thread
129: */
130: class GeneratorThread extends Thread {
131: private String[] args;
132:
133: /**
134: * Initialise the thread
135: * @param args represents the arguments
136: */
137: public GeneratorThread(String[] args) {
138: this .args = args;
139: }
140:
141: /**
142: * Run the thread
143: */
144: public void run() {
145:
146: String generatorOutput = null;
147: String valueMode = null;
148: String domlUrl = null;
149: String packageName = null;
150:
151: String sourceType = null;
152: String sourceDataBase = null;
153: String sourceDriverName = null;
154: String sourceUser = null;
155: String sourcePassword = null;
156:
157: String targetType = null;
158: String targetDataBase = null;
159: String targetDriverName = null;
160: String targetUser = null;
161: String targetPassword = null;
162: //logging
163: String logDirName = null;
164: String logFileName = null;
165: String logMode = null;
166: //Output mode
167: //main
168: String generateXml = null;
169: String generateDoml = null;
170: //for generate sql
171: String generateDropTableStmt = null;
172: String generateDropIntegrityStmt = null;
173: String generateCreateTableStmt = null;
174: String generateCreatePKStmt = null;
175: String generateCreateFKStmt = null;
176: String generateCreateIndexStmt = null;
177:
178: //for genrate sql for all vendors
179: String generateSqlForAllVendors = null;
180: //optimized modes
181: String fullMode = null;
182:
183: String includeTableList = null;
184: String confJarStructure = null;
185:
186: if (args.length > 8 && args.length < 53) {
187: for (int i = 0; i < args.length - 1; i = i + 1) {
188: if (args[i].equalsIgnoreCase("-st"))
189: sourceType = args[++i];
190: else if (args[i].equalsIgnoreCase("-sdb"))
191: sourceDataBase = args[++i];
192: else if (args[i].equalsIgnoreCase("-m"))
193: valueMode = args[++i];
194: else if (args[i].equalsIgnoreCase("-o"))
195: generatorOutput = args[++i];
196: else if (args[i].equalsIgnoreCase("-sdn"))
197: sourceDriverName = args[++i];
198: else if (args[i].equalsIgnoreCase("-tdn"))
199: targetDriverName = args[++i];
200: else if (args[i].equalsIgnoreCase("-tdb"))
201: targetDataBase = args[++i];
202: if (args[i].equalsIgnoreCase("-tt"))
203: targetType = args[++i];
204: if (args[i].equalsIgnoreCase("-su"))
205: sourceUser = args[++i];
206: if (args[i].equalsIgnoreCase("-sp"))
207: sourcePassword = args[++i];
208: if (args[i].equalsIgnoreCase("-tu"))
209: targetUser = args[++i];
210: if (args[i].equalsIgnoreCase("-tp"))
211: targetPassword = args[++i];
212: if (args[i].equalsIgnoreCase("-doml"))
213: domlUrl = args[++i];
214: if (args[i].equalsIgnoreCase("-pack"))
215: packageName = args[++i];
216: if (args[i].equalsIgnoreCase("-xml"))
217: generateXml = args[++i];
218: if (args[i].equalsIgnoreCase("-gdoml"))
219: generateDoml = args[++i];
220: if (args[i].equalsIgnoreCase("-sqlCT"))
221: generateCreateTableStmt = args[++i];
222: if (args[i].equalsIgnoreCase("-sqlDT"))
223: generateDropTableStmt = args[++i];
224: if (args[i].equalsIgnoreCase("-sqlDI"))
225: generateDropIntegrityStmt = args[++i];
226: if (args[i].equalsIgnoreCase("-sqlCPK"))
227: generateCreatePKStmt = args[++i];
228: if (args[i].equalsIgnoreCase("-sqlCFK"))
229: generateCreateFKStmt = args[++i];
230: if (args[i].equalsIgnoreCase("-sqlCI"))
231: generateCreateIndexStmt = args[++i];
232: if (args[i].equalsIgnoreCase("-sqlAll"))
233: generateSqlForAllVendors = args[++i];
234: if (args[i].equalsIgnoreCase("-fm"))
235: fullMode = args[++i];
236: if (args[i].equalsIgnoreCase("-it"))
237: includeTableList = args[++i];
238: if (args[i].equalsIgnoreCase("-cjs"))
239: confJarStructure = args[++i];
240: //logging
241: if (args[i].equalsIgnoreCase("-lm"))
242: logMode = args[++i];
243: else if (args[i].equalsIgnoreCase("-l"))
244: logDirName = args[++i];
245: else if (args[i].equalsIgnoreCase("-f"))
246: logFileName = args[++i];
247: }
248: } else {
249: System.out
250: .println("You didn't enter all required parameters, for running the application!");
251: BufferOctopusClass
252: .getInstance()
253: .writeToBuffer(
254: "You didn't enter all required parameters, for running the application!");
255: printUsage();
256: }
257: try {
258:
259: LoaderGenerator generator = new LoaderGenerator(
260: sourceType, sourceDataBase, valueMode,
261: generatorOutput, sourceDriverName,
262: targetDriverName, targetDataBase, targetType,
263: sourceUser, sourcePassword, targetUser,
264: targetPassword, domlUrl, packageName,
265: generateDropTableStmt,
266: generateDropIntegrityStmt,
267: generateCreateTableStmt, generateCreatePKStmt,
268: generateCreateFKStmt, generateCreateIndexStmt,
269: generateSqlForAllVendors, generateXml,
270: generateDoml, fullMode, "false",
271: includeTableList, confJarStructure, logMode,
272: logDirName, logFileName);
273:
274: generator.generate();
275:
276: } catch (LoaderException le) {
277: //TODO zk added for testing
278: le.printStackTrace();
279: //END
280: System.out.println(le.getMessage());
281: String message = le.getMessage();
282: if (message == null || message.indexOf(-1) != -1
283: || message.indexOf(0) != -1)
284: message = "Application build fails!";
285: BufferOctopusClass.getInstance().writeToBuffer(
286: message + "\n");
287: BufferOctopusClass.getInstance().writeToBuffer(
288: "Check input parameters!" + "\n");
289: try {
290: Thread.sleep(100);
291: } catch (Exception ex) {
292: appendLine(ex.getMessage());
293: }
294: // td.setTitle("Building OctopusGenerator Application (ERROR)");
295: // td.setButtonEnabled();
296: // td.setButtonName("Open");
297: BufferOctopusClass.getInstance().writeToBuffer(
298: "***TogetherGroop***");
299: return;
300: } catch (Throwable th) {
301: BufferOctopusClass.getInstance().writeToBuffer(
302: th.getMessage());
303: try {
304: Thread.sleep(100);
305: } catch (Exception ex) {
306: appendLine(ex.getMessage());
307: }
308: // td.setTitle("Building OctopusGenerator Application (ERROR)");
309: // td.setButtonEnabled();
310: // td.setButtonName("Open");
311: BufferOctopusClass.getInstance().writeToBuffer(
312: "***TogetherGroop***");
313: th.printStackTrace(System.out);
314: return;
315: }
316: try {
317: Thread.sleep(1000);
318: } catch (Exception ex) {
319: appendLine(ex.getMessage());
320: }
321: BufferOctopusClass.getInstance().writeToBuffer(
322: "***TogetherGroop***");
323: }
324:
325: /**
326: * Help for Octopus Loader application
327: */
328: public void printUsage() {
329: System.out
330: .println("Usage: java org.webdocwf.util.loader.generator.Generator [options] ");
331: BufferOctopusClass
332: .getInstance()
333: .writeToBuffer(
334: "Usage: java org.webdocwf.util.loader.generator.Generator [options] ");
335: System.out.println(" Options:");
336: BufferOctopusClass.getInstance().writeToBuffer(" Options:");
337: System.out
338: .println(" -st sourceType, defines the type of the source database.");
339: BufferOctopusClass
340: .getInstance()
341: .writeToBuffer(
342: " -st sourceType, defines the type of the source database.");
343: System.out
344: .println(" -tt targetType, defines the type of the target database.");
345: BufferOctopusClass
346: .getInstance()
347: .writeToBuffer(
348: " -tt targetType, defines the type of the target database.");
349: System.out
350: .println(" -sdn sourceDriverName, represents driver of defined source database.");
351: BufferOctopusClass
352: .getInstance()
353: .writeToBuffer(
354: " -sdn sourceDriverName, represents driver of defined source database.");
355: System.out
356: .println(" -tdn targetDriverName, represents driver of defined target database.");
357: BufferOctopusClass
358: .getInstance()
359: .writeToBuffer(
360: " -tdn targetDriverName, represents driver of defined target database.");
361: System.out
362: .println(" -sdb sourceDatabase, defines the place where you're put the database tables");
363: BufferOctopusClass
364: .getInstance()
365: .writeToBuffer(
366: " -sdb sourceDatabase, defines the place where you're put the database tables");
367: System.out
368: .println(" -tdb targetDataBase defines the place where the target database tables are.");
369: BufferOctopusClass
370: .getInstance()
371: .writeToBuffer(
372: " -tdb targetDataBase defines the place where the target database tables are.");
373: System.out
374: .println(" -m valueMode, is the difference from overwrite and update attribute");
375: BufferOctopusClass
376: .getInstance()
377: .writeToBuffer(
378: " -m valueMode, is the difference from overwrite and update attribute");
379: System.out
380: .println(" -su sourceUser, defines the user of the source database.");
381: BufferOctopusClass
382: .getInstance()
383: .writeToBuffer(
384: " -su sourceUser, defines the user of the source database.");
385: System.out
386: .println(" -sp sourcePassword, defines user password for the source database.");
387: BufferOctopusClass
388: .getInstance()
389: .writeToBuffer(
390: " -sp sourcePassword, defines user password for the source database.");
391: System.out
392: .println(" -tu targetUser, defines the user of the target database.");
393: BufferOctopusClass
394: .getInstance()
395: .writeToBuffer(
396: " -tu targetUser, defines the user of the target database.");
397: System.out
398: .println(" -tp targetPassword, defines user password for the target database.");
399: BufferOctopusClass
400: .getInstance()
401: .writeToBuffer(
402: " -tp targetPassword, defines user password for the target database.");
403: System.out
404: .println(" -doml domlUrl, defines the place where the doml file is placed.");
405: BufferOctopusClass
406: .getInstance()
407: .writeToBuffer(
408: " -doml domlUrl, defines the place where the doml file is placed.");
409: System.out
410: .println(" -o generatorOutput, is optional. That represent the directory, where the TDT place"
411: + " created files. If this argument dont exists, TDT place created files in to current direcory!");
412: BufferOctopusClass
413: .getInstance()
414: .writeToBuffer(
415: " -o generatorOutput, is optional. That represent the directory, where the TDT place"
416: + " created files. If this argument dont exists, TDT place created files in to current direcory!");
417: System.out
418: .println(" -pack packageName, defines the package name for the generated doml file.");
419: BufferOctopusClass
420: .getInstance()
421: .writeToBuffer(
422: " -pack packageName, defines the package name for the generated doml file.");
423:
424: System.out
425: .println(" -xml generateXml, defines if you want to generate xml files as output files. "
426: + " Possible values are true and false.");
427: BufferOctopusClass
428: .getInstance()
429: .writeToBuffer(
430: " -xml generateXml, defines if you want to generate xml files as output files. "
431: + " Possible values are true and false.");
432: System.out
433: .println(" -gdoml generateDoml, defines if you want to generate doml file as output file. "
434: + " Possible values are true and false.");
435: BufferOctopusClass
436: .getInstance()
437: .writeToBuffer(
438: " -gdoml generateDoml, defines if you want to generate doml file as output file. "
439: + " Possible values are true and false.");
440: System.out
441: .println(" -sqlCT generateCreateTables, defines if you want to generate only Sql statement for CREATE TABLE.");
442: BufferOctopusClass
443: .getInstance()
444: .writeToBuffer(
445: " -sqlCT generateCreateTables, defines if you want to generate only Sql statement for CREATE TABLE.");
446:
447: System.out
448: .println(" -sqlDT generateDropTableStmt, defines if you want to generate only Sql statement for DROP TABLE.");
449: BufferOctopusClass
450: .getInstance()
451: .writeToBuffer(
452: " -sqlDT generateDropTableStmt, defines if you want to generate only Sql statement for DROP TABLE.");
453:
454: System.out
455: .println(" -sqlCPK generateCreatePrimaryKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (PRIMARY KEY).");
456: BufferOctopusClass
457: .getInstance()
458: .writeToBuffer(
459: " -sqlCPK generateCreatePrimaryKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (PRIMARY KEY).");
460:
461: System.out
462: .println(" -sqlCFK generateCreateForeigKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (FOREIGN KEY).");
463: BufferOctopusClass
464: .getInstance()
465: .writeToBuffer(
466: " -sqlCFK generateCreateForeigKeys, defines if you want to generate only Sql statement for ALTER TABLE ADD CONSTRAINT (FOREIGN KEY).");
467:
468: System.out
469: .println(" -sqlCI generateCreateIndex, defines if you want to generate only Sql statement for CREATE INDEX.");
470: BufferOctopusClass
471: .getInstance()
472: .writeToBuffer(
473: " -sqlCI generateCreateIndex, defines if you want to generate only Sql statement for CREATE INDEX.");
474:
475: System.out
476: .println(" -fm fullMode, defines the mode of output xml files. Possible values are true and false.");
477: BufferOctopusClass
478: .getInstance()
479: .writeToBuffer(
480: " -fm fullMode, defines the mode of output xml files. Possible values are true and false.");
481:
482: System.out
483: .println(" -it includeTableList, defines tables which you want to incude into Generator process.");
484: BufferOctopusClass
485: .getInstance()
486: .writeToBuffer(
487: " -it includeTableList, defines tables which you want to incude into Generator process.");
488:
489: System.out
490: .println(" -lm defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
491: BufferOctopusClass
492: .getInstance()
493: .writeToBuffer(
494: " -m defines the default logmode. Possible values are 'none', 'normal' (is the default) and 'full'.");
495:
496: System.out
497: .println(" -l defines the logfile directory. The default is the current working directory. \n");
498: BufferOctopusClass
499: .getInstance()
500: .writeToBuffer(
501: " -v defines variables used in variable columns. \n");
502:
503: System.out
504: .println(" -f defines the logfile name. The default is 'GeneratorLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
505: BufferOctopusClass
506: .getInstance()
507: .writeToBuffer(
508: " -f defines the logfile name. The default is 'GeneratorLog-YYYY-MM-DD-HH-mm-SS.txt'. \n");
509:
510: System.out.println("For more details, see documentation.");
511: BufferOctopusClass.getInstance().writeToBuffer(
512: "For more details, see documentation.");
513: }
514: }
515: }
|