📄 jdbcparameterselement.java
字号:
vecJDBCTargetValue.addElement(nodeValueValue);
vecJDBCTargetName.addElement(nodeNameValue);
}
for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
this.strJDBCTargetParameterDriver = vecJDBCTargetValue.get(i).toString();
else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
//Testing SelectMethod parameter in microsoft MSSQL driver
if(vecJDBCTargetValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
if(vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod")==-1) {
this.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString()+";SelectMethod=cursor";
} else {
if(vecJDBCTargetValue.get(i).toString().indexOf("cursor")!=-1) {
this.strJDBCTargetParameterConnection = vecJDBCTargetValue.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.strJDBCTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
}
}
else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
this.strJDBCTargetParameterUser = vecJDBCTargetValue.get(i).toString();
else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Password"))
this.strJDBCTargetParameterPassword = vecJDBCTargetValue.get(i).toString();
}
}
isOK=true;
}
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.logger.write("full", "\tparseImportJDBCDefaultParameters method is finished.");
}
/**
* Method parseImportJDBCDefaultParameters is used to analyse import XML file
* about Default JDBC parameters tags.
* @param inStream Data from inputXML file which is converted into InputStream.
* @return boolean - true default jdbc parameters exists, false otherwise
* @throws LoaderException
*/
public boolean parseImportJDBCDefaultParameters (InputStream inStream) throws LoaderException{
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", "\tparseImportJDBCDefaultParameters 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;
}
if (doc != null) {
NodeList tagDefault = doc.getElementsByTagName("jdbcDefaultParameters");
if (tagDefault.getLength() != 0) {
Element docFragment = (Element)tagDefault.item(0);
NodeList tag = docFragment.getElementsByTagName("jdbcSourceParameters");
if (tag.getLength() != 0) {
NamedNodeMap jdbc = tag.item(0).getAttributes();
Node nodeJdbc = jdbc.getNamedItem("dbVendor");
if (nodeJdbc != null)
this.strDbVendorDefault = nodeJdbc.getNodeValue();
nodeJdbc = jdbc.getNamedItem("driverName");
if (nodeJdbc != null)
this.strDriverNameDefault = nodeJdbc.getNodeValue();
}
tag = docFragment.getElementsByTagName("jdbcTargetParameters");
if (tag.getLength() != 0) {
NamedNodeMap jdbc = tag.item(0).getAttributes();
Node nodeJdbc = jdbc.getNamedItem("dbVendor");
if (nodeJdbc != null)
this.strTargetDbVendorDefault = nodeJdbc.getNodeValue();
nodeJdbc = jdbc.getNamedItem("driverName");
if (nodeJdbc != null)
this.strTargetDriverNameDefault = 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.strJDBCDefaultSourceParameterDriver = 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.strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue.get(i).toString()+";SelectMethod=cursor";
} else {
if(vecJDBCSourceValue.get(i).toString().indexOf("cursor")!=-1) {
this.strJDBCDefaultSourceParameterConnection = 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.strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue.get(i).toString();
}
}
else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("User"))
this.strJDBCDefaultSourceParameterUser = vecJDBCSourceValue.get(i).toString();
else if (vecJDBCSourceName.get(i).toString().equalsIgnoreCase("Password"))
this.strJDBCDefaultSourceParameterPassword = 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();
}
vecJDBCTargetValue.addElement(nodeValueValue);
vecJDBCTargetName.addElement(nodeNameValue);
}
for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("JdbcDriver"))
this.strJDBCDefaultTargetParameterDriver = vecJDBCTargetValue.get(i).toString();
else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Connection.Url")) {
//Testing SelectMethod parameter in microsoft MSSQL driver
if(vecJDBCTargetValue.get(i).toString().indexOf("jdbc:microsoft:sqlserver")!=-1) {
if(vecJDBCTargetValue.get(i).toString().indexOf("SelectMethod")==-1) {
this.strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue.get(i).toString()+";SelectMethod=cursor";
} else {
if(vecJDBCTargetValue.get(i).toString().indexOf("cursor")!=-1) {
this.strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue.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.strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue.get(i).toString();
}
}
else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("User"))
this.strJDBCDefaultTargetParameterUser = vecJDBCTargetValue.get(i).toString();
else if (vecJDBCTargetName.get(i).toString().equalsIgnoreCase("Password"))
this.strJDBCDefaultTargetParameterPassword = vecJDBCTargetValue.get(i).toString();
}
}
isOK=true;
}
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.logger.write("full", "\tparseImportJDBCDefaultParameters method is finished.");
return isOK;
}
//set and get methods
/**
* Set Logger of this class.
* @param logger Logger object which is used to write to log and standard output.
*/
public void setLogger(Logger logger) {
this.logger = logger;
}
/**
* Set ConfigReader of this class.
* @param configReader defines ConfigReader object which is used to store data
* about source driver.
*/
public void setConfigReaderSource(ConfigReader configReader) {
this.configReaderSource = configReader;
}
/**
* This method set the absolute path to loader job file
* @param loaderJobName is relativ path to loader job file
*/
public void setLoaderJobPath(String loaderJobName){
File file=new File(loaderJobName);
this.loaderJobFile=file.getAbsoluteFile().getParent()+System.getProperty("file.separator");
}
/**
* This method make absoulte path from relative path
* @param urlToDatabase relative path
* @return absolute path
* @throws LoaderException
*/
public String getAbsolutePathFromDatabaseURL(String urlToDatabase) throws LoaderException{
if(configReaderSource.getFileSystemDatabase()==true){
String urlPrefix = configReaderSource.getConnectionPrefix();
String pathToDatabase=urlToDatabase.substring(urlPrefix.length());
File file=new File(pathToDatabase);
if (!file.isAbsolute()){
pathToDatabase=this.loaderJobFile + pathToDatabase;
File absolutePath=new File(pathToDatabase);
try {
pathToDatabase=absolutePath.getCanonicalPath();
}
catch (Exception ex) {
this.logger.write("normal", ex.getMessage());
LoaderException le = new LoaderException("Exception: ",(Throwable)ex);
throw le;
}
urlToDatabase = urlToDatabase.substring(0, (urlPrefix.length())) +
pathToDatabase;
}
}
return urlToDatabase;
}
//source parameters
/**
* Method return JDBCSourceParameterConnection,or if that
* parameter is not defined method will return default value which is
* strJDBCDefaultSourceParameterConnection
* @return JDBCSourceParameterConnection
* @throws LoaderException
*/
public String getJDBCSourceParameterConnection() throws LoaderException {
String parseUrl="";
try{
if (!this.strJDBCSourceParameterConnection.equals("")) {
parseUrl= getAbsolutePathFromDatabaseURL(this.strJDBCSourceParameterConnection);
} else {
parseUrl= getAbsolutePathFromDatabaseURL(this.strJDBCDefaultSourceParameterConnection);
}
}catch(LoaderException ex){
throw ex;
}
return parseUrl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -