📄 tabledesignreader.java
字号:
/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
Copyright (C) 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
*/
package org.webdocwf.util.loader.generator;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.logging.Logger;
import org.webdocwf.util.loader.logging.StandardLogger;
/**
* TableDesignReader class read the data which describe database tables.
* @author Radoslav Dutina
* @version 1.0
*/
public class TableDesignReader {
private static List listColumnNames = null;
private static List listTargetTableNames = null;
private static List listTargetTableID = null;
private static List listColumnType = null;
private static List listColumnLenght = null;
private static List listAllowNulls = null;
private Logger logger;
private ImportDefinitionAttributes importDefinitionAttributes = new ImportDefinitionAttributes();
private MappingTypeData mappingTypeData;
/**
* Construct object TableDesignReader with associated parameters.
* @param generatorParameters represents the references to InputParameter object.
* @param tableName is name of the table form which we retrieve data.
* @param conn is the named connection.
* @param catalogName is the name of the current database.
* @throws LoaderException
*/
public TableDesignReader(String tableName, Connection conn, String catalogName, InputParameters generatorParameters) throws LoaderException {
setLogger();
this.logger.write("full", "TableDesignReader is started.");
listColumnNames = new ArrayList();
listTargetTableNames = new ArrayList();
listTargetTableID = new ArrayList();
listColumnType = new ArrayList();
listColumnLenght = new ArrayList();
listAllowNulls = new ArrayList();
importDefinitionAttributes.setName(tableName);
importDefinitionAttributes.setTableName(tableName);
try {
ResultSet rs = conn.getMetaData().getColumns(catalogName, null, tableName, "%");
while (rs.next()) {
listColumnNames.add(rs.getString(4));
listTargetTableNames.add(tableName);
listTargetTableID.add("0");
if (generatorParameters.getSourceType().equalsIgnoreCase(generatorParameters.getTargetType())) {
listColumnType.add(rs.getString(6));
} else {
if (rs.getString(6).toLowerCase().endsWith("identity")) {
listColumnType.add("***autonumber***");
} else {
mappingTypeData = new MappingTypeData(rs.getString(6), generatorParameters);
listColumnType.add(mappingTypeData.getSQLType());
}
}
// if(rs.getString(6).equalsIgnoreCase("decimal")){
if (generatorParameters.getIsDecimal(rs.getString(6)).equalsIgnoreCase("true")) {
//TODO ZK change this 8.7 2004 because of problem with decimal type on DB2
if ((generatorParameters.getTargetType()).equalsIgnoreCase("DB2")) {
int lenght = new Integer(rs.getString(7)).intValue();
int dec = new Integer(rs.getString(9)).intValue();
int result = lenght + dec;
listColumnLenght.add(" (" + result + "," + rs.getString(9) + ") ");
} else {
listColumnLenght.add(" (" + rs.getString(7) + "," + rs.getString(9) + ") ");
}
// ZK change this 5.5.2004
// listColumnLenght.add(rs.getString(7)+","+rs.getString(9));
// }else if(rs.getString(6).equalsIgnoreCase("int")||
// rs.getString(6).equalsIgnoreCase("tinyint")||
// rs.getString(6).equalsIgnoreCase("datetime")||
// rs.getString(6).equalsIgnoreCase("ntext")||
// rs.getString(6).equalsIgnoreCase("blob")||
// rs.getString(6).equalsIgnoreCase("image")||
// rs.getString(6).equalsIgnoreCase("bynary")||
// rs.getString(6).equalsIgnoreCase("long varchar")||
// rs.getString(6).toLowerCase().endsWith("identity")){
} else if (generatorParameters.getHasSize(rs.getString(6)).equalsIgnoreCase("false")) {
listColumnLenght.add(" ");
} else {
//ZK change this 5.5.2004
listColumnLenght.add("(" + rs.getString(7) + ") ");
// listColumnLenght.add(rs.getString(7));
}
if (rs.getString(18).equalsIgnoreCase("YES")) {
listAllowNulls.add("");
} else {
listAllowNulls.add("NOT NULL");
}
}
importDefinitionAttributes.setTagSourceColumnName(getColumnNames());
importDefinitionAttributes.setTagTargetColumnName(getColumnNames());
importDefinitionAttributes.setTagTargetTableName(getTargetTableNames());
importDefinitionAttributes.setTagTargetTableID(getTargetTableID());
importDefinitionAttributes.setTagColumnType(getColumnType());
importDefinitionAttributes.setTagAllowNulls(getAllowNulls());
importDefinitionAttributes.setTagColumnLenght(getColumnLenght());
rs.close();
} catch (java.sql.SQLException e) {
String msg = "Can't get the connection, to " + tableName + " table. ";
LoaderException le = new LoaderException(msg + e.getMessage(), (Throwable) e);
this.logger.write("full", "Exception:" + msg + "\n" + le.getStackTraceAsString());
throw le;
} catch (Exception e) {
String msg = "Exception in class TableDesignReader! ";
LoaderException le = new LoaderException(msg + e.getMessage(), (Throwable) e);
this.logger.write("full", "Exception:" + msg + "\n" + le.getStackTraceAsString());
throw le;
}
this.logger.write("full", "TableDesignReader is finished.");
}
/**
* This method read value of importDefinitionAttributes parameters.
* @return references to ImportDefinitionAttributes objects.
*/
public ImportDefinitionAttributes getImportDefinition() {
return importDefinitionAttributes;
}
/**
* This method sets value of listColumnNames parameters.
* @param list_ColumnNames is value of parameters.
*/
public static void setColumnNames(String[] list_ColumnNames) {
listColumnNames = Arrays.asList(list_ColumnNames);
}
/**
* This method read value of listColumnNames parameters.
* @return value of parameters.
*/
public static String[] getColumnNames() {
String[] ret = new String[listColumnNames.size()];
listColumnNames.toArray(ret);
return ret;
}
/**
* This method sets value of listTargetTableNames parameters.
* @param list_TargetTableNames is value of parameters.
*/
public static void setTargetTableNames(String[] list_TargetTableNames) {
listTargetTableNames = Arrays.asList(list_TargetTableNames);
}
/**
* This method read value of listTargetTableNames parameters.
* @return value of parameters.
*/
public static String[] getTargetTableNames() {
String[] ret = new String[listTargetTableNames.size()];
listTargetTableNames.toArray(ret);
return ret;
}
/**
* This method sets value of listTargetTableID parameters.
* @param list_TargetTableID is value of parameter.
*/
public static void setTargetTableID(String[] list_TargetTableID) {
listTargetTableID = Arrays.asList(list_TargetTableID);
}
/**
* This method read value of listTargetTableID parameters.
* @return value of parameters.
*/
public static String[] getTargetTableID() {
String[] ret = new String[listTargetTableID.size()];
listTargetTableID.toArray(ret);
return ret;
}
/**
* This method sets value of listColumnType parameters.
* @param list_ColumnType is value of parameters.
*/
public static void setColumnType(String[] list_ColumnType) {
listColumnType = Arrays.asList(list_ColumnType);
}
/**
* This method read value of listColumnType parameters.
* @return value of parameters.
*/
public static String[] getColumnType() {
String[] ret = new String[listColumnType.size()];
listColumnType.toArray(ret);
return ret;
}
/**
* This method sets value of listColumnLenght parameters.
* @param list_ColumnLenght is value of parameter.
*/
public static void setColumnLenght(String[] list_ColumnLenght) {
listColumnLenght = Arrays.asList(list_ColumnLenght);
}
/**
* This method read value of listColumnLenght parameters.
* @return value of parameters.
*/
public static String[] getColumnLenght() {
String[] ret = new String[listColumnLenght.size()];
listColumnLenght.toArray(ret);
return ret;
}
/**
* This method sets value of listAllowNulls parameters.
* @param list_AllowNulls is value of parameters.
*/
public static void setAllowNulls(String[] list_AllowNulls) {
listAllowNulls = Arrays.asList(list_AllowNulls);
}
/**
* This method read value of listAllowNulls parameters.
* @return value of parameters.
*/
public static String[] getAllowNulls() {
String[] ret = new String[listAllowNulls.size()];
listAllowNulls.toArray(ret);
return ret;
}
/**
* This method will set logger object
* @param logger
*/
private void setLogger() {
this.logger = StandardLogger.getCentralLogger();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -