001: /*
002: Backup - class which enables you to backup database of you're choice.
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.backup;
023:
024: import org.webdocwf.util.loader.generator.LoaderGenerator;
025: import org.webdocwf.util.loader.Loader;
026: import java.io.File;
027:
028: /**
029: * Backup class is used for backup database of your choice.
030: * @author Radoslav Dutins
031: * @version 1.0
032: */
033: public class Backup {
034:
035: private String generatorOutput = "";
036: private String sourceDatabase = "";
037: private String sourceUser = "";
038: private String sourcePassword = "";
039: private String sourceDatabaseType = "";
040: private String sourceDriverName = "";
041:
042: private String targetDatabase = "";
043: private String targetUser = "";
044: private String targetPassword = "";
045: private String targetDatabaseType = "";
046: private String targetDriverName = "";
047:
048: //sql statements
049: private String generateDropTableStmt = "true";
050: private String generateDropIntegrityStmt = "true";
051: private String generateCreateTableStmt = "true";
052: private String generateCreatePKStmt = "true";
053: private String generateCreateFKStmt = "true";
054: private String generateCreateIndexStmt = "true";
055: private String generateSqlForAllVendors = "true";
056:
057: //xml files
058: private String fullMode = "true";
059: private String generateXml = "false";
060: private String generateDoml = "false";
061: private String restoreMode = "false";
062:
063: private String valueMode = "copy";
064: private String includeTableList = "";
065: private String confJarStructure = "";
066:
067: /**
068: * Construct object Backup with associated parameters.
069: * @param sourceDatabaseType defines type of source database
070: * @param sourceDatabase defines url to source database
071: * @param generatorOutput defines output directory
072: * @param sourceDriverName defines name of source driver name
073: * @param targetDriverName defines name of target driver name
074: * @param targetDatabase defines url to target database
075: * @param targetDatabaseType defines type of target database
076: * @param sourceUser defines user name for source database
077: * @param sourcePassword defines user password for source database
078: * @param targetUser defines user name for target database
079: * @param targetPassword defines user password for target database
080: * @param includeTableList defines the list of tables which you want to include
081: */
082: public Backup(String sourceDatabaseType, String sourceDatabase,
083: String generatorOutput, String sourceDriverName,
084: String targetDriverName, String targetDatabase,
085: String targetDatabaseType, String sourceUser,
086: String sourcePassword, String targetUser,
087: String targetPassword, String includeTableList,
088: String strConfJarStructure) {
089:
090: this .generatorOutput = generatorOutput;
091: this .sourceDatabase = sourceDatabase;
092: this .sourceUser = sourceUser;
093: this .sourcePassword = sourcePassword;
094: this .sourceDatabaseType = sourceDatabase;
095: this .sourceDriverName = sourceDriverName;
096:
097: this .targetDatabase = targetDatabase;
098: this .targetUser = targetUser;
099: this .targetPassword = targetPassword;
100: this .targetDatabaseType = targetDatabaseType;
101: this .targetDriverName = targetDriverName;
102:
103: this .generateDropTableStmt = generateDropTableStmt;
104: this .generateDropIntegrityStmt = generateDropIntegrityStmt;
105: this .generateCreateTableStmt = generateCreateTableStmt;
106: this .generateCreatePKStmt = generateCreatePKStmt;
107: this .generateCreateFKStmt = generateCreateFKStmt;
108: this .generateCreateIndexStmt = generateCreateIndexStmt;
109:
110: this .generateSqlForAllVendors = generateSqlForAllVendors;
111: //optimized modes
112: this .fullMode = fullMode;
113:
114: this .generateXml = generateXml;
115: this .generateDoml = generateDoml;
116:
117: this .includeTableList = includeTableList;
118: this .confJarStructure = confJarStructure;
119:
120: try {//for All Vendors
121: LoaderGenerator loaderGenerator = new LoaderGenerator(
122: sourceDatabaseType, sourceDatabase, valueMode,
123: generatorOutput, sourceDriverName,
124: targetDriverName, targetDatabase,
125: targetDatabaseType, sourceUser, sourcePassword,
126: targetUser, targetPassword, null, null,
127: generateDropTableStmt, generateDropIntegrityStmt,
128: generateCreateTableStmt, generateCreatePKStmt,
129: generateCreateFKStmt, generateCreateIndexStmt,
130: generateSqlForAllVendors, generateXml,
131: generateDoml, fullMode, restoreMode,
132: includeTableList, confJarStructure);
133:
134: loaderGenerator.generate();
135:
136: } catch (Exception ex) {
137: ex.printStackTrace();
138: }
139:
140: try { //for specific vendor (Generator)
141:
142: this .generateSqlForAllVendors = "false";
143: this .generateXml = "true";
144: this .fullMode = "false";
145:
146: LoaderGenerator loaderGenerator = new LoaderGenerator(
147: sourceDatabaseType, sourceDatabase, valueMode,
148: generatorOutput, sourceDriverName,
149: targetDriverName, targetDatabase,
150: targetDatabaseType, sourceUser, sourcePassword,
151: targetUser, targetPassword, null, null,
152: generateDropTableStmt, generateDropIntegrityStmt,
153: generateCreateTableStmt, generateCreatePKStmt,
154: generateCreateFKStmt, generateCreateIndexStmt,
155: generateSqlForAllVendors, generateXml,
156: generateDoml, fullMode, "false", includeTableList,
157: confJarStructure);
158:
159: loaderGenerator.generate();
160: } catch (Exception ex) {
161: ex.printStackTrace();
162: }
163:
164: try { //Octopus loader
165: String loadJobFileName = "";
166: if (!generatorOutput.equalsIgnoreCase("")) {
167: File file = new File(this .generatorOutput);
168: generatorOutput = file.getAbsolutePath();
169: loadJobFileName = generatorOutput
170: + System.getProperty("file.separator")
171: + "LoaderJob.olj";
172: } else {
173: loadJobFileName = "LoaderJob.olj";
174: }
175: Loader octopusLoader = new Loader(loadJobFileName,
176: confJarStructure);
177: octopusLoader.load();
178: } catch (Exception ex) {
179: ex.printStackTrace();
180: }
181:
182: }
183:
184: /**
185: *
186: * @param argv represents input parameters
187: */
188: public static void main(String argv[]) {
189: String strGeneratorOutput = "";
190: String strSourceDatabase = "";
191: String strSourceUser = "";
192: String strSourcePassword = "";
193: String strSourceDatabaseType = "";
194: String strSourceDriverName = "";
195:
196: String strTargetDatabase = "";
197: String strTargetUser = "";
198: String strTargetPassword = "";
199: String strTargetDatabaseType = "";
200: String strTargetDriverName = "";
201:
202: String strIncludeTableList = "";
203: String strConfJarStructure = "";
204:
205: if (argv.length > 0 && argv.length < 28) {
206: for (int i = 0; i < argv.length - 1; i = i + 1) {
207: if (argv[i].equalsIgnoreCase("-o"))
208: strGeneratorOutput = argv[++i];
209: else if (argv[i].equalsIgnoreCase("-sdb"))
210: strSourceDatabase = argv[++i];
211: else if (argv[i].equalsIgnoreCase("-su"))
212: strSourceUser = argv[++i];
213: else if (argv[i].equalsIgnoreCase("-sp"))
214: strSourcePassword = argv[++i];
215: else if (argv[i].equalsIgnoreCase("-st"))
216: strSourceDatabaseType = argv[++i];
217: else if (argv[i].equalsIgnoreCase("-sdn"))
218: strSourceDriverName = argv[++i];
219: else if (argv[i].equalsIgnoreCase("-tdb"))
220: strTargetDatabase = argv[++i];
221: else if (argv[i].equalsIgnoreCase("-tu"))
222: strTargetUser = argv[++i];
223: else if (argv[i].equalsIgnoreCase("-tp"))
224: strTargetPassword = argv[++i];
225: else if (argv[i].equalsIgnoreCase("-tt"))
226: strTargetDatabaseType = argv[++i];
227: else if (argv[i].equalsIgnoreCase("-tdn"))
228: strTargetDriverName = argv[++i];
229: else if (argv[i].equalsIgnoreCase("-it"))
230: strIncludeTableList = argv[++i];
231: else if (argv[i].equalsIgnoreCase("-cjs"))
232: strConfJarStructure = argv[++i];
233:
234: }
235:
236: try {
237: Backup backup = new Backup(strSourceDatabaseType,
238: strSourceDatabase, strGeneratorOutput,
239: strSourceDriverName, strTargetDriverName,
240: strTargetDatabase, strTargetDatabaseType,
241: strSourceUser, strSourcePassword,
242: strTargetUser, strTargetPassword,
243: strIncludeTableList, strConfJarStructure);
244:
245: } catch (Exception ex) {
246: ex.printStackTrace();
247: }
248: }
249: }
250:
251: /**
252: * This method set value of confJarStructure parameter
253: * @param confJarStructure is value of parameter
254: */
255: public void setConfJarStructure(String confJarStructure) {
256: this .confJarStructure = confJarStructure;
257: }
258:
259: /**
260: * This method read value of confJarStructure parameter
261: * @return value of parameter
262: */
263: public String getConfJarStructure() {
264: return this .confJarStructure;
265: }
266:
267: /**
268: * This method set value of generatorOutput parameter
269: * @param generatorOutput is value of parameter
270: */
271: public void setGeneratorOutput(String 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 getTargetDriverName() {
440: return this.targetDriverName;
441: }
442:
443: }
|