1 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 35 public class SqlElement { 36 37 private String strSqlName = ""; 38 private String strSqlOnErrorContinue = ""; 40 private String strSqlCommit = ""; 41 42 private String strDefaultLogMode = ""; 44 private boolean bOnErrorContinue; 45 private boolean bDefaultOnErrorContinue = false; 46 private boolean bDefaultCommit = true; 47 50 56 private JdbcParametersElement jdbcParametersElement; 57 private ConfigReader configReader; 58 private Logger logger; 59 private LoaderJobAttrReader loaderJobReader; 60 61 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 } 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 } 125 this.logger.write("full", "\tparseSql method is finished."); 126 return iNumTagsImportJob; 127 } 128 129 133 public void setLogger(Logger logger) { 134 this.logger = logger; 135 } 136 137 141 public void setConfigReader(ConfigReader reader) { 142 this.configReader = reader; 143 } 144 145 149 public void setJdbcParametersElement(JdbcParametersElement jdbc) { 150 this.jdbcParametersElement = jdbc; 151 } 152 153 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 184 this.strSqlOnErrorContinue = docFragment.getAttribute("onErrorContinue"); 185 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 } 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 } 232 this.logger.write("full", "\timportSQLStatement method is finished."); 233 return strValue; 234 } 235 236 255 263 267 public boolean getDefaultCommit() { 268 return this.bDefaultCommit; 269 } 270 271 275 public boolean getDefaultOnErrorContinue() { 276 return this.bDefaultOnErrorContinue; 277 } 278 279 283 public boolean getOnErrorContinue() { 284 return this.bOnErrorContinue; 285 } 286 287 291 public String getDefaultLogMode() { 292 return this.strDefaultLogMode; 293 } 294 295 299 303 307 public String getSqlCommit() { 308 return this.strSqlCommit; 309 } 310 311 315 public String getSqlOnErrorContinue() { 316 return this.strSqlOnErrorContinue; 317 } 318 319 323 327 331 public String getSqlName() { 332 return this.strSqlName; 333 } 334 335 339 public void setLoaderJob(LoaderJobAttrReader loader) { 340 this.loaderJobReader = loader; 341 } 342 343 344 345 } | Popular Tags |