KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > restore > Restore


1 /*
2 Restore - class which enables you to restore database of you're choice.
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.restore;
23
24 import org.webdocwf.util.loader.generator.LoaderGenerator;
25 import org.webdocwf.util.loader.Loader;
26 import java.io.File JavaDoc;
27
28
29 /**
30  * Restore class is used for restore database of your choice.
31  * @author Radoslav Dutina
32  * @version 1.0
33  */

34 public class Restore {
35
36   private String JavaDoc generatorOutput = "";
37   private String JavaDoc sourceDatabase = "";
38   private String JavaDoc sourceUser = "";
39   private String JavaDoc sourcePassword = "";
40   private String JavaDoc sourceDatabaseType = "";
41   private String JavaDoc sourceDriverName = "";
42
43   private String JavaDoc targetDatabase = "";
44   private String JavaDoc targetUser = "";
45   private String JavaDoc targetPassword = "";
46   private String JavaDoc targetDatabaseType = "";
47   private String JavaDoc targetDriverName = "";
48
49   private String JavaDoc generateDropTableStmt = "false";
50   private String JavaDoc generateDropIntegrityStmt = "false";
51   private String JavaDoc generateCreateTableStmt = "false";
52   private String JavaDoc generateCreatePKStmt = "false";
53   private String JavaDoc generateCreateFKStmt = "false";
54   private String JavaDoc generateCreateIndexStmt = "false";
55
56   private String JavaDoc generateSqlForAllVendors = "false";
57   //optimized modes
58
private String JavaDoc fullMode = "false";
59   private String JavaDoc generateXml = "true";
60   private String JavaDoc generateDoml = "false";
61   private String JavaDoc restoreMode="true";
62
63   private String JavaDoc valueMode="copy";
64   private String JavaDoc includeTableList="";
65   private String JavaDoc confJarStructure="";
66
67   /**
68    * Construct object Restore with associated parameters.
69    * @param sourceDatabaseType defines type of source database
70    * @param sourceDatabase defines url to source database
71    * @param generatorOutput defines output directory
72    * @param sourceDriverName defines name of source driver name
73    * @param targetDriverName defines name of target driver name
74    * @param targetDatabase defines url to target database
75    * @param targetDatabaseType defines type of target database
76    * @param sourceUser defines user name for source database
77    * @param sourcePassword defines user password for source database
78    * @param targetUser defines user name for target database
79    * @param targetPassword defines user password for target database
80    * @param includeTableList defines the list of tables which you want to include
81    */

82   public Restore(String JavaDoc sourceDatabaseType, String JavaDoc sourceDatabase,
83           String JavaDoc generatorOutput,String JavaDoc sourceDriverName,
84           String JavaDoc targetDriverName,String JavaDoc targetDatabase,
85           String JavaDoc targetDatabaseType, String JavaDoc sourceUser,
86           String JavaDoc sourcePassword,String JavaDoc targetUser,
87           String JavaDoc targetPassword,String JavaDoc includeTableList,
88           String JavaDoc confJarStructure) {
89
90     this.generatorOutput = generatorOutput;
91     this.sourceDatabase = sourceDatabase;
92     this.sourceUser = sourceUser;
93     this.sourcePassword = sourcePassword;
94     this.sourceDatabaseType = sourceDatabase;
95     this.sourceDriverName = sourceDriverName;
96
97     this.targetDatabase = targetDatabase;
98     this.targetUser = targetUser;
99     this.targetPassword = targetPassword;
100     this.targetDatabaseType = targetDatabaseType;
101     this.targetDriverName = targetDriverName;
102
103     this.generateDropTableStmt = generateDropTableStmt;
104     this.generateCreateTableStmt = generateCreateTableStmt;
105     this.generateCreatePKStmt = generateCreatePKStmt;
106     this.generateCreateFKStmt = generateCreateFKStmt;
107     this.generateCreateIndexStmt = generateCreateIndexStmt;
108
109     this.generateSqlForAllVendors = generateSqlForAllVendors;
110     //optimized modes
111
this.fullMode = fullMode;
112
113     this.generateXml = generateXml;
114     this.generateDoml = generateDoml;
115
116     this.includeTableList=includeTableList;
117     this.confJarStructure=confJarStructure;
118
119     try {
120       LoaderGenerator loaderGenerator = new LoaderGenerator(sourceDatabaseType,
121           sourceDatabase,
122           valueMode, generatorOutput, sourceDriverName,
123           targetDriverName, targetDatabase, targetDatabaseType, sourceUser,
124           sourcePassword, targetUser, targetPassword, null, null,
125           generateDropTableStmt,generateDropIntegrityStmt, generateCreateTableStmt, generateCreatePKStmt,
126           generateCreateFKStmt,
127           generateCreateIndexStmt, generateSqlForAllVendors, generateXml,
128           generateDoml,
129           fullMode, restoreMode, includeTableList,confJarStructure);
130       loaderGenerator.generate();
131     }
132     catch (Exception JavaDoc ex) {
133       ex.printStackTrace();
134     }
135
136     try { //Octopus loader
137
String JavaDoc loadJobFileName = "";
138       if (!generatorOutput.equalsIgnoreCase("")) {
139         File JavaDoc file = new File JavaDoc(generatorOutput);
140         generatorOutput = file.getAbsolutePath();
141         loadJobFileName = generatorOutput + System.getProperty("file.separator") +
142             "LoaderJob.olj";
143       }
144       else {
145         loadJobFileName = "LoaderJob.olj";
146       }
147       Loader octopusLoader = new Loader(loadJobFileName,confJarStructure);
148       octopusLoader.load();
149     }
150     catch (Exception JavaDoc ex) {
151       ex.printStackTrace();
152     }
153   }
154
155   /**
156    *
157    * @param argv represents input parameters
158    */

159   public static void main(String JavaDoc argv[]) {
160     String JavaDoc strGeneratorOutput = "";
161     String JavaDoc strSourceDatabase = "";
162     String JavaDoc strSourceUser = "";
163     String JavaDoc strSourcePassword = "";
164     String JavaDoc strSourceDatabaseType = "";
165     String JavaDoc strSourceDriverName = "";
166
167     String JavaDoc strTargetDatabase = "";
168     String JavaDoc strTargetUser = "";
169     String JavaDoc strTargetPassword = "";
170     String JavaDoc strTargetDatabaseType = "";
171     String JavaDoc strTargetDriverName = "";
172
173     String JavaDoc strIncludeTableList="";
174     String JavaDoc strConfJarStructure="";
175
176     if (argv.length > 0 && argv.length < 26) {
177       for (int i = 0; i < argv.length - 1; i = i + 1) {
178         if (argv[i].equalsIgnoreCase("-o"))
179           strGeneratorOutput = argv[++i];
180         else if (argv[i].equalsIgnoreCase("-sdb"))
181           strSourceDatabase = argv[++i];
182         else if (argv[i].equalsIgnoreCase("-su"))
183           strSourceUser = argv[++i];
184         else if (argv[i].equalsIgnoreCase("-sp"))
185           strSourcePassword = argv[++i];
186         else if (argv[i].equalsIgnoreCase("-st"))
187           strSourceDatabaseType = argv[++i];
188         else if (argv[i].equalsIgnoreCase("-sdn"))
189           strSourceDriverName = argv[++i];
190         else if (argv[i].equalsIgnoreCase("-tdb"))
191           strTargetDatabase = argv[++i];
192         else if (argv[i].equalsIgnoreCase("-tu"))
193           strTargetUser = argv[++i];
194         else if (argv[i].equalsIgnoreCase("-tp"))
195           strTargetPassword = argv[++i];
196         else if (argv[i].equalsIgnoreCase("-tt"))
197           strTargetDatabaseType = argv[++i];
198         else if (argv[i].equalsIgnoreCase("-tdn"))
199           strTargetDriverName = argv[++i];
200         else if (argv[i].equalsIgnoreCase("-it"))
201           strIncludeTableList = argv[++i];
202         else if (argv[i].equalsIgnoreCase("-cjs"))
203           strConfJarStructure = argv[++i];
204
205       }
206     }
207
208     try {
209       Restore restore=new Restore(strSourceDatabaseType, strSourceDatabase,
210           strGeneratorOutput, strSourceDriverName,
211           strTargetDriverName,strTargetDatabase, strTargetDatabaseType, strSourceUser,
212           strSourcePassword, strTargetUser, strTargetPassword, strIncludeTableList,
213           strConfJarStructure);
214     }
215     catch (Exception JavaDoc ex) {
216       ex.printStackTrace();
217     }
218   }
219
220   /**
221    * This method set value of confJarStructure parameter
222    * @param confJarStructure is value of parameter
223    */

224   public void setConfJarStructure(String JavaDoc confJarStructure) {
225     this.confJarStructure = confJarStructure;
226   }
227
228   /**
229    * This method read value of confJarStructure parameter
230    * @return value of parameter
231    */

232   public String JavaDoc getConfJarStructure() {
233     return this.confJarStructure;
234   }
235
236   /**
237    * This method set value of generatorOutput parameter
238    * @param generatorOutput is value of parameter
239    */

240   public void setGeneratorOutput(String JavaDoc generatorOutput) {
241     this.generatorOutput = generatorOutput;
242   }
243
244   /**
245    * This method read value of generatorOutput parameter
246    * @return value of parameter
247    */

248   public String JavaDoc getGeneratorOutput() {
249     return this.generatorOutput;
250   }
251
252   /**
253    * This method set value of sourceDatabase parameter
254    * @param sourceDatabase is value of parameter
255    */

256   public void setSourceDatabase(String JavaDoc sourceDatabase) {
257     this.sourceDatabase = sourceDatabase;
258   }
259
260   /**
261    * This method read value of sourceDatabase parameter
262    * @return value of parameter
263    */

264   public String JavaDoc getSourceDatabase() {
265     return this.sourceDatabase;
266   }
267
268   /**
269    * This method set value of sourceUser parameter
270    * @param sourceUser is value of parameter
271    */

272   public void setSourceUser(String JavaDoc sourceUser) {
273     this.sourceUser = sourceUser;
274   }
275
276   /**
277    * This method read value of sourceUser parameter
278    * @return value of parameter
279    */

280   public String JavaDoc getSourceUser() {
281     return this.sourceUser;
282   }
283
284   /**
285    * This method set value of sourcePassword parameter
286    * @param sourcePassword is value of parameter
287    */

288   public void setSourcePassword(String JavaDoc sourcePassword) {
289     this.sourcePassword = sourcePassword;
290   }
291
292   /**
293    * This method read value of sourcePassword parameter
294    * @return value of parameter
295    */

296   public String JavaDoc getSourcePassword() {
297     return this.sourcePassword;
298   }
299
300   /**
301    * This method set value of sourceDatabaseType parameter
302    * @param sourceDatabaseType is value of parameter
303    */

304   public void setSourceDatabaseType(String JavaDoc sourceDatabaseType) {
305     this.sourceDatabaseType = sourceDatabaseType;
306   }
307
308   /**
309    * This method read value of sourceDatabaseType parameter
310    * @return value of parameter
311    */

312   public String JavaDoc getSourceDatabaseType() {
313     return this.sourceDatabaseType;
314   }
315
316   /**
317    * This method set value of sourceDriverName parameter
318    * @param sourceDriverName is value of parameter
319    */

320   public void setSourceDriverName(String JavaDoc sourceDriverName) {
321     this.sourceDriverName = sourceDriverName;
322   }
323
324   /**
325    * This method read value of sourceDriverName parameter
326    * @return value of parameter
327    */

328   public String JavaDoc getSourceDriverName() {
329     return this.sourceDriverName;
330   }
331
332   /**
333    * This method set value of targetDatabase parameter
334    * @param targetDatabase is value of parameter
335    */

336   public void setTargetDatabase(String JavaDoc targetDatabase) {
337     this.targetDatabase = targetDatabase;
338   }
339
340   /**
341    * This method read value of targetDatabase parameter
342    * @return value of parameter
343    */

344   public String JavaDoc getTargetDatabase() {
345     return this.targetDatabase;
346   }
347
348   /**
349    * This method set value of targetUser parameter
350    * @param targetUser is value of parameter
351    */

352   public void setTargetUser(String JavaDoc targetUser) {
353     this.targetUser = targetUser;
354   }
355
356   /**
357    * This method read value of targetDatabase parameter
358    * @return value of parameter
359    */

360   public String JavaDoc getTargetUser() {
361     return this.targetUser;
362   }
363
364   /**
365    * This method set value of targetPassword parameter
366    * @param targetPassword is value of parameter
367    */

368   public void setTargetPassword(String JavaDoc targetPassword) {
369     this.targetPassword = targetPassword;
370   }
371
372   /**
373    * This method read value of targetPassword parameter
374    * @return value of parameter
375    */

376   public String JavaDoc getTargetPassword() {
377     return this.targetPassword;
378   }
379
380   /**
381    * This method set value of targetDatabaseType parameter
382    * @param targetDatabaseType is value of parameter
383    */

384   public void setTargetDatabaseType(String JavaDoc targetDatabaseType) {
385     this.targetDatabaseType = targetDatabaseType;
386   }
387
388   /**
389    * This method read value of targetDatabaseType parameter
390    * @return value of parameter
391    */

392   public String JavaDoc getTargetDatabaseType() {
393     return this.targetDatabaseType;
394   }
395
396   /**
397    * This method set value of targetDriverName parameter
398    * @param targetDriverName is value of parameter
399    */

400   public void setTargetDriverName(String JavaDoc targetDriverName) {
401     this.targetDriverName = targetDriverName;
402   }
403
404   /**
405    * This method read value of targetDriverName parameter
406    * @return value of parameter
407    */

408   public String JavaDoc getTargetDriverName() {
409     return this.targetDriverName;
410   }
411
412
413
414 }
Popular Tags