📄 jdbcparameterselement.java
字号:
package org.webdocwf.util.loader;
/**
JdbcParametersElement - Element in parallel to importDefinitions and sql's.
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
JdbcParametersElement.java
Date: 20.5.2003.
@version 1.0.0
@author: Zoran Milakovic zoran@prozone.co.yu
*/
import java.io.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.webdocwf.util.loader.logging.*;
/**
*
* JdbcParametersElement class sets the jdbc parameters
* @author Radoslav Dutina
* @version 1.0
*/
public class JdbcParametersElement {
private String strJDBCSourceParameterDriver = "";
private String strJDBCTargetParameterDriver = "";
private String strJDBCSourceParameterConnection = "";
private String strJDBCTargetParameterConnection = "";
private String strJDBCSourceParameterUser = "";
private String strJDBCTargetParameterUser = "";
private String strJDBCSourceParameterPassword = "";
private String strJDBCTargetParameterPassword = "";
private String strJDBCDefaultSourceParameterDriver = "";
private String strJDBCDefaultTargetParameterDriver = "";
private String strJDBCDefaultSourceParameterConnection = "";
private String strJDBCDefaultTargetParameterConnection = "";
private String strJDBCDefaultSourceParameterUser = "";
private String strJDBCDefaultTargetParameterUser = "";
private String strJDBCDefaultSourceParameterPassword = "";
private String strJDBCDefaultTargetParameterPassword = "";
private String strDbVendor = "";
private String strDriverName = "";
private String strTargetDbVendor = "";
private String strTargetDriverName = "";
private String strDbVendorDefault = "";
private String strDriverNameDefault = "";
private String strTargetDbVendorDefault = "";
private String strTargetDriverNameDefault = "";
private Logger logger;
private Vector targetConnections;
private String loaderJobFile="";
private ConfigReader configReaderSource;
/**
* Method parseTargetJDBCParameters is used to analyse import XML file
* @param inStream Data from inputXML file which is converted into InputStream.
* @throws LoaderException
*/
public void parseTargetJDBCParameters(InputStream inStream) throws LoaderException{
Document doc = null;
targetConnections=new Vector();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
db = dbf.newDocumentBuilder();
doc = db.parse(inStream);
} catch (Exception e) {
this.logger.write("normal", "Sorry, an error occurred: " + e);
LoaderException le = new LoaderException("Exception: ",
(Throwable)e);
throw le;
}
if (doc != null) {
NodeList targetList = doc.getElementsByTagName( "jdbcTargetParameters" );
int position=0;
if(targetList.getLength()!=0){
for(int i=0;i<targetList.getLength();i++){
targetConnections.add(position,"");
targetConnections.add(position+1,"");
targetConnections.add(position+2,"");
targetConnections.add(position+3,"");
NodeList childs=targetList.item(i).getChildNodes();
for(int k=0;k<childs.getLength();k++){
if(childs.item(k).getNodeType()==3){
//
}else{
NamedNodeMap attributes= childs.item(k).getAttributes();
String name=attributes.getNamedItem("name").getNodeValue();
if(name.equalsIgnoreCase("JdbcDriver"))
targetConnections.set(position,attributes.getNamedItem("value").getNodeValue());
else if(name.equalsIgnoreCase("Connection.Url")){
targetConnections.set(position+1,attributes.getNamedItem("value").getNodeValue());
}else if(name.equalsIgnoreCase("User"))
targetConnections.set(position+2,attributes.getNamedItem("value").getNodeValue());
else if(name.equalsIgnoreCase("Password"))
targetConnections.set(position+3,attributes.getNamedItem("value").getNodeValue());
}
}
position=position+4;
}
}
}
try {
inStream.reset();
} catch (IOException e) {
this.logger.write("normal", "Sorry, an error occurred: " + e);
LoaderException le = new LoaderException("IOException: ",(Throwable)e);
throw le;
}
}
/**
* This method read the value of targetConnections parameter
* @return value of parameter
*/
public Vector getTargetConnections(){
return targetConnections;
}
/**
* Method parseImportJDBCParameters is used to analyse import XML file
* about JDBC parameters tags. Puts values of first importDefinition's JDBC parameters in global variables.
* @param inStream Data from inputXML file which is converted into InputStream.
* @param number order number of importDefinition or sql tag which is proceeded.
* @param tagName name of tag which is proceeded
* @throws LoaderException
*/
public void parseImportJDBCParameters (InputStream inStream,int number,String tagName) throws LoaderException{
this.strJDBCSourceParameterDriver = "";
this.strJDBCTargetParameterDriver = "";
this.strJDBCSourceParameterConnection = "";
this.strJDBCTargetParameterConnection = "";
this.strJDBCSourceParameterUser = "";
this.strJDBCTargetParameterUser = "";
this.strJDBCSourceParameterPassword = "";
this.strJDBCTargetParameterPassword = "";
this.strDbVendor = "";
this.strDriverName = "";
this.strTargetDbVendor = "";
this.strTargetDriverName = "";
number--;
Document doc = null;
Vector vecJDBCTargetValue = new Vector();
Vector vecJDBCTargetName = new Vector();
Vector vecJDBCSourceValue = new Vector();
Vector vecJDBCSourceName = new Vector();
boolean isOK = false;
this.logger.write("full", "\tparseImportJDBCParameters method is started.");
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
db = dbf.newDocumentBuilder();
doc = db.parse(inStream);
} catch (Exception e) {
this.logger.write("normal", "Sorry, an error occurred: " + e);
LoaderException le = new LoaderException("Exception: ",
(Throwable)e);
throw le;
// System.exit(1);
}
if (doc != null) {
NodeList tagDefault = doc.getElementsByTagName( tagName );
if (tagDefault.getLength() != 0) {
Element docFragment = (Element)tagDefault.item( number );
//source parameters
NodeList tag = docFragment.getElementsByTagName("jdbcSourceParameters");
if (tag.getLength() != 0) {
NamedNodeMap jdbc = tag.item(0).getAttributes();
Node nodeJdbc = jdbc.getNamedItem("dbVendor");
if (nodeJdbc != null)
this.strDbVendor = nodeJdbc.getNodeValue();
nodeJdbc = jdbc.getNamedItem("driverName");
if (nodeJdbc != null)
this.strDriverName = nodeJdbc.getNodeValue();
}
//target parameters
tag = docFragment.getElementsByTagName("jdbcTargetParameters");
if (tag.getLength() != 0) {
NamedNodeMap jdbc = tag.item(0).getAttributes();
Node nodeJdbc = jdbc.getNamedItem("dbVendor");
if (nodeJdbc != null)
this.strTargetDbVendor = nodeJdbc.getNodeValue();
nodeJdbc = jdbc.getNamedItem("driverName");
if (nodeJdbc != null)
this.strTargetDriverName = nodeJdbc.getNodeValue();
}
tag = docFragment.getElementsByTagName("jdbcSourceParameter");
for (int i = 0; i < tag.getLength(); i++) {
String nodeValueValue = "";
String nodeNameValue = "";
NamedNodeMap attrs = tag.item(i).getAttributes();
Node nodeValue = attrs.getNamedItem("value");
Node nodeName = attrs.getNamedItem("name");
if (nodeValue != null && nodeName != null) {
nodeValueValue = nodeValue.getNodeValue();
nodeNameValue = nodeName.getNodeValue();
}
vecJDBCSourceValue.addElement(nodeValueValue);
vecJDBCSourceName.addElement(nodeNameValue);
}
for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
this.strJDBCSourceParameterDriver = vecJDBCSourceValue.get(i).toString();
else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
//Testing SelectMethod parameter in microsoft MSSQL driver
if(vecJDBCSourceValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
if(vecJDBCSourceValue.get(i).toString().indexOf("SelectMethod")==-1) {
this.strJDBCSourceParameterConnection = vecJDBCSourceValue.get(i).toString()+";SelectMethod=cursor";
} else {
if(vecJDBCSourceValue.get(i).toString().indexOf("cursor")!=-1) {
this.strJDBCSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
} else {
this.logger.write("normal", "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor" );
LoaderException le = new LoaderException("Exception:", new Exception("value of Connection.Url perameter SelectMethod has to be cursor"));
throw le;
}
}
} else {
this.strJDBCSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
}
}
else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("User"))
this.strJDBCSourceParameterUser = vecJDBCSourceValue.get(i).toString();
else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Password"))
this.strJDBCSourceParameterPassword = vecJDBCSourceValue.get(i).toString();
}
tag = docFragment.getElementsByTagName("jdbcTargetParameter");
for (int i = 0; i < tag.getLength(); i++) {
String nodeValueValue = "";
String nodeNameValue = "";
NamedNodeMap attrs = tag.item(i).getAttributes();
Node nodeValue = attrs.getNamedItem("value");
Node nodeName = attrs.getNamedItem("name");
if (nodeValueValue != null && nodeName != null) {
nodeValueValue = nodeValue.getNodeValue();
nodeNameValue = nodeName.getNodeValue();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -