1
2 /*
3 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
4
5
6 Copyright (C) 2003 Together
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 package org.webdocwf.util.loader.generator;
24
25 import java.io.BufferedWriter;
26 import java.io.File;
27 import java.io.FileWriter;
28 import java.io.Writer;
29 import java.util.Vector;
30
31 import org.webdocwf.util.loader.LoaderException;
32 import org.webdocwf.util.loader.logging.Logger;
33 import org.webdocwf.util.loader.logging.StandardLogger;
34
35 /***
36 *
37 * WriteSqlFiles class creates sql files from input data.
38 * @author Radoslav Dutina
39 * @version 1.0
40 */
41 public class WriteSqlFiles {
42 private Logger logger;
43
44 /***
45 * Construct object WriteSqlFiles with associated parameters.
46 * @param generatorParameters represents the references to InputParameter object.
47 * @param tableName is name of the table form which we retrieve data.
48 * @param i is the number of tables in generatorOutput directories.
49 * @param importDefinitionAttributes is references to ImportDefinitionAttributes object.
50 * @param relationshipsAttributes is references to RelationshipsAttributes object.
51 * @throws LoaderException
52 */
53
54 public WriteSqlFiles(String tableName, int i, ImportDefinitionAttributes importDefinitionAttributes, RelationshipsAttributes relationshipsAttributes, InputParameters generatorParameters) throws LoaderException {
55 setLogger();
56 this.logger.write("full", "WriteSqlFiles is started.");
57 Writer out;
58 SqlTagAttributes sqlTagAttributes = null;
59 String nameSQL;
60 Vector sqlStatement = generatorParameters.getSqlToGenerate();
61 try {
62 File sqlFile = null;
63 if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) {
64 sqlFile = new File("sql");
65 } else {
66 sqlFile = new File(generatorParameters.getGeneratorOutput() + "/sql");
67 }
68 if (!sqlFile.exists())
69 sqlFile.mkdirs();
70 int x = 0;
71 while (x < 6) {
72 if (sqlStatement.get(x) != null) {
73 sqlTagAttributes = new SqlTagAttributes(x);
74 nameSQL = sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/") + 1, sqlTagAttributes.getHref().lastIndexOf("."));
75 SqlStatements sqlStatements = new SqlStatements(nameSQL, tableName, importDefinitionAttributes, relationshipsAttributes, i, generatorParameters);
76 String lineSeparator = System.getProperty("line.separator");
77 String[] lines = sqlStatements.getCreateStream();
78
79 if (i == 0) {
80 //this is the first time, that we are write sql files.
81 out = new BufferedWriter(new FileWriter(sqlFile + sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/")), false));
82 } else {
83 out = new BufferedWriter(new FileWriter(sqlFile + sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/")), true));
84 }
85 for (int k = 0; k < lines.length; k++) {
86 out.write(lines[k]);
87 out.write(lineSeparator);
88 }
89 out.close();
90 }
91 x++;
92
93 } //end while
94 } catch (Exception e) {
95 String msg = "Exception in class WriteSqlFiles: Error has occurred when trying to write sql file!";
96 LoaderException le = new LoaderException(msg + "\n" + e.getMessage(), (Throwable) e);
97 this.logger.write("full","Exception:"+ msg + "\n" + le.getStackTraceAsString());
98 throw le;
99 }
100 this.logger.write("full", "WriteSqlFiles is finished.");
101
102 }
103 /***
104 * This method will set logger object
105 * @param logger
106 */
107 private void setLogger() {
108 this.logger = StandardLogger.getCentralLogger();
109 }
110 }
This page was automatically generated by Maven