KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > wizard > OctopusGeneratorThread


1 /*
2 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
3
4
5     Copyright (C) 2003 Together
6
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package org.webdocwf.util.loader.wizard;
23
24 import javax.swing.JTextArea JavaDoc;
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 /**
31  *
32  * ExecThread class execute thread which control LoaderGenerator application
33  * @author Radoslav Dutina
34  * @version 1.0
35  */

36 public class OctopusGeneratorThread extends Thread JavaDoc {
37     private OctopusGeneratorData initData;
38     // TraceDialog td = null; //trace dialog of this Thread
39
private JTextArea JavaDoc td;
40     private String JavaDoc errorMsg = null;
41
42     private OctopusGenerator generator;
43
44     /**
45      * Construct object ExecThread with associated parameters.
46      * @param traceArea
47      * @param initData is object which contain input parameters of wizard application
48      * @param errorMsg is error message
49      */

50     public OctopusGeneratorThread(OctopusGeneratorData initData, String JavaDoc errorMsg, JTextArea JavaDoc traceArea) {
51         this.initData = initData;
52         this.errorMsg = errorMsg;
53         td = traceArea;
54         // desktop.add(td);
55
}
56
57     /**
58        * This method append line in to trace area
59        * @param s is value which to be set
60        */

61     public void appendLine(String JavaDoc s) {
62         td.append(s);
63         td.getCaret().setDot(td.getText().length() - 1);
64     }
65
66     /**
67      * Run the thread
68      */

69     public void run() {
70
71         td.setVisible(true);
72         // td.setDefaultFocus();
73
if (errorMsg != null) {
74             appendLine(errorMsg + "\n");
75             // td.setButtonEnabled();
76
// td.setButtonName("Open");
77

78         } else {
79             try {
80                 OctopusGenerator generator = new OctopusGenerator(initData);
81                 String JavaDoc[] 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 JavaDoc value = BufferOctopusClass.getInstance().readFromBuffer();
92                         if (value.indexOf("***TogetherGroop***") == -1)
93                             appendLine(value + "\n");
94                         else
95                             break;
96                     }
97                     // td.setButtonEnabled();
98
} else {
99                     appendLine("Some error is occur!" + "\n");
100                 }
101                 // td.setButtonName("Open");
102
// setTitle("Building OctopusGenerator Application (Done)");
103
generator = null;
104
105             } catch (Exception JavaDoc e) {
106                 appendLine(e.getMessage());
107                 try {
108                     Thread.sleep(100);
109                 } catch (Exception JavaDoc ex) {
110                     appendLine(ex.getMessage());
111                 }
112                 // td.setButtonEnabled();
113
// td.setTitle("Building OctopusGenerator Application (ERROR)");
114
// td.setButtonName("Open");
115
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
116                 BufferOctopusClass.getInstance().empty();
117                 System.out.println(e.getMessage());
118             }
119             BufferOctopusClass.getInstance().empty();
120         }
121     }
122
123     /**
124      * This class creates new thread
125      */

126     class GeneratorThread extends Thread JavaDoc {
127         private String JavaDoc[] args;
128
129         /**
130          * Initialise the thread
131          * @param args represents the arguments
132          */

133         public GeneratorThread(String JavaDoc[] args) {
134             this.args = args;
135         }
136
137         /**
138          * Run the thread
139          */

140         public void run() {
141
142             String JavaDoc generatorOutput = null;
143             String JavaDoc valueMode = null;
144             String JavaDoc domlUrl = null;
145             String JavaDoc packageName = null;
146
147             String JavaDoc sourceType = null;
148             String JavaDoc sourceDataBase = null;
149             String JavaDoc sourceDriverName = null;
150             String JavaDoc sourceUser = null;
151             String JavaDoc sourcePassword = null;
152
153             String JavaDoc targetType = null;
154             String JavaDoc targetDataBase = null;
155             String JavaDoc targetDriverName = null;
156             String JavaDoc targetUser = null;
157             String JavaDoc targetPassword = null;
158             //logging
159
String JavaDoc logDirName = null;
160             String JavaDoc logFileName = null;
161             String JavaDoc logMode = null;
162             //Output mode
163
//main
164
String JavaDoc generateXml = null;
165             String JavaDoc generateDoml = null;
166             //for generate sql
167
String JavaDoc generateDropTableStmt = null;
168             String JavaDoc generateDropIntegrityStmt = null;
169             String JavaDoc generateCreateTableStmt = null;
170             String JavaDoc generateCreatePKStmt = null;
171             String JavaDoc generateCreateFKStmt = null;
172             String JavaDoc generateCreateIndexStmt = null;
173
174             //for genrate sql for all vendors
175
String JavaDoc generateSqlForAllVendors = null;
176             //optimized modes
177
String JavaDoc fullMode = null;
178
179             String JavaDoc includeTableList = null;
180             String JavaDoc 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                         //logging
237
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                 //TODO zk added for testing
264
le.printStackTrace();
265                 //END
266
System.out.println(le.getMessage());
267                 String JavaDoc 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 JavaDoc ex) {
275                     appendLine(ex.getMessage());
276                 }
277                 // td.setTitle("Building OctopusGenerator Application (ERROR)");
278
// td.setButtonEnabled();
279
// td.setButtonName("Open");
280
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
281                 return;
282             } catch (Throwable JavaDoc th) {
283                 BufferOctopusClass.getInstance().writeToBuffer(th.getMessage());
284                 try {
285                     Thread.sleep(100);
286                 } catch (Exception JavaDoc ex) {
287                     appendLine(ex.getMessage());
288                 }
289                 // td.setTitle("Building OctopusGenerator Application (ERROR)");
290
// td.setButtonEnabled();
291
// td.setButtonName("Open");
292
BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
293                 th.printStackTrace(System.out);
294                 return;
295             }
296             try {
297                 Thread.sleep(1000);
298             } catch (Exception JavaDoc ex) {
299                 appendLine(ex.getMessage());
300             }
301             BufferOctopusClass.getInstance().writeToBuffer("***TogetherGroop***");
302         }
303
304         /**
305          * Help for Octopus Loader application
306          */

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