Compare commits

..

5 Commits

Author SHA1 Message Date
wchen-talend
1342f2ceec TPS-1120:[5.4.2]copy to branch' search option appears to take time to
generate the results (TDI-31520)
2015-10-12 15:50:11 +08:00
Sebastien Gandon
f7623122bf TDM-4411 : generate a timestamp at every export for TDM generation
Conflicts:
	main/plugins/org.talend.core/src/main/java/org/talend/designer/runprocess/ProcessorUtilities.java
2015-01-27 16:26:02 +08:00
hcyi
3c22d8c4e0 TPS-710:[5.4.2] Unable to extract schema from an AS400
Connection(TDI-30384,TDI-30423)
2014-09-11 13:52:52 +08:00
hcyi
cff9e0ac4c TPS-710:[5.4.2] Unable to extract schema from an AS400
Connection(TDI-30384,TDI-30423)
2014-09-10 18:10:32 +08:00
cmeng-talend
da2be71e56 TPS-674 [5.4.2] Problem (unwanted preceding joblet name in a sql) with
migration from 512 to 542 (TDI-29901)
https://jira.talendforge.org/browse/TPS-674
2014-07-14 15:41:42 +08:00
7 changed files with 812 additions and 42 deletions

View File

@@ -13,39 +13,40 @@
package org.talend.commons.utils.database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
/**
* created by zshen on Apr 12, 2013 Detailled comment
*
*/
public class AS400DatabaseMetaData extends PackageFakeDatabaseMetadata {
private static final String[] TABLE_META = {
"TABLE_TYPE", "TABLE_NAME", "SYSTEM_TABLE_NAME", "TABLE_SCHEMA", "SYSTEM_TABLE_SCHEMA" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
private String T = "T";//$NON-NLS-1$
private String V = "V";//$NON-NLS-1$
private String S = "S";//$NON-NLS-1$
private String A = "A";//$NON-NLS-1$
private String TABLE = "TABLE"; //$NON-NLS-1$
private String VIEW = "VIEW"; //$NON-NLS-1$
private String SYNONYM = "SYNONYM"; //$NON-NLS-1$
private String ALIAS = "ALIAS"; //$NON-NLS-1$
private static final String[] TABLE_META = {
"TABLE_TYPE", "TABLE_NAME", "SYSTEM_TABLE_NAME", "TABLE_SCHEMA", "SYSTEM_TABLE_SCHEMA" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
private String T = "T";//$NON-NLS-1$
private String V = "V";//$NON-NLS-1$
private String S = "S";//$NON-NLS-1$
private String A = "A";//$NON-NLS-1$
private String TABLE = "TABLE"; //$NON-NLS-1$
private String VIEW = "VIEW"; //$NON-NLS-1$
private String SYNONYM = "SYNONYM"; //$NON-NLS-1$
private String ALIAS = "ALIAS"; //$NON-NLS-1$
public AS400DatabaseMetaData(Connection conn) throws SQLException {
super(conn);
@@ -112,6 +113,7 @@ public class AS400DatabaseMetaData extends PackageFakeDatabaseMetadata {
ResultSet rs = null;
PreparedStatement stmt = null;
List<String[]> list = new ArrayList<String[]>();
Set<String> tablesRetrieved = new HashSet<String>();
try {
stmt = connection.prepareStatement(sql);
if (!StringUtils.isEmpty(tableNamePattern)) {
@@ -122,10 +124,11 @@ public class AS400DatabaseMetaData extends PackageFakeDatabaseMetadata {
String type = rs.getString("TYPE"); //$NON-NLS-1$
String table_name = rs.getString("TABLE_NAME"); //$NON-NLS-1$
String system_table_name = rs.getString("SYSTEM_TABLE_NAME"); //$NON-NLS-1$
tablesRetrieved.add(system_table_name);
String table_schema = rs.getString("TABLE_SCHEMA"); //$NON-NLS-1$
String system_table_schema = rs.getString("SYSTEM_TABLE_SCHEMA");
String system_table_schema = rs.getString("SYSTEM_TABLE_SCHEMA");//$NON-NLS-1$
String[] r = new String[] { type, table_name, system_table_name, table_schema, system_table_schema }; //$NON-NLS-1$ //$NON-NLS-2$
String[] r = new String[] { type, table_name, system_table_name, table_schema, system_table_schema };
list.add(r);
}
@@ -138,11 +141,23 @@ public class AS400DatabaseMetaData extends PackageFakeDatabaseMetadata {
} catch (Exception e) {
}
}
ResultSet jdbcRset = super.getTables(catalog, schemaPattern, tableNamePattern, types);
while (jdbcRset.next()) {
String table_name = jdbcRset.getString("TABLE_NAME"); //$NON-NLS-1$
if (tablesRetrieved.contains(table_name)) {
continue;
}
String type = jdbcRset.getString("TABLE_TYPE"); //$NON-NLS-1$
String table_schema = jdbcRset.getString("TABLE_SCHEM"); //$NON-NLS-1$
String[] r = new String[] { type, table_name, table_name, table_schema, table_schema };
list.add(r);
}
AS400ResultSet tableResultSet = new AS400ResultSet();
tableResultSet.setMetadata(TABLE_META);
tableResultSet.setData(list);
return tableResultSet;
// return super.getTables(catalog, schemaPattern, tableNamePattern, types);
}
private String getTypeNameType(String typeName) {

View File

@@ -0,0 +1,438 @@
// ============================================================================
//
// Copyright (C) 2006-2014 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.core.model.utils;
import junit.framework.Assert;
import org.junit.Test;
/**
* DOC cmeng class global comment. Detailled comment
*/
@SuppressWarnings("nls")
public class ParameterValueUtilTest {
@Test
public void testSplitQueryData4SQL() {
String testString = null;
String expectRetValue = null;
String retValue = null;
int i = 0;
// test case 0
// testString : context.operation+" "+context.schema+"."+context.table+";"
testString = "context.operation+\" \"+context.schema+\".\"+context.table+\";\"";
expectRetValue = "context.oper+\" \"+context.schema+\".\"+context.table+\";\"";
retValue = ParameterValueUtil.splitQueryData("context.operation", "context.oper", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// schema
expectRetValue = "context.operation+\" \"+context.db+\".\"+context.table+\";\"";
retValue = ParameterValueUtil.splitQueryData("context.schema", "context.db", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// table
expectRetValue = "context.operation+\" \"+context.schema+\".\"+context.table1+\";\"";
retValue = ParameterValueUtil.splitQueryData("context.table", "context.table1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// part of replacing
retValue = ParameterValueUtil.splitQueryData("text.schema", "text.schemaABC", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, testString.equals(retValue));
// only normal sting
testString = "context.operation+\" \"+context_schema+schema+\".\"+context.table+\";\"";
expectRetValue = "context.operation+\" \"+context_schema+schema123+\".\"+context.table+\";\"";
retValue = ParameterValueUtil.splitQueryData("schema", "schema123", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// only normal sting for context
testString = "context.operation+\" \"+context.schema+schema+\".\"+context.table+\";\"";
expectRetValue = "context.operation+\" \"+context.schema+schema123+\".\"+context.table+\";\"";
retValue = ParameterValueUtil.splitQueryData("schema", "schema123", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// same prefix
testString = "context.operation+\" \"+context.test1+\".\"+context.test11+\";\"";
expectRetValue = "context.operation+\" \"+context.test2+\".\"+context.test11+\";\"";
retValue = ParameterValueUtil.splitQueryData("context.test1", "context.test2", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 1
// testString (For bug:TDI-29092) : "drop table "+context.oracle_schema+".\"TDI_26803\""
testString = "\"drop table \"+context.oracle_schema+\".\\\"TDI_26803\\\"\"";
expectRetValue = "\"drop table \"+context.oracl_schema+\".\\\"TDI_26803\\\"\"";
retValue = ParameterValueUtil.splitQueryData("context.oracle_schema", "context.oracl_schema", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// column, don't replace the file for SQL
expectRetValue = "\"drop table \"+context.oracl_schema+\".\\\"TDI_12345\\\"\"";
retValue = ParameterValueUtil.splitQueryData("TDI_26803", "TDI_12345", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, testString.equals(retValue)); // not changed
// test case 7
// all are empty
// testString :
// ""
testString = "";
expectRetValue = "";
retValue = ParameterValueUtil.splitQueryData("", "", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 8
// many same varibles
// testString :
// "contextA"+context+"contextB"+context+"contextC" + context+" "
testString = "\"contextA\"+context+\"contextB\"+context+\"contextC\" + context+\" \"";
expectRetValue = "\"contextA\"+context.db+\"contextB\"+context.db+\"contextC\" + context.db+\" \"";
retValue = ParameterValueUtil.splitQueryData("context", "context.db", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
expectRetValue = "\"contextA\"+context.db+\"contextB\"+context.db+\"contextCC\" + context.db+\" \"";
retValue = ParameterValueUtil.splitQueryData("contextC", "contextCC", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, testString.equals(retValue)); // not changed
// test case 9
// testString :
// "contextA"+contextA+"contextB"+context+"contextC" + context+" "
testString = "\"contextA\"+contextA+\"contextB\"+context+\"contextC\" + context+\" \"";
expectRetValue = "\"contextA\"+contextA+\"contextB\"+context.db+\"contextC\" + context.db+\" \"";
retValue = ParameterValueUtil.splitQueryData("context", "context.db", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
expectRetValue = "\"contextA\"+contextAA+\"contextB\"+context+\"contextC\" + context+\" \"";
retValue = ParameterValueUtil.splitQueryData("contextA", "contextAA", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 10
// "SELECT
// "+context.ORA_VIRTULIA_Schema+".PER_ETATCIVIL.IDE_DOSSIER,
// "+context.ORA_VIRTULIA_Schema+".PER_ETATCIVIL.QUALITE,
// "+context.ORA_VIRTULIA_Schema+".PER_ETATCIVIL.NOM
// FROM "+context.ORA_VIRTULIA_Schema+".PER_ETATCIVIL"
// this function should not replace constant
testString = "\"SELECT \r\n" + "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.IDE_DOSSIER,\r\n"
+ "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.QUALITE,\r\n"
+ "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.NOM\r\n"
+ "FROM \"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL\"";
expectRetValue = "\"SELECT \r\n" + "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.IDE_DOSSIER,\r\n"
+ "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.QUALITE,\r\n"
+ "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.NOM\r\n"
+ "FROM \"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL\"";
retValue = ParameterValueUtil.splitQueryData("PER_ETATCIVIL.IDE_DOSSIER", "simplejoblet_1_PER_ETATCIVIL.IDE_DOSSIER",
testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
testString = "\"SELECT \r\n" + "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.IDE_DOSSIER,\r\n"
+ "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.QUALITE,\r\n"
+ "\"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL.NOM\r\n"
+ "FROM \"+context.ORA_VIRTULIA_Schema+\".PER_ETATCIVIL\"";
expectRetValue = "\"SELECT \r\n" + "\"+context.ORA_CHANGE_Schema+\".PER_ETATCIVIL.IDE_DOSSIER,\r\n"
+ "\"+context.ORA_CHANGE_Schema+\".PER_ETATCIVIL.QUALITE,\r\n"
+ "\"+context.ORA_CHANGE_Schema+\".PER_ETATCIVIL.NOM\r\n"
+ "FROM \"+context.ORA_CHANGE_Schema+\".PER_ETATCIVIL\"";
retValue = ParameterValueUtil.splitQueryData("context.ORA_VIRTULIA_Schema", "context.ORA_CHANGE_Schema", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
testString = "no match";
expectRetValue = "no match";
retValue = ParameterValueUtil.splitQueryData("context.schema", "context.db", testString);
Assert.assertTrue(retValue != null && !"".equals(retValue));
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 11
// testString : "select * from " + context.table + " where value = \"value from context.table\""
// expectString : "select * from " + context.table1 + " where value = \"value from context.table\""
testString = "\"select * from \" + context.table + \" where value = \\\"value from context.table\\\"\"";
expectRetValue = "\"select * from \" + context.table1 + \" where value = \\\"value from context.table\\\"\"";
retValue = ParameterValueUtil.splitQueryData("context.table", "context.table1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 12
// testString : "select * from " + context.table + " where value = \"context.table\""
// expectString : "select * from " + context.table1 + " where value = \"context.table\""
testString = "\"select * from \" + context.table + \" where value = \\\"context.table\\\"\"";
expectRetValue = "\"select * from \" + context.table1 + \" where value = \\\"context.table\\\"\"";
retValue = ParameterValueUtil.splitQueryData("context.table", "context.table1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 13
// testString : "select * from " + context.table + " where value = \"context.table\"" + context.table
// expectString : "select * from " + context.table1 + " where value = \"context.table\"" + context.table
testString = "\"select * from \" + context.table + \" where value = \\\"context.table\\\"\" + context.table";
expectRetValue = "\"select * from \" + context.table1 + \" where value = \\\"context.table\\\"\" + context.table1";
retValue = ParameterValueUtil.splitQueryData("context.table", "context.table1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 14 : incomplete double quota
// testString : "select a,context.b from " + context.b + "where value = context.b
// expectString : "select a,context.b from " + context.b1 + "where value = context.b1
testString = "\"select a,context.b from \" + context.b + \"where value = context.b";
expectRetValue = "\"select a,context.b from \" + context.b1 + \"where value = context.b1";
retValue = ParameterValueUtil.splitQueryData("context.b", "context.b1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 15 : incomplete double quota
// testString : "select a,context.b from " + context.b + "where value = \"context.b
// expectString : "select a,context.b from " + context.b1 + "where value = \"context.b1
testString = "\"select a,context.b from \" + context.b + \"where value = \\\"context.b";
expectRetValue = "\"select a,context.b from \" + context.b1 + \"where value = \\\"context.b1";
retValue = ParameterValueUtil.splitQueryData("context.b", "context.b1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 16
// testString : "select * from " + context.table + " where value = \"\\" + context.table + "\\context.table\""
// expectString : "select * from " + context.table1 + " where value = \"\\" + context.table1 +
// "\\context.table\""
testString = "\"select * from \" + context.table + \" where value = \\\"\\\\\" + context.table + \"\\\\context.table\\\"\"";
expectRetValue = "\"select * from \" + context.table1 + \" where value = \\\"\\\\\" + context.table1 + \"\\\\context.table\\\"\"";
retValue = ParameterValueUtil.splitQueryData("context.table", "context.table1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 17
// testString : "select * from ""context.table where value = \"\\" + context.table + "\\context.table\""
// expectString : "select * from ""context.table where value = \"\\" + context.table1 + "\\context.table\""
testString = "\"select * from \"\"context.table where value = \\\"\\\\\" + context.table + \"\\\\context.table\\\"\"";
expectRetValue = "\"select * from \"\"context.table where value = \\\"\\\\\" + context.table1 + \"\\\\context.table\\\"\"";
retValue = ParameterValueUtil.splitQueryData("context.table", "context.table1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 18
// testString : "select * from " + context.table + "where id = " + getId(getHeader(context.header, "CONTEXT_ID")
// + "CONTEXT_ID")
// expectString : "select * from " + context.table + "where id = " + getId(getHeader(context.header,
// "CONTEXT_ID") + "CONTEXT_ID")
testString = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_ID\") + \"CONTEXT_ID\")";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_IDS\") + \"CONTEXT_IDS\")";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_IDS", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 19
// testString : "select * from " + context.table + "where id = " + getId(getHeader(context.header, "CONTEXT_ID")
// + "CONTEXT_ID", context.p2, "CONTEXT_ID")
// expectString : "select * from " + context.table + "where id = " + getId(getHeader(context.header,
// "CONTEXT_IDS") + "CONTEXT_IDS", context.p2, "CONTEXT_IDS")
testString = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_ID\") + \"CONTEXT_ID\", context.p2, \"CONTEXT_ID\")";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_IDS\") + \"CONTEXT_IDS\", context.p2, \"CONTEXT_IDS\")";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_IDS", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 20
// testString : "select * from " + context.table + "where id = " + getId(global.getHeader(context.header,
// "CONTEXT_ID")
// + "CONTEXT_ID", context.p2, "CONTEXT_ID")
// expectString : "select * from " + context.table + "where id = " + getId(global.getHeader(context.header,
// "CONTEXT_IDS") + "CONTEXT_IDS", context.p2, "CONTEXT_IDS")
testString = "\"select * from \" + context.table + \"where id = \" + getId(global.getHeader(context.header, \"CONTEXT_ID\") + \"CONTEXT_ID\", context.p2, \"CONTEXT_ID\")";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(global.getHeader(context.header, \"CONTEXT_IDS\") + \"CONTEXT_IDS\", context.p2, \"CONTEXT_IDS\")";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_IDS", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 21
// testString : "select * from " + context.table + "where id = " + getId(global.getHeader(context.header,
// "\"CONTEXT_ID\\\"")
// + "\"CONTEXT_ID", context.p2, "CONTEXT_ID")
// expectString : "select * from " + context.table + "where id = " + getId(global.getHeader(context.header,
// "CONTEXT_IDS") + "CONTEXT_IDS", context.p2, "CONTEXT_IDS")
testString = "\"select * from \" + context.table + \"where id = \" + getId(global.getHeader(context.header, \"\\\"CONTEXT_ID\\\\\\\"\") + \"\\\"CONTEXT_ID\", context.p2, \"CONTEXT_ID\")";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(global.getHeader(context.header, \"\\\"CONTEXT_IDS\\\\\\\"\") + \"\\\"CONTEXT_IDS\", context.p2, \"CONTEXT_IDS\")";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_IDS", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 22
// testString : "select * from " + context.table + "where id = " + getId(getHeader(context.header, "CONTEXT_ID")
// + "CONTEXT_ID", context.p2, "CONTEXT_ID"
// expectString : "select * from " + context.table + "where id = " + getId(getHeader(context.header,
// "CONTEXT_IDS") + "CONTEXT_IDS", context.p2, "CONTEXT_IDS"
testString = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_ID\") + \"CONTEXT_ID\", context.p2, \"CONTEXT_ID\"";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_IDS\") + \"CONTEXT_IDS\", context.p2, \"CONTEXT_IDS\"";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_IDS", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 23
// testString : "select * from " + context.table + "where id = " + getId(getHeader(context.header, "CONTEXT_ID")
// + "CONTEXT_ID", context.p2, "CONTEXT_ID
// expectString : "select * from " + context.table + "where id = " + getId(getHeader(context.header,
// "CONTEXT_IDS") + "CONTEXT_IDS", context.p2, "CONTEXT_IDS
testString = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_ID\") + \"CONTEXT_ID\", context.p2, \"CONTEXT_ID";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(getHeader(context.header, \"CONTEXT_IDS\") + \"CONTEXT_IDS\", context.p2, \"CONTEXT_IDS";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_IDS", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 24
// testString : "select * from " + context.table + "where id = " + getId(context.id) + globalMap.get("CONST")
// expectString : "select * from " + context.table + "where id = " + getId(context.id) + globalMap.get("CONST1")
testString = "\"select * from \" + context.table + \"where id = \" + getId(context.id) + globalMap.get(\"CONST\")";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(context.id) + globalMap.get(\"CONST1\")";
retValue = ParameterValueUtil.splitQueryData("CONST", "CONST1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 25 : should not replace method name
// testString : "select * from " + context.table + "where id = " + getId(context.id) +
// globalMap.get("globalMap")
// expectString : "select * from " + context.table + "where id = " + getId(context.id) +
// globalMap.get("globalMap1")
testString = "\"select * from \" + context.table + \"where id = \" + getId(context.id) + globalMap.get(\"globalMap\")";
expectRetValue = "\"select * from \" + context.table + \"where id = \" + getId(context.id) + globalMap.get(\"globalMap1\")";
retValue = ParameterValueUtil.splitQueryData("globalMap", "globalMap1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 26
// testString : "select * from " + context.table.a.b + contextA.table.a + table.a.b + table.a + "where id = " +
// getId(table.a) + table.a.get("table.a")
//
// expectString : "select * from " + context.table.a.b + contextA.table.a + table.a.b + table.a1 + "where id = "
// + getId(table.a1) + table.a.get("table.a1")
testString = "\"select * from \" + context.table.a.b + contextA.table.a + table.a.b + table.a + \"where id = \" + getId(table.a) + table.a.get(\"table.a\")";
expectRetValue = "\"select * from \" + context.table.a.b + contextA.table.a + table.a.b + table.a1 + \"where id = \" + getId(table.a1) + table.a.get(\"table.a1\")";
retValue = ParameterValueUtil.splitQueryData("table.a", "table.a1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
// test case 2
// testString : "select * from " + a.CONTEXT_ID + CONTEXT_ID.b + CONTEXT_ID + "where id = " +
// CONTEXT_ID(CONTEXT_ID(CONTEXT_ID, "\"CONTEXT_ID\"\\" + CONTEXT_ID, CONTEXT_ID, "CONTEXT_ID") + "CONTEXT_ID",
// CONTEXT_ID(ID, "CONTEXT_ID"), "CONTEXT_ID")
// expectString : "select * from " + a.CONTEXT_ID + CONTEXT_ID.b + CONTEXT_ID1 + "where id = " +
// CONTEXT_ID(CONTEXT_ID(CONTEXT_ID1, "\"CONTEXT_ID1\"\\" + CONTEXT_ID1, CONTEXT_ID1, "CONTEXT_ID1") +
// "CONTEXT_ID1", CONTEXT_ID(ID, "CONTEXT_ID1"), "CONTEXT_ID1")
testString = "\"select * from \" + a.CONTEXT_ID + CONTEXT_ID.b + CONTEXT_ID + \"where id = \" + CONTEXT_ID(CONTEXT_ID(CONTEXT_ID, \"\\\"CONTEXT_ID\\\"\\\\\" + CONTEXT_ID, CONTEXT_ID, \"CONTEXT_ID\") + \"CONTEXT_ID\", CONTEXT_ID(ID, \"CONTEXT_ID\"), \"CONTEXT_ID\")";
expectRetValue = "\"select * from \" + a.CONTEXT_ID + CONTEXT_ID.b + CONTEXT_ID1 + \"where id = \" + CONTEXT_ID(CONTEXT_ID(CONTEXT_ID1, \"\\\"CONTEXT_ID1\\\"\\\\\" + CONTEXT_ID1, CONTEXT_ID1, \"CONTEXT_ID1\") + \"CONTEXT_ID1\", CONTEXT_ID(ID, \"CONTEXT_ID1\"), \"CONTEXT_ID1\")";
retValue = ParameterValueUtil.splitQueryData("CONTEXT_ID", "CONTEXT_ID1", testString);
Assert.assertTrue("testSplitQueryDataCase_" + i++, expectRetValue.equals(retValue));
}
@Test
public void testSplitQueryData4SQL_Case2() {
// case 2:
// "insert into "+context.schema+"."+context.table+"(schema, table) values(\"context.schema\", \"context.table\")"
testSplitQueryData4SQL_Case2_5("testSplitQueryData4Case2", null, null, null);
}
@Test
public void testSplitQueryData4SQL_Case3() {
// case 3:
// ""+"insert into "+context.schema+"."+context.table+"(schema, table) values(\"context.schema\", \"context.table\")"
testSplitQueryData4SQL_Case2_5("testSplitQueryData4Case3", "\"\"", null, null);
}
@Test
public void testSplitQueryData4SQL_Case4() {
// case 4:
// "insert into "+context.schema+"."+context.table+"(schema, table) values(\"context.schema\", \"context.table\")"+""
testSplitQueryData4SQL_Case2_5("testSplitQueryData4Case4", null, null, "\"\"");
}
@Test
public void testSplitQueryData4SQL_Case5() {
// case 5:
// "insert into "+context.schema+"."+context.table+""+
// "(schema, table) values(\"context.schema\", \"context.table\")"
testSplitQueryData4SQL_Case2_5("testSplitQueryData4Case5", null, "\"\"", null);
}
private void testSplitQueryData4SQL_Case2_5(String message, String prefix, String mid, String suffix) {
if (prefix == null) {
prefix = "";
}
if (mid == null) {
mid = "";
}
if (suffix == null) {
suffix = "";
}
String testString = null;
String expectRetValue = null;
int i = 0;
// test case 2-5
// String which is same to the String to be replaced was contained in the testString
// testString :
/*
* case 2:
* "insert into "+context.schema+"."+context.table+"(schema, table) values(\"context.schema\", \"context.table\")"
*
* case 3: ""+"insert into "+context.schema+"."+context.table+
* "(schema, table) values(\"context.schema\", \"context.table\")"
*
*
* case 4:
* "insert into "+context.schema+"."+context.table+"(schema, table) values(\"context.schema\", \"context.table\")"
* +""
*
* case 5: "insert into "+context.schema+"."+context.table+""+
* "(schema, table) values(\"context.schema\", \"context.table\")"
*/
testString = "\"insert into \"+context.schema+\".\"+context.table+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
expectRetValue = "\"insert into \"+context.db+\".\"+context.table+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
assertTest(message, i++, prefix + testString + suffix, prefix + expectRetValue + suffix, "context.schema", "context.db");
// table
expectRetValue = "\"insert into \"+context.schema+\".\"+context.table111+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
assertTest(message, i++, prefix + testString + suffix, prefix + expectRetValue + suffix, "context.table",
"context.table111");
// prefix name 1
testString = "\"insert into \"+context.schema+\".\"+context.schematable+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
expectRetValue = "\"insert into \"+context.db+\".\"+context.schematable+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
assertTest(message, i++, prefix + testString + suffix, prefix + expectRetValue + suffix, "context.schema", "context.db");
// prefix name 2
testString = "\"insert into \"+context.schema+\".\"+context.schema_table+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
expectRetValue = "\"insert into \"+context.db+\".\"+context.schema_table+" + mid
+ "\"(schema, table) values(\\\"context.schema\\\", \\\"context.table\\\")\"";
assertTest(message, i++, prefix + testString + suffix, prefix + expectRetValue + suffix, "context.schema", "context.db");
}
private void assertTest(String message, int index, String testString, String expectRetValue, String oldOne, String newOne) {
String resultValue = ParameterValueUtil.splitQueryData(oldOne, newOne, testString);
Assert.assertTrue(message + index, expectRetValue.equals(resultValue));
}
@Test
public void testRenameValues4GlobleMap() {
String testString = "((String)globalMap.get(\"tFileList_1_CURRENT_FILE\"))";
String expectedValue = "((String)globalMap.get(\"tFileList_2_CURRENT_FILE\"))";
String resultValue = ParameterValueUtil.renameValues(testString, "tFileList_1", "tFileList_2", true);
Assert.assertTrue(expectedValue.equals(resultValue));
//
testString = "((String)globalMap.get(\"tFileList_1_CURRENT_FILEDIRECTORY\"))+((String)globalMap.get(\"tFileList_1_CURRENT_FILE\"))";
expectedValue = "((String)globalMap.get(\"tFileList_2_CURRENT_FILEDIRECTORY\"))+((String)globalMap.get(\"tFileList_2_CURRENT_FILE\"))";
resultValue = ParameterValueUtil.renameValues(testString, "tFileList_1", "tFileList_2", true);
Assert.assertTrue(expectedValue.equals(resultValue));
//
testString = "((String)globalMap.get(\"tFileList_1_CURRENT_FILEDIRECTORY\"))+((String)globalMap.get(\"tFileList_11_CURRENT_FILE\"))";
expectedValue = "((String)globalMap.get(\"tFileList_2_CURRENT_FILEDIRECTORY\"))+((String)globalMap.get(\"tFileList_11_CURRENT_FILE\"))";
resultValue = ParameterValueUtil.renameValues(testString, "tFileList_1", "tFileList_2", true);
Assert.assertTrue(expectedValue.equals(resultValue));
}
@Test
public void testRenameValues4SQLAndGlobleMap() {
// case
// "select A.id, A.name form "+context.table+" A where A.name= "+((String)globalMap.get("tFileList_1_CURRENT_FILE"))
String testString = "\"select A.id, A.name form \"+context.table+\" A where A.name= \"+((String)globalMap.get(\"tFileList_1_CURRENT_FILE\"))";
String expectRetValue = "\"select A.id, A.name form \"+context.table123+\" A where A.name= \"+((String)globalMap.get(\"tFileList_1_CURRENT_FILE\"))";
// if flag is false, means is from SQL. but when replace the globlemap, will be problem.
String retValue = ParameterValueUtil.renameValues(testString, "context.table", "context.table123", false);
Assert.assertTrue("testRenameValues4SQLAndGlobleMap", expectRetValue.equals(retValue));
expectRetValue = "\"select A.id, A.name form \"+context.table+\" A where A.name= \"+((String)globalMap.get(\"tFileList_2_CURRENT_FILE\"))";
// if flag is false, means is from SQL. but when replace the globlemap, will be problem.
retValue = ParameterValueUtil.renameValues(testString, "tFileList_1", "tFileList_2", false);
Assert.assertTrue("testRenameValues4SQLAndGlobleMap", expectRetValue.equals(retValue));
}
}

View File

@@ -12,19 +12,25 @@
// ============================================================================
package org.talend.core.model.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternCompiler;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import org.apache.oro.text.regex.Perl5Substitution;
import org.apache.oro.text.regex.Substitution;
import org.apache.oro.text.regex.Util;
import org.eclipse.emf.common.util.EList;
import org.eclipse.swt.graphics.Point;
import org.talend.core.model.context.UpdateContextVariablesHelper;
import org.talend.core.model.process.EParameterFieldType;
import org.talend.core.model.process.IElementParameter;
@@ -101,6 +107,7 @@ public final class ParameterValueUtil {
// replace
String returnValue = "";
if (value.contains(TalendQuoteUtils.getQuoteChar()) && !flag) {
// returnValue = splitQueryData(matcher, pattern, substitution, value, Util.SUBSTITUTE_ALL);
returnValue = splitQueryData(oldName, newName, value);
} else {
returnValue = Util.substitute(matcher, pattern, substitution, value, Util.SUBSTITUTE_ALL);
@@ -112,21 +119,203 @@ public final class ParameterValueUtil {
}
// function before TDI-29092 modify,this function seems only rename variables in context,I put this funciton back
// incase any problem with the new function and we can refer the old one to check the problem.
public static String splitQueryData(PatternMatcher matcher, Pattern pattern, Substitution sub, String value, int numSubs) {
String[] split = value.split("\"");
int i = 0;
String replace = "";
for (String s : split) {
if (i % 2 == 0) {
replace = s;
if (i != 0) {
if (matcher.contains(value, pattern)) {
replace = split[i].toString();
split[i] = Util.substitute(matcher, pattern, sub, replace, numSubs);
}
}
}
i++;
}
String returnValue = "";
for (int t = 1; t < split.length; t++) {
if (t % 2 == 0) {
returnValue += split[t];
} else {
returnValue += "\"" + split[t] + "\"";
}
}
return returnValue;
}
// for bug 12594 split "; for bug 29092(it has JUnits)
public static String splitQueryData(String oldName, String newName, String value) {
// example:"drop table "+context.oracle_schema+".\"TDI_26803\""
// >>>>>>>>__(const)__ ______(varible)_______ ___(const)___
String regex = "\"\"|\".*?([^\\\\]\")";
// >>>>>>>>_*_(const)__ _____*_(varible)_______ __*_(const)___
final int length = value.length();
// quotaStrings which stores the start and end point for all const strings in the value
LinkedHashMap<Integer, Integer> quotaStrings = new LinkedHashMap<Integer, Integer>();
List<Point> functionNameAreas = new ArrayList<Point>();
// get and store all start and end point of const strings
int start = -1;
int end = -2;
char ch;
for (int i = 0; i < length; i++) {
ch = value.charAt(i);
if (ch == '\"') {
// in case of cases :
// case 1 : [ "select * from " + context.table + " where value = \"context.table\"" ]
// case 2 : [ "select * from " + context.table + " where value = \"\\" + context.table +
// "\\context.table\"" ]
if (isEscapeSequence(value, i)) {
continue;
}
// [0 <= start] >> in case the first const String position compute error
if (0 <= start && end < start) {
end = i;
quotaStrings.put(start, end);
} else {
start = i;
}
}
}
{
// in case the value has not complete quota
// exapmle > "select a,context.b from " + context.b + "where value = context.b
// **but** maybe more impossible truth is that
// they write this(context.b) just want to use it as a varible...
// so maybe should not set the string behind the quota as a const by default..
// ---*--- the following code is set the string behind the quota as a const
// if (0 <= start && end < start) {
// end = length - 1;
// quotaStrings.put(start, end);
// }
}
// find the varible string, do replace, then concat them
StringBuffer strBuffer = new StringBuffer();
String subString = null;
int vStart = 0;
int vEnd = 0;
int methodMaxIndex = 0;
int calcMaxIndex = 0;
start = 0;
end = 0;
for (Entry<Integer, Integer> entry : quotaStrings.entrySet()) {
start = entry.getKey();
end = entry.getValue() + 1;
vEnd = start;
if (vStart == start) {
// const string follow with const string, maybe won't happen...
// get the const string
subString = value.substring(start, end);
if (start < methodMaxIndex) {
subString = subString.replaceAll(oldName, newName);
}
} else {
// get the varible string, do replace, then append it
subString = value.substring(vStart, vEnd);
calcMaxIndex = calcMethodArea(subString, value, vStart, functionNameAreas, methodMaxIndex);
if (methodMaxIndex < calcMaxIndex) {
methodMaxIndex = calcMaxIndex;
}
String replacedString = doVaribleReplace(oldName, newName, value, functionNameAreas, vStart, vEnd);
strBuffer.append(replacedString);
// get the const string
subString = value.substring(start, end);
if (start < methodMaxIndex) {
subString = subString.replaceAll(oldName, newName);
}
}
// append the const string
strBuffer.append(subString);
// update the varible string start point
vStart = end;
}
// in case the last string of the value is a varible string
// then get it, and do replace, finally append it.
if (vStart < length) {
vEnd = length;
String replacedString = doVaribleReplace(oldName, newName, value, functionNameAreas, vStart, vEnd);
strBuffer.append(replacedString);
}
return strBuffer.toString();
}
/**
* DOC cmeng Comment method "doVaribleReplace".
*
* @param oldName
* @param newName
* @param value
* @param functionNameAreas
* @param vStart
* @param vEnd
*/
private static String doVaribleReplace(String oldName, String newName, String value, List<Point> functionNameAreas,
int vStart, int vEnd) {
StringBuffer replacedString = new StringBuffer();
int replaceableStart = vStart;
int replaceableEnd = vEnd;
for (Point functionNameArea : functionNameAreas) {
if (vEnd <= functionNameArea.x) {
break;
}
if (functionNameArea.y <= vStart) {
continue;
}
if (replaceableStart < functionNameArea.x) {
replaceableEnd = functionNameArea.x;
String replaceableString = value.substring(replaceableStart, replaceableEnd);
replacedString.append(doReplace(oldName, newName, replaceableString));
replacedString.append(value.substring(functionNameArea.x, functionNameArea.y));
} else {
replacedString.append(value.substring(functionNameArea.x, functionNameArea.y));
}
replaceableStart = functionNameArea.y;
}
if (replaceableStart < vEnd) {
String replaceableString = value.substring(replaceableStart, vEnd);
replacedString.append(doReplace(oldName, newName, replaceableString));
}
return replacedString.toString();
}
private static String doReplace(String oldName, String newName, String value) {
String vOldName = oldName.replaceAll("\\.", "\\\\."); //$NON-NLS-1$ //$NON-NLS-2$
// ((\b\w+\s*\.\s*)+schema(\s*\.\s*\w+)*)|((\b\w+\s*\.\s*)*schema(\s*\.\s*\w+)+)
String regex = "((\\b\\w+\\s*\\.\\s*)+" + vOldName + "(\\s*\\.\\s*\\w+)*)|((\\b\\w+\\s*\\.\\s*)*" + vOldName + "(\\s*\\.\\s*\\w+)+)"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// obtain all varibles
String[] split = value.split(regex);
Map<String, String> replacedStrings = new HashMap<String, String>();
String returnValue = "";
StringBuffer returnValue = new StringBuffer();
// replace the variables & store both value of old and new
for (String s : split) {
if (s.contains(oldName)) {
replacedStrings.put(s, s.replaceAll("\\b" + oldName + "\\b", newName));
replacedStrings.put(s, s.replaceAll("\\b" + oldName + "\\b", newName)); //$NON-NLS-1$ //$NON-NLS-2$
} else {
replacedStrings.put(s, s);
}
}
if (split.length == 1) {
returnValue.append(replacedStrings.get(split[0]));
}
// obtain consts & concat the consts with the variables
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
Matcher matcher = pattern.matcher(value);
@@ -144,14 +333,14 @@ public final class ParameterValueUtil {
if (curPos < x) {
oldFill = value.substring(curPos, x);
if ((newFill = replacedStrings.get(oldFill)) != null) {
returnValue += newFill;
returnValue.append(newFill);
} else {
returnValue += oldFill;
returnValue.append(oldFill);
}
curPos = x;
continue;
}
returnValue += matcher.group();
returnValue.append(matcher.group());
curPos = y;
if (!matcher.find()) {
x = valueLength;
@@ -161,7 +350,68 @@ public final class ParameterValueUtil {
}
}
}
return returnValue;
return returnValue.toString();
}
/**
* DOC cmeng Comment method "isEscapeSequence".
*
* @param value
* @param i
* @return
*/
private static boolean isEscapeSequence(String value, int i) {
boolean isEscapeSequence = false;
for (int index = i; 0 < index; index--) {
if (value.charAt(index - 1) == '\\') {
isEscapeSequence = !isEscapeSequence;
} else {
break;
}
}
return isEscapeSequence;
}
private static int calcMethodArea(String varibleString, String wholeString, int beginIndex, List<Point> functionNameAreas,
int lastIndex) {
// globalMap.get(...)
// String regex = "\\b\\S*\\s*\\.\\s*\\S*\\s*\\(\\z"; //$NON-NLS-1$
// maybe get(...) also is target
String regex = "\\b[\\S\\.]*?\\s*\\("; //$NON-NLS-1$
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
Matcher matcher = pattern.matcher(varibleString);
int i = 0;
int varibleStringMaxIndex = beginIndex + varibleString.length() - 1;
while (matcher.find()) {
boolean isInQuota = false;
int parenthesisNum = 0;
Point functionNameArea = new Point(beginIndex + matcher.start(), beginIndex + matcher.end());
functionNameAreas.add(functionNameArea);
if (varibleStringMaxIndex < i || varibleStringMaxIndex < lastIndex) {
continue;
}
for (i = matcher.end(); i < wholeString.length(); i++) {
char ch = wholeString.charAt(i);
if (ch == '\"' && !isEscapeSequence(wholeString, i)) {
isInQuota = !isInQuota;
}
if (isInQuota) {
continue;
}
if (ch == '(') {
parenthesisNum++;
} else if (ch == ')') {
parenthesisNum--;
}
if (parenthesisNum < 0) {
break;
}
}
}
return i;
}
public static boolean isUseData(final IElementParameter param, final String name) {

View File

@@ -27,6 +27,7 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
@@ -69,6 +70,8 @@ public class FilteredCheckboxTree extends Composite {
*/
protected Text filterText;
protected ModifyListener filterTextModifyListener;
/**
* The control representing the clear button for the filter text entry. This value may be <code>null</code> if no
* such button exists, or if the controls have not yet been created.
@@ -199,7 +202,7 @@ public class FilteredCheckboxTree extends Composite {
showFilterControls = PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_FILTERED_TEXTS);
createControl(parent, treeStyle);
createRefreshJob();
setInitialText(WorkbenchMessages.FilteredTree_FilterMessage);
setFont(parent.getFont());
}
@@ -284,7 +287,6 @@ public class FilteredCheckboxTree extends Composite {
if (treeViewer instanceof NotifyingTreeViewer) {
patternFilter.setUseCache(true);
}
treeViewer.addFilter(patternFilter);
return treeViewer.getControl();
}
@@ -363,7 +365,6 @@ public class FilteredCheckboxTree extends Composite {
// }
// }
treeViewer.refresh(true);
if (text.length() > 0 && !initial) {
/*
* Expand elements one at a time. After each is expanded, check to see if the filter text has
@@ -453,6 +454,7 @@ public class FilteredCheckboxTree extends Composite {
*/
protected void createFilterText(Composite parent) {
filterText = doCreateFilterText(parent);
setInitialText(WorkbenchMessages.FilteredTree_FilterMessage);
filterText.getAccessible().addAccessibleListener(new AccessibleAdapter() {
/*
@@ -545,7 +547,7 @@ public class FilteredCheckboxTree extends Composite {
}
});
filterText.addModifyListener(new ModifyListener() {
filterTextModifyListener = new ModifyListener() {
/*
* (non-Javadoc)
@@ -556,7 +558,8 @@ public class FilteredCheckboxTree extends Composite {
public void modifyText(ModifyEvent e) {
textChanged();
}
});
};
filterText.addModifyListener(filterTextModifyListener);
GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
// if the text widget supported cancel then it will have it's own
@@ -594,6 +597,19 @@ public class FilteredCheckboxTree extends Composite {
calculateCheckedLeafNodes();
// narrowingDown = previousFilterText==null || getFilterString().startsWith(previousFilterText);
previousFilterText = getFilterString();
boolean hasPatternFilter = false;
for (ViewerFilter filter : treeViewer.getFilters()) {
if (filter == patternFilter) {
hasPatternFilter = true;
}
}
// add pattern filter to be the last filter
if (!hasPatternFilter) {
patternFilter.setOtherFilters(treeViewer.getFilters());
treeViewer.addFilter(patternFilter);
}
// cancel currently running job first, to prevent unnecessary redraw
refreshJob.cancel();
refreshJob.schedule(200);
@@ -700,6 +716,7 @@ public class FilteredCheckboxTree extends Composite {
}
};
// clearTextAction.setToolTipText(WorkbenchMessages.FilteredTree_ClearToolTip);
clearTextAction.setToolTipText(WorkbenchMessages.FilteredTree_ClearToolTip);
clearTextAction.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON));
clearTextAction.setDisabledImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(DCLEAR_ICON));
@@ -774,8 +791,13 @@ public class FilteredCheckboxTree extends Composite {
*/
public void setInitialText(String text) {
initialText = text;
if (filterTextModifyListener != null) {
filterText.removeModifyListener(filterTextModifyListener);
}
setFilterText(initialText);
textChanged();
if (filterTextModifyListener != null) {
filterText.addModifyListener(filterTextModifyListener);
}
}
/**

View File

@@ -28,6 +28,13 @@ import org.eclipse.ui.internal.misc.StringMatcher;
*/
public class PatternFilter extends ViewerFilter {
private ViewerFilter[] otherFilters;
/**
* Cache of element filtered by other filters
*/
private Map<Object, Object[]> filteredByOthersCache = new HashMap<Object, Object[]>();
/*
* Cache of filtered elements in the tree
*/
@@ -69,6 +76,10 @@ public class PatternFilter extends ViewerFilter {
return elements;
}
if (elements.length == 0) {
return elements;
}
if (!useCache) {
return super.filter(viewer, parent, elements);
}
@@ -240,7 +251,17 @@ public class PatternFilter extends ViewerFilter {
* @return true if the given element has children that matches the filter text
*/
protected boolean isParentMatch(Viewer viewer, Object element) {
Object[] children = ((ITreeContentProvider) ((AbstractTreeViewer) viewer).getContentProvider()).getChildren(element);
Object[] children = filteredByOthersCache.get(element);
if (children == null) {
// fix for TDI-31520 , no need to check child elements already filtered by others
children = ((ITreeContentProvider) ((AbstractTreeViewer) viewer).getContentProvider()).getChildren(element);
if (otherFilters != null) {
for (ViewerFilter filter : otherFilters) {
children = filter.filter(viewer, element, children);
}
}
filteredByOthersCache.put(element, children);
}
if ((children != null) && (children.length > 0)) {
return isAnyVisible(viewer, element, children);
@@ -302,4 +323,13 @@ public class PatternFilter extends ViewerFilter {
void setUseCache(boolean useCache) {
this.useCache = useCache;
}
/**
* Sets the otherFilters.
*
* @param otherFilters the otherFilters to set
*/
public void setOtherFilters(ViewerFilter[] otherFilters) {
this.otherFilters = otherFilters;
}
}

View File

@@ -105,6 +105,8 @@ public class ProcessorUtilities {
private static Map<String, Integer> lastGeneratedWithStatsOrTrace = new HashMap<String, Integer>();
private static Date exportTimeStamp;// time stamp create when exporting a job and reset when export ends.
private static final int GENERATED_WITH_STATS = 1;
private static final int GENERATED_WITH_TRACES = 2;
@@ -144,6 +146,11 @@ public class ProcessorUtilities {
codeLocation = exportCodeLocation;
libraryPath = exportLibraryPath;
exportConfig = true;
exportTimeStamp = new Date();
}
public static Date getExportTimestamp() {
return exportTimeStamp;
}
public static boolean isExportConfig() {
@@ -155,6 +162,7 @@ public class ProcessorUtilities {
codeLocation = null;
libraryPath = null;
exportConfig = false;
exportTimeStamp = null;
}
public static String getInterpreter() {

View File

@@ -656,6 +656,7 @@ public class DBConnectionFillerImpl extends MetadataFillerImpl {
}
String pattern = ExtractMetaDataUtils.getInstance().retrieveSchemaPatternForAS400(
iMetadataCon.getAdditionalParams());
String sid = dbConnection.getSID();
if (pattern != null && !"".equals(pattern)) { //$NON-NLS-1$
String[] multiSchems = ExtractMetaDataUtils.getInstance().getMultiSchems(pattern);
if (multiSchems != null) {
@@ -665,6 +666,8 @@ public class DBConnectionFillerImpl extends MetadataFillerImpl {
}
}
}
} else if (sid != null && !"".equals(sid)) { //$NON-NLS-1$
scheamFilterList.add(sid);
}
}
} else {
@@ -750,7 +753,11 @@ public class DBConnectionFillerImpl extends MetadataFillerImpl {
if (dbJDBCMetadata instanceof SybaseDatabaseMetaData) {
schemaRs = ((SybaseDatabaseMetaData) dbJDBCMetadata).getSchemas(catalog.getName(), null);
} else if (dbJDBCMetadata instanceof AS400DatabaseMetaData) {
schemaRs = dbJDBCMetadata.getSchemas(catalog.getName(), null);
String schemaPattern = null;
if (!schemaFilter.isEmpty()) {
schemaPattern = schemaFilter.get(0);
}
schemaRs = dbJDBCMetadata.getSchemas(catalog.getName(), schemaPattern);
} else {
schemaRs = dbJDBCMetadata.getSchemas();
}