001: /*
002: Restore - class which enables you to restore 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.restore;
023:
024: import org.webdocwf.util.loader.generator.LoaderGenerator;
025: import org.webdocwf.util.loader.Loader;
026: import java.io.File;
027:
028: /**
029: * Restore class is used for restore database of your choice.
030: * @author Radoslav Dutina
031: * @version 1.0
032: */
033: public class Restore {
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: private String generateDropTableStmt = "false";
049: private String generateDropIntegrityStmt = "false";
050: private String generateCreateTableStmt = "false";
051: private String generateCreatePKStmt = "false";
052: private String generateCreateFKStmt = "false";
053: private String generateCreateIndexStmt = "false";
054:
055: private String generateSqlForAllVendors = "false";
056: //optimized modes
057: private String fullMode = "false";
058: private String generateXml = "true";
059: private String generateDoml = "false";
060: private String restoreMode = "true";
061:
062: private String valueMode = "copy";
063: private String includeTableList = "";
064: private String confJarStructure = "";
065:
066: /**
067: * Construct object Restore with associated parameters.
068: * @param sourceDatabaseType defines type of source database
069: * @param sourceDatabase defines url to source database
070: * @param generatorOutput defines output directory
071: * @param sourceDriverName defines name of source driver name
072: * @param targetDriverName defines name of target driver name
073: * @param targetDatabase defines url to target database
074: * @param targetDatabaseType defines type of target database
075: * @param sourceUser defines user name for source database
076: * @param sourcePassword defines user password for source database
077: * @param targetUser defines user name for target database
078: * @param targetPassword defines user password for target database
079: * @param includeTableList defines the list of tables which you want to include
080: */
081: public Restore(String sourceDatabaseType, String sourceDatabase,
082: String generatorOutput, String sourceDriverName,
083: String targetDriverName, String targetDatabase,
084: String targetDatabaseType, String sourceUser,
085: String sourcePassword, String targetUser,
086: String targetPassword, String includeTableList,
087: String confJarStructure) {
088:
089: this .generatorOutput = generatorOutput;
090: this .sourceDatabase = sourceDatabase;
091: this .sourceUser = sourceUser;
092: this .sourcePassword = sourcePassword;
093: this .sourceDatabaseType = sourceDatabase;
094: this .sourceDriverName = sourceDriverName;
095:
096: this .targetDatabase = targetDatabase;
097: this .targetUser = targetUser;
098: this .targetPassword = targetPassword;
099: this .targetDatabaseType = targetDatabaseType;
100: this .targetDriverName = targetDriverName;
101:
102: this .generateDropTableStmt = generateDropTableStmt;
103: this .generateCreateTableStmt = generateCreateTableStmt;
104: this .generateCreatePKStmt = generateCreatePKStmt;
105: this .generateCreateFKStmt = generateCreateFKStmt;
106: this .generateCreateIndexStmt = generateCreateIndexStmt;
107:
108: this .generateSqlForAllVendors = generateSqlForAllVendors;
109: //optimized modes
110: this .fullMode = fullMode;
111:
112: this .generateXml = generateXml;
113: this .generateDoml = generateDoml;
114:
115: this .includeTableList = includeTableList;
116: this .confJarStructure = confJarStructure;
117:
118: try {
119: LoaderGenerator loaderGenerator = new LoaderGenerator(
120: sourceDatabaseType, sourceDatabase, valueMode,
121: generatorOutput, sourceDriverName,
122: targetDriverName, targetDatabase,
123: targetDatabaseType, sourceUser, sourcePassword,
124: targetUser, targetPassword, null, null,
125: generateDropTableStmt, generateDropIntegrityStmt,
126: generateCreateTableStmt, generateCreatePKStmt,
127: generateCreateFKStmt, generateCreateIndexStmt,
128: generateSqlForAllVendors, generateXml,
129: generateDoml, fullMode, restoreMode,
130: includeTableList, confJarStructure);
131: loaderGenerator.generate();
132: } catch (Exception ex) {
133: ex.printStackTrace();
134: }
135:
136: try { //Octopus loader
137: String loadJobFileName = "";
138: if (!generatorOutput.equalsIgnoreCase("")) {
139: File file = new File(generatorOutput);
140: generatorOutput = file.getAbsolutePath();
141: loadJobFileName = generatorOutput
142: + System.getProperty("file.separator")
143: + "LoaderJob.olj";
144: } else {
145: loadJobFileName = "LoaderJob.olj";
146: }
147: Loader octopusLoader = new Loader(loadJobFileName,
148: confJarStructure);
149: octopusLoader.load();
150: } catch (Exception ex) {
151: ex.printStackTrace();
152: }
153: }
154:
155: /**
156: *
157: * @param argv represents input parameters
158: */
159: public static void main(String argv[]) {
160: String strGeneratorOutput = "";
161: String strSourceDatabase = "";
162: String strSourceUser = "";
163: String strSourcePassword = "";
164: String strSourceDatabaseType = "";
165: String strSourceDriverName = "";
166:
167: String strTargetDatabase = "";
168: String strTargetUser = "";
169: String strTargetPassword = "";
170: String strTargetDatabaseType = "";
171: String strTargetDriverName = "";
172:
173: String strIncludeTableList = "";
174: String 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,
210: strSourceDatabase, strGeneratorOutput,
211: strSourceDriverName, strTargetDriverName,
212: strTargetDatabase, strTargetDatabaseType,
213: strSourceUser, strSourcePassword, strTargetUser,
214: strTargetPassword, strIncludeTableList,
215: strConfJarStructure);
216: } catch (Exception ex) {
217: ex.printStackTrace();
218: }
219: }
220:
221: /**
222: * This method set value of confJarStructure parameter
223: * @param confJarStructure is value of parameter
224: */
225: public void setConfJarStructure(String confJarStructure) {
226: this .confJarStructure = confJarStructure;
227: }
228:
229: /**
230: * This method read value of confJarStructure parameter
231: * @return value of parameter
232: */
233: public String getConfJarStructure() {
234: return this .confJarStructure;
235: }
236:
237: /**
238: * This method set value of generatorOutput parameter
239: * @param generatorOutput is value of parameter
240: */
241: public void setGeneratorOutput(String generatorOutput) {
242: this .generatorOutput = generatorOutput;
243: }
244:
245: /**
246: * This method read value of generatorOutput parameter
247: * @return value of parameter
248: */
249: public String getGeneratorOutput() {
250: return this .generatorOutput;
251: }
252:
253: /**
254: * This method set value of sourceDatabase parameter
255: * @param sourceDatabase is value of parameter
256: */
257: public void setSourceDatabase(String sourceDatabase) {
258: this .sourceDatabase = sourceDatabase;
259: }
260:
261: /**
262: * This method read value of sourceDatabase parameter
263: * @return value of parameter
264: */
265: public String getSourceDatabase() {
266: return this .sourceDatabase;
267: }
268:
269: /**
270: * This method set value of sourceUser parameter
271: * @param sourceUser is value of parameter
272: */
273: public void setSourceUser(String sourceUser) {
274: this .sourceUser = sourceUser;
275: }
276:
277: /**
278: * This method read value of sourceUser parameter
279: * @return value of parameter
280: */
281: public String getSourceUser() {
282: return this .sourceUser;
283: }
284:
285: /**
286: * This method set value of sourcePassword parameter
287: * @param sourcePassword is value of parameter
288: */
289: public void setSourcePassword(String sourcePassword) {
290: this .sourcePassword = sourcePassword;
291: }
292:
293: /**
294: * This method read value of sourcePassword parameter
295: * @return value of parameter
296: */
297: public String getSourcePassword() {
298: return this .sourcePassword;
299: }
300:
301: /**
302: * This method set value of sourceDatabaseType parameter
303: * @param sourceDatabaseType is value of parameter
304: */
305: public void setSourceDatabaseType(String sourceDatabaseType) {
306: this .sourceDatabaseType = sourceDatabaseType;
307: }
308:
309: /**
310: * This method read value of sourceDatabaseType parameter
311: * @return value of parameter
312: */
313: public String getSourceDatabaseType() {
314: return this .sourceDatabaseType;
315: }
316:
317: /**
318: * This method set value of sourceDriverName parameter
319: * @param sourceDriverName is value of parameter
320: */
321: public void setSourceDriverName(String sourceDriverName) {
322: this .sourceDriverName = sourceDriverName;
323: }
324:
325: /**
326: * This method read value of sourceDriverName parameter
327: * @return value of parameter
328: */
329: public String getSourceDriverName() {
330: return this .sourceDriverName;
331: }
332:
333: /**
334: * This method set value of targetDatabase parameter
335: * @param targetDatabase is value of parameter
336: */
337: public void setTargetDatabase(String targetDatabase) {
338: this .targetDatabase = targetDatabase;
339: }
340:
341: /**
342: * This method read value of targetDatabase parameter
343: * @return value of parameter
344: */
345: public String getTargetDatabase() {
346: return this .targetDatabase;
347: }
348:
349: /**
350: * This method set value of targetUser parameter
351: * @param targetUser is value of parameter
352: */
353: public void setTargetUser(String targetUser) {
354: this .targetUser = targetUser;
355: }
356:
357: /**
358: * This method read value of targetDatabase parameter
359: * @return value of parameter
360: */
361: public String getTargetUser() {
362: return this .targetUser;
363: }
364:
365: /**
366: * This method set value of targetPassword parameter
367: * @param targetPassword is value of parameter
368: */
369: public void setTargetPassword(String targetPassword) {
370: this .targetPassword = targetPassword;
371: }
372:
373: /**
374: * This method read value of targetPassword parameter
375: * @return value of parameter
376: */
377: public String getTargetPassword() {
378: return this .targetPassword;
379: }
380:
381: /**
382: * This method set value of targetDatabaseType parameter
383: * @param targetDatabaseType is value of parameter
384: */
385: public void setTargetDatabaseType(String targetDatabaseType) {
386: this .targetDatabaseType = targetDatabaseType;
387: }
388:
389: /**
390: * This method read value of targetDatabaseType parameter
391: * @return value of parameter
392: */
393: public String getTargetDatabaseType() {
394: return this .targetDatabaseType;
395: }
396:
397: /**
398: * This method set value of targetDriverName parameter
399: * @param targetDriverName is value of parameter
400: */
401: public void setTargetDriverName(String targetDriverName) {
402: this .targetDriverName = targetDriverName;
403: }
404:
405: /**
406: * This method read value of targetDriverName parameter
407: * @return value of parameter
408: */
409: public String getTargetDriverName() {
410: return this.targetDriverName;
411: }
412:
413: }
|