📄 configreader.java
字号:
/**
ConfigReader - Read vales from config files for specified database.
Copyright (C) 2002-2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ConfigReader.java
Date: 20.5.2003.
*/
package org.webdocwf.util.loader;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.webdocwf.util.loader.logging.*;
import java.util.Hashtable;
/**
* Class read configuration parameters from configuration XML file.
*
* @author Zoran Milakovic, Radoslav Dutina
* @version 1.1
*/
public class ConfigReader {
private Logger logger;
private String strVendorFileName = null;
private String strDriverClassName = "";
private int iFirstColumnResult = 1;
private boolean bRequiredUser = false;
private boolean bEnableJumpResult = false;
private boolean bAfterLastRow = true;
private boolean bEnableOrderBy = false;
private boolean bRowCountEnabled = false;
private boolean bSetFetchSizeEnabled = false;
private String oidDbType = "";
private String versionDbType = "";
private String oidColumnName = "oid";
private String versionColumnName = "version";
//This is default date format.
//private String dateFormat = "MM/dd/yyyy hh:mm:ss";
private String dateFormat = "yyyy-MM-dd";
private boolean bSetCursorNameEnabled = false;
private boolean bSetEmptyStringAsNull = false;
private boolean bReadingOrderRelevant = false;
private boolean bGetColumnsSupported = false;
private boolean bSetMaxRowsSupported = false;
private String bConnectionPrefix = "";
private boolean bFileSystemDatabase = false;
private String confJarStructure = "";
private boolean useSeparateConfFiles = false;
private Hashtable javaTypeMapp = new Hashtable();
//ZK added this 6.5.2004
private Hashtable isNumberMapp = new Hashtable();
private Hashtable isBinaryObjectMap = new Hashtable();
private Hashtable isDateMap = new Hashtable();
//end
private String currentDriverName = "";
private String currentDatabaseName = "";
private static final String BYTE_ARRAY="1";
private static final String JAVA_MATH_BIGDECIMAL="2";
private static final String JAVA_LANG_DOUBLE="3";
private static final String JAVA_LANG_FLOAT="4";
private static final String JAVA_LANG_INTEGER="5";
private static final String JAVA_LANG_LONG="6";
private static final String JAVA_LANG_SHORT="7";
private static final String JAVA_LANG_STRING="8";
private static final String JAVA_SQL_DATE="9";
private static final String JAVA_SQL_TIME="10";
private static final String JAVA_SQL_TIMESTAMP="11";
private static final String JAVA_LANG_BOOLEAN="12";
private static final String JAVA_LANG_BYTE="13";
private static final String JAVA_LANG_OBJECT="14";
/**Method readConfigValues read specific values for desired database(dbVendor) and
* puts them into global variables. Third parameter in this method describes which database is analysed (target or source)
* Method reads values from Loader.conf configuration file (XML format).
* @param dbVendor - String - type of source database (table);
* @param strType - String - type of Loader database (source or target);
* @param driverName is name of the driver
* @throws LoaderException
*/
public void readConfigValues(String dbVendor, String driverName,
String strType) throws LoaderException {
Document doc = null;
this.logger.write("full", "\treadConfigValues method is started.");
if(this.javaTypeMapp.size()>0)
this.javaTypeMapp.clear();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
db = dbf.newDocumentBuilder();
String OCTOPUS_HOME = System.getProperty("OCTOPUS_HOME");
String databaseConfFile = null;
InputStream confFile = null;
File configFile = null;
//sinisa - Octopus supports mssql and msql values for dbVendor element
if (dbVendor.equalsIgnoreCase("mssql"))
dbVendor = "MSQL";
if (dbVendor.equalsIgnoreCase("Hsqldb"))
dbVendor = "HypersonicSQL";
if (this.strVendorFileName != null && !this.strVendorFileName.equals("")) {
configFile = new File(this.strVendorFileName);
if (configFile.exists()) {
doc = db.parse(configFile);
}
} else {
if (OCTOPUS_HOME != null) {
if (! (OCTOPUS_HOME.endsWith("\\") || OCTOPUS_HOME.endsWith("/")))
OCTOPUS_HOME += "/";
configFile = new File(OCTOPUS_HOME + "conf/OctopusDBVendors.xml");
if (configFile.exists())
doc = db.parse(configFile);
} else {
if (this.useSeparateConfFiles) {
confFile = this.getClass().getClassLoader().getResourceAsStream(
this.confJarStructure + "/OctopusDBVendors.xml");
} else {
confFile = this.getClass().getClassLoader().getResourceAsStream(
"xml/conf/OctopusDBVendors.xml");
}
if (confFile != null)
doc = db.parse(confFile);
}
}
if (doc != null) {
NodeList tagConfFile = doc.getElementsByTagName("Vendor");
out:for (int i = 0; i < tagConfFile.getLength(); i++) {
Node nodeMain = tagConfFile.item(i);
NamedNodeMap attrs = nodeMain.getAttributes();
Node nodeDriver = attrs.getNamedItem("name");
if (nodeDriver != null &&
nodeDriver.getFirstChild().getNodeValue().
equalsIgnoreCase(dbVendor)) {
databaseConfFile = nodeMain.getFirstChild().getNodeValue();
break out;
}
}
} else {
//if driver name don't exists use default for source i target
if (strType.equalsIgnoreCase("source"))
databaseConfFile = "CsvConf.xml";
else
databaseConfFile = "MSQLConf.xml";
}
doc = null;
if (OCTOPUS_HOME == null) {
if (this.useSeparateConfFiles) {
confFile = getClass().getClassLoader().getResourceAsStream(
this.confJarStructure + "/" + databaseConfFile);
} else {
confFile = getClass().getClassLoader().getResourceAsStream(
"xml/conf/" + databaseConfFile);
}
if (confFile != null)
doc = db.parse(confFile);
} else {
if (databaseConfFile != null)
configFile = new File(databaseConfFile);
else
configFile = new File("null");
if (configFile.exists()) {
doc = db.parse(configFile);
}
}
if (doc == null) {
if (strType.equalsIgnoreCase("source")) {
this.logger.write("normal",
"Failed to load config file for source database, load default configuration.");
this.strDriverClassName = "org.relique.jdbc.csv.CsvDriver";
this.iFirstColumnResult = 1;
this.bRequiredUser = false;
this.bEnableJumpResult = false;
this.bAfterLastRow = true;
this.bEnableOrderBy = false;
if (driverName == null || driverName.equals(""))
driverName = "csv";
this.bFileSystemDatabase = true;
} else {
this.logger.write("normal",
"Failed to load config file for target database, load default configuration.");
this.strDriverClassName = "com.newatlanta.jturbo.driver.Driver";
this.iFirstColumnResult = 1;
this.bRequiredUser = true;
if (driverName == null || driverName.equals(""))
driverName = "jTurbo";
}
}
}
catch (Exception e) {
this.logger.write("normal", "Sorry, an error occurred: " + e.getMessage());
LoaderException le = new LoaderException("Exception: ", (Throwable)e);
throw le;
}
String strDriverName = "";
if (doc != null) {
if (driverName == null || driverName.equalsIgnoreCase("")) {
if (dbVendor.equalsIgnoreCase("MSQL"))
driverName = "jTurbo";
}
//oid db type
NodeList tagOidDbType = doc.getElementsByTagName("OidDbType");
this.oidDbType = tagOidDbType.item(0).getFirstChild().getNodeValue();
NodeList tagVersionDbType = doc.getElementsByTagName("VersionDbType");
this.versionDbType = tagVersionDbType.item(0).getFirstChild().getNodeValue();
NodeList tagOidColumnName = doc.getElementsByTagName("OidDbColumnName");
this.oidColumnName = tagOidColumnName.item(0).getFirstChild().getNodeValue();
NodeList tagVersionColumnName = doc.getElementsByTagName("VersionDbColumnName");
this.versionColumnName = tagVersionColumnName.item(0).getFirstChild().getNodeValue();
NodeList tagDateFormat = doc.getElementsByTagName("DateFormat");
Node tempChildNode = tagDateFormat.item(0).getFirstChild();
if (tempChildNode != null ){
String tmpDate = tagDateFormat.item(0).getFirstChild().getNodeValue();
this.dateFormat = tmpDate;
}
//if(strType.equalsIgnoreCase("target")){
NodeList tagJavaType = doc.getElementsByTagName("SQLType");
Node nodeJavaTMain = tagJavaType.item(0);
NodeList dataTypeNodes = nodeJavaTMain.getChildNodes();
String nodeAttrIsNumber = "";
String nodeAttrIsBinary = "";
String nodeAttrIsDate = "";
for (int i = 0; i < dataTypeNodes.getLength(); i++) {
if (dataTypeNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
String nodeName = dataTypeNodes.item(i).getNodeName();
String nodeAttr = dataTypeNodes.item(i).getAttributes()
.getNamedItem("javaType").getNodeValue();
//ZK added this 6.5.2004
if (dataTypeNodes.item(i).getAttributes().getNamedItem("isNumber")!=null){
nodeAttrIsNumber = dataTypeNodes.item(i).getAttributes().getNamedItem("isNumber").getNodeValue();
}else{
nodeAttrIsNumber = "false";
}
if (dataTypeNodes.item(i).getAttributes().getNamedItem("isBinary")!=null){
nodeAttrIsBinary = dataTypeNodes.item(i).getAttributes().getNamedItem("isBinary").getNodeValue();
}else{
nodeAttrIsBinary = "false";
}
if (dataTypeNodes.item(i).getAttributes().getNamedItem("isDate")!=null){
nodeAttrIsDate = dataTypeNodes.item(i).getAttributes().getNamedItem("isDate").getNodeValue();
}else{
nodeAttrIsDate = "false";
}
//end
String nodeAttrInt;
if (nodeAttr.equalsIgnoreCase("byte[]"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -