1 /***
2 SqlElement - Sql element in xml file.
3 Copyright (C) 2002-2003 Together
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Lesser General Public License for more details.
12 You should have received a copy of the GNU Lesser General Public
13 License along with this library; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 SqlElement.java
16 Date: 20.5.2003.
17 @version 1.0.0
18 @author: Zoran Milakovic zoran@prozone.co.yu
19 */
20
21 package org.webdocwf.util.loader;
22
23 import java.io.*;
24 import java.util.*;
25 import javax.xml.parsers.*;
26 import org.w3c.dom.*;
27 import org.webdocwf.util.loader.logging.*;
28
29 /***
30 * Class is wrapper for SqlElement tag in XML file.
31 *
32 * @author Zoran Milakovic
33 * @version 1.1
34 */
35 public class SqlElement {
36
37 private String strSqlName = "";
38 //private String strSqlLogMode = "";
39 private String strSqlOnErrorContinue = "";
40 private String strSqlCommit = "";
41
42 // String strLogMode = "";
43 private String strDefaultLogMode = "";
44 private boolean bOnErrorContinue;
45 private boolean bDefaultOnErrorContinue = false;
46 private boolean bDefaultCommit = true;
47 // private String strTargetDbVendor = "";
48 // private String strTargetDriverName = "";
49
50 // private String strJDBCTargetParameterDriver = "";
51 // private String strJDBCTargetParameterConnection = "";
52 // private String strJDBCTargetParameterUser = "";
53 // private String strJDBCTargetParameterPassword = "";
54 // private String strTargetDriverClassName = "";
55
56 private JdbcParametersElement jdbcParametersElement;
57 private ConfigReader configReader;
58 private Logger logger;
59 private LoaderJobAttrReader loaderJobReader;
60
61 /***
62 * Method parseSql is used to analyse import XML file
63 * about sql tags. Return number of sql elements in a whole xml input file.
64 * @param inStream Data from inputXML file which is converted into InputStream.
65 * @return Number of sql tags in an input XML file.
66 * @throws LoaderException
67 */
68 public int parseSql(InputStream inStream) throws LoaderException {
69 int iNumTagsImportJob = 0;
70 Document doc = null;
71 this.logger.write("full", "\tparseSql method is started.");
72 try {
73 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
74 DocumentBuilder db = null;
75 db = dbf.newDocumentBuilder();
76 doc = db.parse(inStream);
77 }
78 catch (Exception e) {
79 this.logger.write("normal", "Sorry, an error occurred: " + e);
80 LoaderException le = new LoaderException("Exception: ",
81 (Throwable) e);
82 throw le;
83 // System.exit(1);
84 }
85 if (doc != null) {
86 NodeList tagBasic = doc.getElementsByTagName("sql");
87 iNumTagsImportJob = tagBasic.getLength();
88 Vector vecNames = new Vector();
89 String strName = "";
90 for (int i = 0; i < iNumTagsImportJob; i++) {
91 strName = new String("");
92 strName = OctopusXMLUtil.importAttributeValue(doc, "sql","name",i);
93 for (int j = 0; j < vecNames.size(); j++) {
94 if (strName.equals("")) {
95 this.logger.write("normal",
96 "Sorry, an error occurred: No Sql statement name .");
97 LoaderException le = new LoaderException("Exception: ",
98 (Throwable) (new Exception(
99 "Sorry, an error occurred: No Sql statement name .")));
100 throw le;
101 }
102 if (strName.equalsIgnoreCase(vecNames.get(j).toString())) {
103 this.logger.write("normal",
104 "Sorry, an error occurred: More Sql statements with same name :"
105 + strName);
106 LoaderException le = new LoaderException("Exception: ",
107 (Throwable) (new Exception(
108 "Sorry, an error occurred: More Sql statements with same name :")));
109 throw le;
110 }
111 }
112 vecNames.addElement(strName);
113 }
114 }
115 try {
116 inStream.reset();
117 }
118 catch (IOException e) {
119 this.logger.write("normal", "Sorry, an error occurred: " + e);
120 LoaderException le = new LoaderException("IOxception: ",
121 (Throwable) e);
122 throw le;
123 // System.exit(1);
124 }
125 this.logger.write("full", "\tparseSql method is finished.");
126 return iNumTagsImportJob;
127 }
128
129 /***
130 * This method set value of logger parameter
131 * @param logger is value of parameter
132 */
133 public void setLogger(Logger logger) {
134 this.logger = logger;
135 }
136
137 /***
138 * This method set value of echo parameter
139 * @param reader is value of parameter
140 */
141 public void setConfigReader(ConfigReader reader) {
142 this.configReader = reader;
143 }
144
145 /***
146 * This method set value of jdbcParametersElement parameter
147 * @param jdbc is value of parameter
148 */
149 public void setJdbcParametersElement(JdbcParametersElement jdbc) {
150 this.jdbcParametersElement = jdbc;
151 }
152
153 /***
154 * Method importSQLStatement imports sql attributes from xml file and puts them in the global variables.
155 * Return Vector. It's elements are strings which represents sql statements.
156 * @param inStream Data from inputXML file which is converted into InputStream.
157 * @param iSqlItem Number of sql tag in XML file which will be analised.
158 * @return vector
159 * @throws LoaderException
160 */
161 public Vector importSQLStatement(InputStream inStream, int iSqlItem) throws LoaderException {
162 Vector strValue = new Vector();
163 Vector vecJDBCTargetValue = new Vector();
164 Vector vecJDBCTargetName = new Vector();
165 Document doc = null;
166 String strNodeValue = "";
167 this.logger.write("full", "\timportSQLStatement method is started.");
168 try {
169 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
170 DocumentBuilder db = null;
171 db = dbf.newDocumentBuilder();
172 doc = db.parse(inStream);
173 if (doc != null) {
174 NodeList tagBasic = doc.getElementsByTagName("sql");
175 if (tagBasic.getLength() != 0) {
176 Element docFragment = (Element) tagBasic.item(iSqlItem);
177 this.strSqlName = docFragment.getAttribute("name");
178 /*
179 this.strSqlLogMode = docFragment.getAttribute("logMode");
180 if (this.strSqlLogMode.equals("")) {
181 this.strSqlLogMode = loaderJobReader.getDefaultLogMode();
182 }
183 */
184 this.strSqlOnErrorContinue = docFragment.getAttribute("onErrorContinue");
185 // if (this.strSqlOnErrorContinue.equals("")) {
186 // if (this.bOnErrorContinue == true)
187 // this.strSqlOnErrorContinue = "true";
188 // else
189 // this.strSqlOnErrorContinue = (new Boolean(this.bDefaultOnErrorContinue)).toString();
190 // }
191
192
193 this.strSqlCommit = docFragment.getAttribute("commit");
194 if (this.strSqlCommit.equals("")) {
195 this.strSqlCommit = (new Boolean(this.bDefaultCommit)).toString();
196 }
197 String strReturnCode = docFragment.getAttribute("returnCode");
198 if (!strReturnCode.equals("")) {
199 ReturnCode.setErrorReturnCode(Integer.parseInt(strReturnCode));
200 }
201 else
202 ReturnCode.setErrorReturnCode(ReturnCode.getDefaultErrorReturnCode());
203
204 NodeList targetTag = docFragment.getElementsByTagName("sqlStmt");
205 for (int i = 0; i < targetTag.getLength(); i++) {
206 NodeList nodeText = targetTag.item(i).getChildNodes();
207 if (nodeText.item(0) != null) {
208 strNodeValue = nodeText.item(0).getNodeValue();
209 strValue.addElement(strNodeValue);
210 }
211 }
212 }
213 }
214 }
215 catch (Exception e) {
216 this.logger.write("normal", "Sorry, an error occurred: " + e);
217 LoaderException le = new LoaderException("Exception: ",
218 (Throwable) e);
219 throw le;
220 // System.exit(1);
221 }
222 try {
223 inStream.reset();
224 }
225 catch (IOException e) {
226 this.logger.write("normal", "Sorry, an error occurred: " + e);
227 LoaderException le = new LoaderException("IOException: ",
228 (Throwable) e);
229 throw le;
230 // System.exit(1);
231 }
232 this.logger.write("full", "\timportSQLStatement method is finished.");
233 return strValue;
234 }
235
236 // public String getTargetDriverClassName() {
237 // return this.strTargetDriverClassName;
238 // }
239 // public String getJDBCTargetParameterPassword() {
240 // return this.strJDBCTargetParameterPassword;
241 // }
242 //
243 // public String getJDBCTargetParameterUser() {
244 // return this.strJDBCTargetParameterUser;
245 // }
246 //
247 // public String getJDBCTargetParameterConnection() {
248 // return this.strJDBCTargetParameterConnection;
249 // }
250 //
251 // public String getJDBCTargetParameterDriver() {
252 // return this.strJDBCTargetParameterDriver;
253 // }
254
255 // public String getTargetDriverName() {
256 // return this.strTargetDriverName;
257 // }
258 //
259 // public String getTargetDbVendor() {
260 // return this.strTargetDbVendor;
261 // }
262
263 /***
264 * This method read value of bDefaultCommit parameter
265 * @return default value for attribute Commit
266 */
267 public boolean getDefaultCommit() {
268 return this.bDefaultCommit;
269 }
270
271 /***
272 * This method read value of bDefaultOnErrorContinue parameter
273 * @return default value for attribute OnErrorContinue
274 */
275 public boolean getDefaultOnErrorContinue() {
276 return this.bDefaultOnErrorContinue;
277 }
278
279 /***
280 * This method read value of bOnErrorContinue parameter
281 * @return value for attribute OnErrorContinue
282 */
283 public boolean getOnErrorContinue() {
284 return this.bOnErrorContinue;
285 }
286
287 /***
288 * This method read value of strDefaultLogMode parameter
289 * @return default value for attribute LogMode
290 */
291 public String getDefaultLogMode() {
292 return this.strDefaultLogMode;
293 }
294
295 /***
296 * This method read value of strLogMode parameter
297 * @return value for attribute LogMode
298 */
299 // public String getLogMode() {
300 // return this.strLogMode;
301 // }
302
303 /***
304 * This method read value of strSqlCommit parameter
305 * @return value for attribute SqlCommit
306 */
307 public String getSqlCommit() {
308 return this.strSqlCommit;
309 }
310
311 /***
312 * This method read value of strSqlOnErrorContinue parameter
313 * @return value for attribute SqlOnErrorContinue
314 */
315 public String getSqlOnErrorContinue() {
316 return this.strSqlOnErrorContinue;
317 }
318
319 /***
320 * This method read value of strSqlLogMode parameter
321 * @return value for attribute SqlLogMode
322 */
323 // public String getSqlLogMode() {
324 // return this.strSqlLogMode;
325 // }
326
327 /***
328 * This method read value of strSqlName parameter
329 * @return value for attribute SqlName
330 */
331 public String getSqlName() {
332 return this.strSqlName;
333 }
334
335 /***
336 * Set LoaderJobAttrReader object
337 * @param loader LoaderJobAttrReader object,which stores loaderJob tag attributes
338 */
339 public void setLoaderJob(LoaderJobAttrReader loader) {
340 this.loaderJobReader = loader;
341 }
342
343
344
345 }
This page was automatically generated by Maven