KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > backup > Backup


1 /*
2 Backup - class which enables you to backup 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.backup;
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  * Backup class is used for backup database of your choice.
30  * @author Radoslav Dutins
31  * @version 1.0
32  */

33 public class Backup {
34
35   private String JavaDoc generatorOutput = "";
36   private String JavaDoc sourceDatabase = "";
37   private String JavaDoc sourceUser = "";
38   private String JavaDoc sourcePassword = "";
39   private String JavaDoc sourceDatabaseType = "";
40   private String JavaDoc sourceDriverName = "";
41
42   private String JavaDoc targetDatabase = "";
43   private String JavaDoc targetUser = "";
44   private String JavaDoc targetPassword = "";
45   private String JavaDoc targetDatabaseType = "";
46   private String JavaDoc targetDriverName = "";
47
48   //sql statements
49
private String JavaDoc generateDropTableStmt = "true";
50   private String JavaDoc generateDropIntegrityStmt="true";
51   private String JavaDoc generateCreateTableStmt = "true";
52   private String JavaDoc generateCreatePKStmt = "true";
53   private String JavaDoc generateCreateFKStmt = "true";
54   private String JavaDoc generateCreateIndexStmt = "true";
55   private String JavaDoc generateSqlForAllVendors = "true";
56
57   //xml files
58
private String JavaDoc fullMode = "true";
59   private String JavaDoc generateXml = "false";
60   private String JavaDoc generateDoml = "false";
61   private String JavaDoc restoreMode="false";
62
63   private String JavaDoc valueMode="copy";
64   private String JavaDoc includeTableList="";
65   private String JavaDoc confJarStructure="";
66
67   /**
68    * Construct object Backup 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 Backup(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, String JavaDoc targetPassword,
87                 String JavaDoc includeTableList, String JavaDoc strConfJarStructure) {
88
89     this.generatorOutput = generatorOutput;
90     this.sourceDatabase = sourceDatabase;
91     this.sourceUser = sourceUser;
92     this.sourcePassword = sourcePassword;
93     this.sourceDatabaseType = sourceDatabase;
94     this.sourceDriverName = sourceDriverName;
95
96     this.targetDatabase = targetDatabase;
97     this.targetUser = targetUser;
98     this.targetPassword = targetPassword;
99     this.targetDatabaseType = targetDatabaseType;
100     this.targetDriverName = targetDriverName;
101
102     this.generateDropTableStmt = generateDropTableStmt;
103     this.generateDropIntegrityStmt = generateDropIntegrityStmt;
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 {//for All Vendors
120
LoaderGenerator loaderGenerator = new LoaderGenerator(sourceDatabaseType,
121           sourceDatabase,valueMode, generatorOutput, sourceDriverName,
122           targetDriverName, targetDatabase, targetDatabaseType, sourceUser,
123           sourcePassword, targetUser, targetPassword, null, null,
124           generateDropTableStmt,generateDropIntegrityStmt ,generateCreateTableStmt, generateCreatePKStmt,
125           generateCreateFKStmt,generateCreateIndexStmt, generateSqlForAllVendors,
126           generateXml,generateDoml,fullMode, restoreMode, includeTableList,confJarStructure);
127
128       loaderGenerator.generate();
129
130     }
131     catch (Exception JavaDoc ex) {
132       ex.printStackTrace();
133     }
134
135     try { //for specific vendor (Generator)
136

137       this.generateSqlForAllVendors = "false";
138       this.generateXml = "true";
139       this.fullMode = "false";
140
141       LoaderGenerator loaderGenerator = new LoaderGenerator(
142           sourceDatabaseType, sourceDatabase,valueMode, generatorOutput,
143           sourceDriverName,targetDriverName, targetDatabase, targetDatabaseType,
144           sourceUser,sourcePassword, targetUser, targetPassword, null, null,
145           generateDropTableStmt, generateDropIntegrityStmt,generateCreateTableStmt,
146           generateCreatePKStmt, generateCreateFKStmt,
147           generateCreateIndexStmt, generateSqlForAllVendors, generateXml,
148           generateDoml,fullMode, "false", includeTableList,confJarStructure);
149
150       loaderGenerator.generate();
151     }
152     catch (Exception JavaDoc ex) {
153       ex.printStackTrace();
154     }
155
156     try { //Octopus loader
157
String JavaDoc loadJobFileName = "";
158       if (!generatorOutput.equalsIgnoreCase("")) {
159         File JavaDoc file = new File JavaDoc(this.generatorOutput);
160         generatorOutput = file.getAbsolutePath();
161         loadJobFileName = generatorOutput +
162             System.getProperty("file.separator") + "LoaderJob.olj";
163       }
164       else {
165         loadJobFileName = "LoaderJob.olj";
166       }
167       Loader octopusLoader = new Loader(loadJobFileName,confJarStructure);
168       octopusLoader.load();
169     }
170     catch (Exception JavaDoc ex) {
171       ex.printStackTrace();
172     }
173
174   }
175
176   /**
177    *
178    * @param argv represents input parameters
179    */

180   public static void main(String JavaDoc argv[]) {
181     String JavaDoc strGeneratorOutput = "";
182     String JavaDoc strSourceDatabase = "";
183     String JavaDoc strSourceUser = "";
184     String JavaDoc strSourcePassword = "";
185     String JavaDoc strSourceDatabaseType = "";
186     String JavaDoc strSourceDriverName = "";
187
188     String JavaDoc strTargetDatabase = "";
189     String JavaDoc strTargetUser = "";
190     String JavaDoc strTargetPassword = "";
191     String JavaDoc strTargetDatabaseType = "";
192     String JavaDoc strTargetDriverName = "";
193
194     String JavaDoc strIncludeTableList="";
195     String JavaDoc strConfJarStructure="";
196
197     if (argv.length > 0 && argv.length < 28) {
198       for (int i = 0; i < argv.length - 1; i = i + 1) {
199         if (argv[i].equalsIgnoreCase("-o"))
200           strGeneratorOutput = argv[++i];
201         else if (argv[i].equalsIgnoreCase("-sdb"))
202           strSourceDatabase = argv[++i];
203         else if (argv[i].equalsIgnoreCase("-su"))
204           strSourceUser = argv[++i];
205         else if (argv[i].equalsIgnoreCase("-sp"))
206           strSourcePassword = argv[++i];
207         else if (argv[i].equalsIgnoreCase("-st"))
208           strSourceDatabaseType = argv[++i];
209         else if (argv[i].equalsIgnoreCase("-sdn"))
210           strSourceDriverName = argv[++i];
211         else if (argv[i].equalsIgnoreCase("-tdb"))
212           strTargetDatabase = argv[++i];
213         else if (argv[i].equalsIgnoreCase("-tu"))
214           strTargetUser = argv[++i];
215         else if (argv[i].equalsIgnoreCase("-tp"))
216           strTargetPassword = argv[++i];
217         else if (argv[i].equalsIgnoreCase("-tt"))
218           strTargetDatabaseType = argv[++i];
219         else if (argv[i].equalsIgnoreCase("-tdn"))
220           strTargetDriverName = argv[++i];
221         else if (argv[i].equalsIgnoreCase("-it"))
222           strIncludeTableList= argv[++i];
223         else if (argv[i].equalsIgnoreCase("-cjs"))
224           strConfJarStructure = argv[++i];
225
226       }
227
228       try {
229         Backup backup = new Backup(strSourceDatabaseType,
230                                    strSourceDatabase,
231                                    strGeneratorOutput,
232                                    strSourceDriverName,
233                                    strTargetDriverName,
234                                    strTargetDatabase,
235                                    strTargetDatabaseType,
236                                    strSourceUser,
237                                    strSourcePassword,
238                                    strTargetUser,
239                                    strTargetPassword,
240                                    strIncludeTableList,
241                                    strConfJarStructure);
242
243       }
244       catch (Exception JavaDoc ex) {
245         ex.printStackTrace();
246       }
247     }
248   }
249
250   /**
251    * This method set value of confJarStructure parameter
252    * @param confJarStructure is value of parameter
253    */

254   public void setConfJarStructure(String JavaDoc confJarStructure) {
255     this.confJarStructure = confJarStructure;
256   }
257
258   /**
259    * This method read value of confJarStructure parameter
260    * @return value of parameter
261    */

262   public String JavaDoc getConfJarStructure() {
263     return this.confJarStructure;
264   }
265
266
267   /**
268    * This method set value of generatorOutput parameter
269    * @param generatorOutput is value of parameter
270    */

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

279   public String JavaDoc getGeneratorOutput() {
280     return this.generatorOutput;
281   }
282
283   /**
284    * This method set value of sourceDatabase parameter
285    * @param sourceDatabase is value of parameter
286    */

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

295   public String JavaDoc getSourceDatabase() {
296     return this.sourceDatabase;
297   }
298
299   /**
300    * This method set value of sourceUser parameter
301    * @param sourceUser is value of parameter
302    */

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

311   public String JavaDoc getSourceUser() {
312     return this.sourceUser;
313   }
314
315   /**
316    * This method set value of sourcePassword parameter
317    * @param sourcePassword is value of parameter
318    */

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

327   public String JavaDoc getSourcePassword() {
328     return this.sourcePassword;
329   }
330
331   /**
332    * This method set value of sourceDatabaseType parameter
333    * @param sourceDatabaseType is value of parameter
334    */

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

343   public String JavaDoc getSourceDatabaseType() {
344     return this.sourceDatabaseType;
345   }
346
347   /**
348    * This method set value of sourceDriverName parameter
349    * @param sourceDriverName is value of parameter
350    */

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

359   public String JavaDoc getSourceDriverName() {
360     return this.sourceDriverName;
361   }
362
363   /**
364    * This method set value of targetDatabase parameter
365    * @param targetDatabase is value of parameter
366    */

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

375   public String JavaDoc getTargetDatabase() {
376     return this.targetDatabase;
377   }
378
379   /**
380    * This method set value of targetUser parameter
381    * @param targetUser is value of parameter
382    */

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

391   public String JavaDoc getTargetUser() {
392     return this.targetUser;
393   }
394
395   /**
396    * This method set value of targetPassword parameter
397    * @param targetPassword is value of parameter
398    */

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

407   public String JavaDoc getTargetPassword() {
408     return this.targetPassword;
409   }
410
411   /**
412    * This method set value of targetDatabaseType parameter
413    * @param targetDatabaseType is value of parameter
414    */

415   public void setTargetDatabaseType(String JavaDoc targetDatabaseType) {
416     this.targetDatabaseType = targetDatabaseType;
417   }
418
419   /**
420    * This method read value of targetDatabaseType parameter
421    * @return value of parameter
422    */

423   public String JavaDoc getTargetDatabaseType() {
424     return this.targetDatabaseType;
425   }
426
427   /**
428    * This method set value of targetDriverName parameter
429    * @param targetDriverName is value of parameter
430    */

431   public void setTargetDriverName(String JavaDoc targetDriverName) {
432     this.targetDriverName = targetDriverName;
433   }
434
435   /**
436    * This method read value of targetDriverName parameter
437    * @return value of parameter
438    */

439   public String JavaDoc getTargetDriverName() {
440     return this.targetDriverName;
441   }
442
443 }
Popular Tags