📄 transformation.java
字号:
return retVal;
}
/**
* Returns Vector with target key column names
* @param index logical table index
* @return vector
*/
public Vector getTargetKeyColumnNames(int index) {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableID().equals( String.valueOf(index) ) ) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getValueMode().equals("Key") )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getName() );
}
}
return retVal;
}
/**
* Returns Vector with target column names for specified table
* @param tableName name of table
* @return vector
*/
public Vector getTargetColumnNames(String tableName) {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableName().equals(tableName) )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getName() );
}
return retVal;
}
/**
* Returns Vector with target key column names
* @return vector
*/
public Vector getTargetKeyColumnNames() {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getValueMode().equals("Key") )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getName() );
}
return retVal;
}
/**
* Returns Vector with target value mode
* @return vector
*/
public Vector getTargetValueMode() {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getValueMode() );
}
return retVal;
}
/**
* Returns Vector with target column types
* @return vector
*/
// public Vector getTargetColumnTypes() {
// Vector retVal = new Vector();
// for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
// retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getValueMode() );
// }
// return retVal;
// }
/**
* This method read value of sub counter parameter
* @param sourceValues values to transform
* @return vector transformed values
* @throws SQLException
*/
public Vector transformValues(Vector sourceValues) throws Exception{
Vector results = new Vector();
try {
results.addAll(this.transformer.transformValue(sourceValues));
} catch (Exception except) {
throw except;
}
return results;
}
/**
* This method returns transformation name
* @return String which represents transformation name
*/
public String getName() {
return this.transformationName;
}
/**
* Method transformationColumnTypes is used to put types of transformation columns into
* global vector sorted in target tables. If there is an error, Exception
* "SQLException" or "NullPointerException" is thrown.
* @param c Connection to target database.
* @param firstColumn is first column
* @param columnsSuportedTarget is true if driver for target database supports getColumns method
* @param configReaderTarget is ConfigReader object for target database
* @throws SQLException Constructs an SQLException object with a reason.
* @throws NullPointerException Constructs a NullPointerException with the specified detail message.
*/
public void transformationColumnTypes(
Connection c,
int firstColumn,
boolean columnsSuportedTarget, ConfigReader configReaderTarget) throws SQLException, NullPointerException {
int iCnt = 0;
try {
List tableNames = this.getTargetTableNames();
for(int k = 0; k < tableNames.size(); k++) {
Vector columnNames = this.getTargetColumnNames(tableNames.get(k).toString());
Statement stmtTrans = c.createStatement();
//Vector typs = new Vector();
Vector subTyps = new Vector();
String strQuery = "select ";
ResultSet rsetTrans=null;
if (columnNames.size() != 0) {
for (int i = 0; i < columnNames.size(); i++) {
strQuery += columnNames.get(i).toString() +
", ";
}
strQuery = strQuery.substring(0, strQuery.length() - 2);
strQuery += " from " + tableNames.get(k).toString();
if (columnsSuportedTarget){
rsetTrans = c.getMetaData().getColumns( c.getCatalog(), null, tableNames.get(k).toString(), "%" );
String columnName = "";
String columnType = "";
while(rsetTrans.next()){
columnName = rsetTrans.getString(3+firstColumn);
columnType = rsetTrans.getString(5+firstColumn);
for (int j = 0; j < columnNames.size(); j++) {
if( columnNames.get(j).toString().equalsIgnoreCase( columnName ) ){
this.setType(tableNames.get(k).toString(),columnNames.get(j).toString(),columnType);
//typs.add(columnType);
}
}
}
}else{//TODO ZK ADDED stmtConstant.setMaxRows(1). Place this as parameter in conf file, like maxRowsSuported
if (configReaderTarget.getMaxRowsSupported()){
stmtTrans.setMaxRows(1);
}
rsetTrans = stmtTrans.executeQuery(strQuery);
for (int j = 0; j < columnNames.size(); j++) {
this.setType( tableNames.get(k).toString(),
columnNames.get(j).toString(),
rsetTrans.getMetaData().getColumnTypeName(j + firstColumn) );
//typs.add(rsetConstant.getMetaData().getColumnTypeName(j + firstColumn));
}
}
rsetTrans.close();
}
stmtTrans.close();
}
// this.hmTargetColumnTypes.addAll(typs);
}
catch (SQLException ex) {
throw ex;
}
catch (NullPointerException ex) {
throw ex;
}
}
public List getTargetTableNames() {
List retVal = new ArrayList();
Element transformation = this.transformationDocFragment;
NodeList nodeList = transformation.getChildNodes();
String tableName = "";
for(int i = 0; i < nodeList.getLength(); i++) {
if( nodeList.item(i).getNodeType() != Node.ELEMENT_NODE )
continue;
if( !nodeList.item(i).getNodeName().equals("targetColumns"))
continue;
Element targetColumns = (Element)nodeList.item(i);
NodeList targetColumnElements = targetColumns.getElementsByTagName("targetColumn");
for(int j = 0; j < targetColumnElements.getLength();j++) {
Element targetColumn = (Element)targetColumnElements.item(j);
tableName = targetColumn.getAttribute("tableName");
if( !retVal.contains(tableName) )
retVal.add(tableName);
}
}
return retVal;
}
public String getTargetTableID() {
Element transformation = this.transformationDocFragment;
NodeList nodeList = transformation.getChildNodes();
for(int i = 0; i < nodeList.getLength(); i++) {
if( nodeList.item(i).getNodeType() != Node.ELEMENT_NODE )
continue;
if( !nodeList.item(i).getNodeName().equals("targetColumns"))
continue;
Element targetColumns = (Element)nodeList.item(i);
Element targetColumn = (Element)targetColumns.getElementsByTagName("targetColumn").item(0);
return targetColumn.getAttribute("tableID");
}
return null;
}
private void setType(String tableName, String columnName, String type) {
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableName().equals(tableName) &&
((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getName().equals(columnName) )
((TransformationTargetColumn)this.transformationTargetColumns.get(i)).setType(type);
}
}
/**
* This method reset all variables
*/
public void reset() {
this.sourceColumnNames = new Vector();
this.transformationTargetColumns = new ArrayList();
}
public void release() throws Exception{
this.transformer.release();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -