teiid SVN: r1526 - in trunk/test-integration/db/src/main/java/org/teiid/test/framework: connection and 2 other directories.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-10-06 11:15:15 -0400 (Tue, 06 Oct 2009)
New Revision: 1526
Modified:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
Log:
Teiid 773 - updated logic to support fine grain control over which datasource type is assigned to which model
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/ConfigPropertyLoader.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -1,5 +1,7 @@
package org.teiid.test.framework;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import org.teiid.test.framework.exception.TransactionRuntimeException;
@@ -13,7 +15,7 @@
* These properties only live for the duration of one test.
*
* NOTE: System properties set by the VM will be considered long living. This is so the
- * -Dusedatasources option can be maintained for the duration of a set of tests.
+ * -Dusedatasources ( {@link ConfigPropertyNames#USE_DATASOURCES_PROP} ) option can be maintained for the duration of a set of tests.
*
*
* @author vanhalbert
@@ -28,6 +30,8 @@
public static final String DEFAULT_CONFIG_FILE_NAME = "default-config.properties";
private Properties props = null;
+
+ private Map<String, String>modelAssignedDatabaseType = new HashMap<String, String>(5);
private ConfigPropertyLoader() {
}
@@ -66,6 +70,14 @@
public Properties getProperties() {
return props;
}
+
+ public Map getModelAssignedDatabaseTypes() {
+ return this.modelAssignedDatabaseType;
+ }
+
+ public void setModelAssignedToDatabaseType(String modelname, String dbtype) {
+ this.modelAssignedDatabaseType.put(modelname, dbtype);
+ }
private void loadProperties(String filename) {
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionContainer.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -61,12 +61,14 @@
// cleanup all defined datasources for the last test and
// any overrides regarding inclusions and exclusions.
- this.dsfactory.cleanup();
-
+ if (dsfactory != null) {
+ this.dsfactory.cleanup();
+ }
// cleanup all connections created for this test.
- connStrategy.shutdown();
-
+ if (connStrategy != null) {
+ connStrategy.shutdown();
+ }
}
}
@@ -79,15 +81,16 @@
try {
setUp(test);
+ test.setConnectionStrategy(connStrategy);
+
- if (test.getNumberRequiredDataSources() > this.dsfactory.getNumberAvailableDataSources()) {
- detail(test.getTestName() + " will not be run, it requires " + test.getNumberRequiredDataSources() +
- " datasources, but only available is " + this.dsfactory.getNumberAvailableDataSources());
+ if (!test.hasRequiredDataSources()) {
return;
}
+
+
- test.setConnectionStrategy(connStrategy);
- test.setupDataSource();
+ test.setupDataSource();
debug(" setConnection");
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/TransactionQueryTest.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -62,18 +62,16 @@
void setConnectionStrategy(ConnectionStrategy connStrategy);
/**
- * The test case has to specify how many sources its using so that the correct
- * data setup is performed.
- * @return int is the number of datasources in use
+ * Indicates if the test has the required datasources in order to execute.
+ * If it doesn't have the required datasources, it will be bypassed for execution.
+ * @return true if the test has the required sources to execute
*
* @since
*/
-
- int getNumberRequiredDataSources();
+ boolean hasRequiredDataSources();
+
-
-
/**
* Called by the {@link TransactionContainer} prior to testcase processing so that
* the responsibility for performing datasource setup can be done
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -79,7 +79,7 @@
}
private void shutDownSources(Map<String, ConnectionStrategy> sources) {
- for (Iterator it=sources.keySet().iterator(); it.hasNext(); ){
+ for (Iterator<String> it=sources.keySet().iterator(); it.hasNext(); ){
ConnectionStrategy cs = sources.get(it.next());
try {
cs.shutdown();
@@ -114,6 +114,10 @@
return env;
}
+ public int getNumberAvailableDataSources() {
+ return this.dsFactory.getNumberAvailableDataSources();
+ }
+
public Map<String, DataSource> getDataSources() {
return this.datasources;
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSource.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -49,23 +49,7 @@
return this.dbtype;
}
-
- /**
- * These types match the "ddl" directories for supported database types
- * and it also found in the datasources connection.properties defined by the DB_TYPE property
- * @author vanhalbert
- *
- */
- public static interface DataSourcTypes{
- public static String MYSQL = "mysql";
- public static String ORACLE = "oracle";
- public static String POSTRES = "postgres";
- public static String SQLSERVER = "sqlserver";
- public static String DB2 = "db2";
- public static String SYBASE = "sybase";
- public static String DERBY = "derby";
+
- }
-
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/datasource/DataSourceFactory.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -16,32 +16,73 @@
/**
* The DataSourceFactory is responsible for managing the datasources used during a single test.
- * It ensures the same data source is used in both the connector binding and during validation.
- * Otherwise, validation may be validating against a source for which the test didn't run.
+ * It ensures the same data source is used in both the connector binding and during validation to ensure validation is performed
+ * against the same datasource the test was performed on.
+ *
+ * The following are the available options for controlling which datasources are used during a test:
+ * <li>Control which datasources are used and to which model they are assigned</li>
*
- * A test has the option of specifying the following properties to control which data sources are / or not used
+ * <p>
+ * Use the {@link ConfigPropertyNames#USE_DATASOURCES_PROP} property to specify a comma delimited ordered list to control which data sources to use.
*
- * <li>{@link ConfigPropertyNames#USE_DATASOURCES_PROP} : is a comma delimited ordered list to control which data sources to use</li>
+ * <br><br>
+ * This will enable integration testing to be setup to use well known combinations, to ensure coverage and makes it easier to replicate issues.
*
- * This is an ordered list because based on the model:order mapping in the config.properties file will map to the ordered list
- * respectfully.
+ * This indicates to use only the specified datasources for this test. This option can be used in test cases where only
+ * specific sources are to be used and tested against.
*
- * Example: in the config.properties may specify:
- * pm1=1
- * pm2=2
+ * This ordered list will map to the model:order mapping in the config.properties file.
+ * <br><br>
+ * Example: in the config.properties file, the models in the test and their order can be specified:
+ * <li> pm1=1 </li>
+ * <li> pm2=2 </li>
+ * <br>
*
- * Set ConfigPropertyNames.USE_DATASOURCES_PROP=oracle,sqlserver
+ * Then set property: ConfigPropertyNames.USE_DATASOURCES_PROP=oracle,sqlserver
*
- * This indicates that when a datasource is requested for "pm1", then oracle datasource will be returned. And when a data source
- * for "pm2" is requested, then a data source representing sqlserver will be returned.
+ * This will use oracle and sqlserver datasources in the test, and when a datasource is requested for model "pm1", the oracle datasource will be returned. And when a data source
+ * for "pm2" is requested, the data source mapped to 2nd ordered datasource of sqlserver will be returned.
+ *
+ * </p>
+ * <li>Control which datasources of a specific database type to exclude</li>
+ * <p>
+ *
+ * Use the {@link ConfigPropertyNames#EXCLUDE_DATASBASE_TYPES_PROP} property to specify a comma delimited list of {@link DataBaseTypes} to exclude.
+ * <br><br>
+ * This will remove all datasources of a specific database type from the list of available datasources. This option will be applied after
+ * {@link ConfigPropertyNames#USE_DATASOURCES_PROP} option. This is done because there are some test that will not work with certain database
+ * types, and therefore, if the required datasources are not met, the test will be bypassed for execution.
+ *</p>
+ * <li>Control for a specfic model, which database type of datasource to be assigned</li>
+ * <p>
+ * This option gives the developer even more fine grain control of how datasources are assigned. There are cases where a specific model must be assigned
+ * to a datasource of a specific database type.
*
- * <li>{@link ConfigPropertyNames#EXCLUDE_DATASBASE_TYPES_PROP} : is a comma delimited list indicating which data sources not use
- * during that specific test.
- *
+ * To use this option,
+ *
+ * </p>
* @author vanhalbert
*
*/
public class DataSourceFactory {
+
+ /**
+ * These types match the "ddl" directories for supported database types
+ * and it also found in the datasources connection.properties defined by the DB_TYPE property
+ * These are also the values used to specify the required database types.
+ *
+ */
+ public static interface DataBaseTypes{
+ public static String MYSQL = "mysql";
+ public static String ORACLE = "oracle";
+ public static String POSTRES = "postgres";
+ public static String SQLSERVER = "sqlserver";
+ public static String DB2 = "db2";
+ public static String SYBASE = "sybase";
+ public static String DERBY = "derby";
+ public static String ANY = "any";
+
+ }
// the DO_NO_USE_DEFAULT will be passed in when the test are run from maven and no property is passed in for UseDataSources
private static final String DO_NOT_USE_DEFAULT="${usedatasources}";
@@ -50,24 +91,31 @@
// contains the names of the datasources when the -Dusedatasources option is used
private Map<String, String> useDS = null;
- private Map<String, DataSource> useDataSources = null;
+ // contains all the datasources available to be used
+ private Map<String, DataSource> availDS = null;
// map of the datasources assigned to with model
- private Map<String, DataSource> modelToDatasourceMap = new HashMap<String, DataSource>(); // key
- // =
- // modelname
- // +
- // "_"
- // +
- // datasourceid
+ private Map<String, DataSource> modelToDatasourceMap = new HashMap<String, DataSource>(); // key = modelname
+
+ // contains any dbtype preconditions on a model, which requires a model to be assigned a certain database type
+ private Map<String, String> requiredDataBaseTypes = null; // key=modelname value=dbtype
// this set is use to track datasources that have already been assigned
private Set<String> assignedDataSources = new HashSet<String>();
private int lastassigned = 0;
+
+ // indicates if the datasource requirements have been, it will be false in the case
+ // a specific dbtype is required and that type was not one of the available types defined
+ private boolean metDBRequiredTypes = true;
+
+ // indicates that there are required dbtypes to consider
+ private boolean hasRequiredDBTypes = false;
+
public DataSourceFactory(ConfigPropertyLoader config) {
this.configprops = config;
+ this.requiredDataBaseTypes = config.getModelAssignedDatabaseTypes();
config();
}
@@ -88,8 +136,21 @@
Map<String, DataSource> availDatasources = DataSourceMgr.getInstance().getDataSources();
- useDataSources = new HashMap<String, DataSource>(availDatasources.size());
+ availDS = new HashMap<String, DataSource>(availDatasources.size());
+ String excludeprop = configprops
+ .getProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP);
+
+ Set<String> excludedDBTypes = null;
+
+ if (excludeprop != null && excludeprop.length() > 0) {
+ List<String> eprops = StringUtil.split(excludeprop, ",");
+ excludedDBTypes = new HashSet<String>(eprops.size());
+ excludedDBTypes.addAll(eprops);
+ System.out.println("EXCLUDE datasources: " + excludeprop);
+ }
+
+
String limitdsprop = configprops
.getProperty(ConfigPropertyNames.USE_DATASOURCES_PROP);
if (limitdsprop != null && limitdsprop.length() > 0 && ! limitdsprop.equalsIgnoreCase(DO_NOT_USE_DEFAULT)) {
@@ -102,46 +163,100 @@
int i = 1;
for (Iterator<String> it = dss.iterator(); it.hasNext(); i++) {
String dssName = it.next();
- useDS.put(String.valueOf(i), dssName);
ds = availDatasources.get(dssName);
- useDataSources.put(dssName, ds);
+ if (!excludedDBTypes.contains(ds.getDBType())) {
+ useDS.put(String.valueOf(i), dssName);
+
+ availDS.put(dssName, ds);
+ }
+
}
} else {
- useDataSources.putAll(availDatasources);
+ for (Iterator<DataSource> it = availDatasources.values().iterator(); it.hasNext(); ) {
+ DataSource ds = it.next();
+ if (!excludedDBTypes.contains(ds.getDBType())) {
+ availDS.put(ds.getName(), ds);
+
+ // availDS.putAll(availDatasources);
+ }
+ }
}
- String excludeprop = configprops
- .getProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP);
+// String excludeprop = configprops
+// .getProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP);
+//
+// Set<String> excludedDBTypes = null;
+//
+// if (excludeprop != null && excludeprop.length() > 0) {
+// List<String> eprops = StringUtil.split(excludeprop, ",");
+// excludedDBTypes = new HashSet<String>(eprops.size());
+// excludedDBTypes.addAll(eprops);
+// System.out.println("EXCLUDE datasources: " + excludeprop);
+//
+// Iterator<DataSource> it = availDS.values().iterator();
+//
+// // go thru all the datasources and remove those that are excluded
+// while (it.hasNext()) {
+// DataSource checkit = it.next();
+//
+// if (excludedDBTypes.contains(checkit.getDBType())) {
+// it.remove();
+//
+// if (useDS != null) {
+// useDS
+// }
+// }
+//
+//
+// }
+//
+// }
- Set<String> excludedDBTypes = null;
-
- if (excludeprop != null && excludeprop.length() > 0) {
- List<String> eprops = StringUtil.split(excludeprop, ",");
- excludedDBTypes = new HashSet<String>(eprops.size());
- excludedDBTypes.addAll(eprops);
- System.out.println("EXCLUDE datasources: " + excludeprop);
+
+ if (requiredDataBaseTypes != null) {
+ this.hasRequiredDBTypes = true;
- Iterator<DataSource> it = useDataSources.values().iterator();
+ Iterator<String> rit = this.requiredDataBaseTypes.keySet().iterator();
// go thru all the datasources and remove those that are excluded
- while (it.hasNext()) {
- DataSource checkit = it.next();
+ while (rit.hasNext()) {
+ String modelName = rit.next();
+ String rdbtype = this.requiredDataBaseTypes.get(modelName);
+
+ Iterator<DataSource> ait = availDS.values().iterator();
- if (excludedDBTypes.contains(checkit.getDBType())) {
- it.remove();
+ metDBRequiredTypes = false;
+
+ // go thru all the datasources and find the matching datasource of the correct dbtype
+ while (ait.hasNext()) {
+ DataSource ds = ait.next();
+ if (ds.getDBType().equalsIgnoreCase(rdbtype)) {
+ assignedDataSources.add(ds.getName());
+
+ modelToDatasourceMap.put(modelName, ds);
+ metDBRequiredTypes = true;
+
+ }
+
+ }
+
+ if (!metDBRequiredTypes) {
+ // did find a required dbtype, no need going any further
+ break;
+ }
+
}
- }
-
+
}
}
public int getNumberAvailableDataSources() {
- return this.useDataSources.size();
+ return (metDBRequiredTypes ? this.availDS.size() :0);
}
public synchronized DataSource getDatasource(String datasourceid,
@@ -155,7 +270,8 @@
// corresponds to the same datasource
String key = null;
- key = modelName + "_" + datasourceid;
+ key = modelName;
+ //+ "_" + datasourceid;
// if the datasourceid represents a group name, then use the group name
// so that all future request using that group name for a specified
@@ -164,49 +280,64 @@
if (modelToDatasourceMap.containsKey(key)) {
return modelToDatasourceMap.get(key);
}
+
+ if (this.hasRequiredDBTypes) {
+ if (this.requiredDataBaseTypes.containsKey(modelName)) {
+ String dbtype = this.requiredDataBaseTypes.get(modelName);
+
+ Iterator<DataSource> it = availDS.values().iterator();
- if (useDS != null) {
- String dsname = useDS.get(datasourceid);
- if (dsname != null) {
- ds = useDataSources.get(dsname);
- if (ds == null) {
- throw new QueryTestFailedException("Datasource name "
- + dsname
- + " was not found in the allDatasources map");
+ // need to go thru all the datasources to know if any has already been
+ // assigned
+ // because the datasourceid passed in was a group name
+ while (it.hasNext()) {
+ DataSource checkit = it.next();
+ if (dbtype.equalsIgnoreCase(checkit.getDBType())) {
+ ds = checkit;
+ break;
+ }
+
}
- } else {
- throw new QueryTestFailedException("Model:id " + modelName
- + ":" + datasourceid
- + " did not map to the usedatasources: "
- + useDS.toString());
+
}
+
+ } if (useDS != null) {
+ String dsname = useDS.get(datasourceid);
+ if (dsname != null) {
+ ds = availDS.get(dsname);
+ if (ds == null) {
+ throw new QueryTestFailedException("Datasource name "
+ + dsname
+ + " was not found in the allDatasources map");
+
+ }
+ } else {
+ throw new QueryTestFailedException("Model:id " + modelName
+ + ":" + datasourceid
+ + " did not map to the usedatasources: "
+ + useDS.toString());
+
+ }
+
- modelToDatasourceMap.put(key, ds);
- return ds;
-
- }
-
- Iterator<DataSource> it = useDataSources.values().iterator();
-
- // need to go thru all the datasources to know if any has already been
- // assigned
- // because the datasourceid passed in was a group name
- while (it.hasNext()) {
- DataSource checkit = it.next();
-
-// if (excludedDBTypes != null
-// && excludedDBTypes.contains(checkit.getDBType())) {
-// continue;
-// }
-
- if (!assignedDataSources.contains(checkit.getName())) {
- ds = checkit;
- assignedDataSources.add(ds.getName());
- break;
+ } else {
+
+ Iterator<DataSource> it = availDS.values().iterator();
+
+ // need to go thru all the datasources to know if any has already been
+ // assigned
+ // because the datasourceid passed in was a group name
+ while (it.hasNext()) {
+ DataSource checkit = it.next();
+
+ if (!assignedDataSources.contains(checkit.getName())) {
+ ds = checkit;
+ break;
+ }
+
}
-
}
if (ds == null) {
@@ -223,7 +354,7 @@
if (cnt == this.lastassigned) {
- ds = useDataSources.get(dsname);
+ ds = availDS.get(dsname);
this.lastassigned++;
if (lastassigned >= assignedDataSources.size()) {
@@ -243,6 +374,8 @@
}
+ assignedDataSources.add(ds.getName());
+
modelToDatasourceMap.put(key, ds);
return ds;
@@ -287,7 +420,7 @@
try {
- DataSource dsfind = factory.getDatasource("2", "model1");
+ DataSource dsfind = factory.getDatasource("2", "model2");
if (dsfind == null) {
throw new RuntimeException("No datasource was not found as the 2nd datasource");
@@ -335,6 +468,8 @@
if (ds1 == null) {
throw new RuntimeException("No datasource was found for: model:" + k);
+ } if (ds1.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
+ throw new RuntimeException("sqlserver dbtype should have been excluded");
}
}
@@ -346,7 +481,71 @@
throw new RuntimeException("The process was not able to reassign an already used datasource");
}
+
+ factory.cleanup();
+
+
+ // test required database types
+ // test 1 source
+ config = ConfigPropertyLoader.createInstance();
+
+ config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ORACLE);
+
+ factory = new DataSourceFactory(config);
+
+ DataSource ds1 = factory.getDatasource("1","pm1");
+ if (!ds1.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.ORACLE)) {
+ throw new RuntimeException("Required DB Type of oracle for model pm1 is :" + ds1.getDBType());
+ }
+
+ System.out.println("Test1 Required DS1 " + ds1.getDBType());
+ factory.cleanup();
+
+ // test required database types
+ // test 2 sources, 1 required and other ANY
+ config = ConfigPropertyLoader.createInstance();
+
+
+ config.setModelAssignedToDatabaseType("pm2", DataSourceFactory.DataBaseTypes.SQLSERVER);
+ config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ANY);
+
+ factory = new DataSourceFactory(config);
+
+ DataSource ds2 = factory.getDatasource("2","pm2");
+ if (!ds2.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
+ throw new RuntimeException("Required DB Type of sqlserver for model pm2 is :" + ds2.getDBType());
+ }
+ System.out.println("Test2 Required DS2 " + ds2.getDBType());
+
+ factory.cleanup();
+
+
+ // test required database types
+ // test 2 sources, 2 required
+ config = ConfigPropertyLoader.createInstance();
+
+
+ config.setModelAssignedToDatabaseType("pm2", DataSourceFactory.DataBaseTypes.SQLSERVER);
+ config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ORACLE);
+
+ factory = new DataSourceFactory(config);
+
+ DataSource ds3a = factory.getDatasource("2","pm2");
+ if (!ds3a.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
+ throw new RuntimeException("Required DB Type of sqlserver for model pm12 is :" + ds3a.getDBType());
+ }
+
+ DataSource ds3b = factory.getDatasource("2","pm1");
+ if (!ds3b.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.ORACLE)) {
+ throw new RuntimeException("Required DB Type of oracle for model pm1 is :" + ds3b.getDBType());
+ }
+ System.out.println("Test3 Required DS3a " + ds3a.getDBType());
+ System.out.println("Test3 Required DS3b " + ds3b.getDBType());
+
+ factory.cleanup();
+
+
} catch (QueryTestFailedException e) {
e.printStackTrace();
}
Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java 2009-10-06 15:13:18 UTC (rev 1525)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/transaction/LocalTransaction.java 2009-10-06 15:15:15 UTC (rev 1526)
@@ -35,7 +35,7 @@
}
protected void after(TransactionQueryTest test) {
- // boolean exception = false;
+ boolean exception = false;
try {
if (test.rollbackAllways()|| test.exceptionOccurred()) {
test.getConnection().rollback();
@@ -45,7 +45,7 @@
test.getConnection().commit();
}
} catch (SQLException se) {
-// exception = true;
+ exception = true;
// if exception, try to trigger the rollback
try {
test.getConnection().rollback();
@@ -58,13 +58,13 @@
} finally {
// if an exception occurs and the autocommit is set to true - while doing a transaction
// will generate a new exception overriding the first exception
-// if (!exception) {
-// try {
-// test.getConnection().setAutoCommit(true);
-// } catch (SQLException e) {
-// throw new RuntimeException(e);
-// }
-// }
+ if (!exception) {
+ try {
+ test.getConnection().setAutoCommit(true);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
}
15 years, 2 months
teiid SVN: r1525 - in trunk/test-integration/db/src/main/java/org/teiid/test/framework: query and 1 other directory.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-10-06 11:13:18 -0400 (Tue, 06 Oct 2009)
New Revision: 1525
Added:
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/QueryExecution.java
Log:
Teiid 773 - refactored out of the test code into the main framework code
Added: trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java 2009-10-06 15:13:18 UTC (rev 1525)
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2000-2007 MetaMatrix, Inc.
+ * All rights reserved.
+ */
+package org.teiid.test.framework.query;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.sql.XAConnection;
+
+import org.teiid.test.framework.TransactionContainer;
+import org.teiid.test.framework.TransactionQueryTest;
+import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
+import org.teiid.test.framework.connection.ConnectionStrategy;
+import org.teiid.test.framework.connection.ConnectionUtil;
+import org.teiid.test.framework.datasource.DataSource;
+import org.teiid.test.framework.datasource.DataSourceSetup;
+import org.teiid.test.framework.datasource.DataSourceSetupFactory;
+import org.teiid.test.framework.exception.QueryTestFailedException;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+
+/**
+ * The AbstractQueryTransactionTest is the class that should be extended when
+ * a testcase is being created to validate certain behavior
+ *
+ * @see QueryExecution for use when direct queries to the source are used
+ * to validate the results of the testcase.
+ *
+ */
+public abstract class AbstractQueryTransactionTest extends AbstractQueryTest implements TransactionQueryTest{
+ protected Properties executionProperties = null;
+ protected String testname = "NA";
+
+ protected Map<String, DataSource> datasources = null;
+
+ protected ConnectionStrategy connStrategy;
+
+
+ public AbstractQueryTransactionTest() {
+ super();
+ }
+
+ public AbstractQueryTransactionTest(String testname) {
+ super();
+ this.testname = testname;
+ }
+
+ public String getTestName() {
+ return this.testname;
+ }
+
+
+ @Override
+ public void setConnectionStrategy(ConnectionStrategy connStrategy) {
+ this.connStrategy = connStrategy;
+
+ this.datasources = this.connStrategy.getDataSources();
+
+ }
+
+ public void setExecutionProperties(Properties props) {
+ assertNotNull(props);
+ this.executionProperties = props;
+ }
+ @Override
+ protected void compareResults(BufferedReader resultReader, BufferedReader expectedReader) throws IOException {
+ assertEquals(read(expectedReader, compareResultsCaseSensitive()) , read(resultReader, compareResultsCaseSensitive()));
+ }
+
+ @Override protected void assignExecutionProperties(Statement stmt) {
+ if (this.executionProperties != null) {
+ if (stmt instanceof com.metamatrix.jdbc.api.Statement) {
+ com.metamatrix.jdbc.api.Statement statement = (com.metamatrix.jdbc.api.Statement)stmt;
+ String txnautowrap = this.executionProperties.getProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP);
+ if (txnautowrap != null) {
+ statement.setExecutionProperty(CONNECTION_STRATEGY_PROPS.TXN_AUTO_WRAP, txnautowrap);
+ }
+
+ if (this.executionProperties.getProperty(CONNECTION_STRATEGY_PROPS.FETCH_SIZE) != null) {
+ statement.setExecutionProperty(CONNECTION_STRATEGY_PROPS.FETCH_SIZE, this.executionProperties.getProperty(CONNECTION_STRATEGY_PROPS.FETCH_SIZE));
+ }
+ }
+ }
+
+ }
+
+ public boolean hasRequiredDataSources() {
+ boolean rtn = true;
+
+ if (getNumberRequiredDataSources() == 0 || getNumberRequiredDataSources() > this.connStrategy.getNumberAvailableDataSources()) {
+ this.print(getTestName() + " will not be run, it requires " + getNumberRequiredDataSources() +
+ " datasources, but only available is " + this.connStrategy.getNumberAvailableDataSources());
+ return false;
+
+ }
+
+
+
+
+ return rtn;
+ }
+
+ public int getNumberRequiredDataSources() {
+ return 1;
+ }
+
+ public boolean compareResultsCaseSensitive() {
+ return true;
+ }
+
+
+ /**
+ * Override <code>setupDataSource</code> if there is different mechinism for
+ * setting up the datasources for the testcase
+ * @throws QueryTestFailedException
+ * @throws QueryTestFailedException
+ *
+ * @since
+ */
+ @Override
+ public void setupDataSource() throws QueryTestFailedException {
+
+ DataSourceSetup dss = DataSourceSetupFactory.createDataSourceSetup(this.getNumberRequiredDataSources());
+ dss.setup(datasources, connStrategy);
+
+ }
+
+
+ public Connection getSource(String identifier) throws QueryTestFailedException {
+ return ConnectionUtil.getConnection(identifier, this.datasources, this.connStrategy);
+ }
+
+ public XAConnection getXASource(String identifier) throws QueryTestFailedException {
+ return ConnectionUtil.getXAConnection(identifier, this.datasources, this.connStrategy);
+ }
+
+
+ /**
+ * Implement testCase(), it is the entry point to the execution of the test.
+ * @throws Exception
+ *
+ * @since
+ */
+ public abstract void testCase() throws Exception;
+
+ /**
+ * Indicates what should be done when a failure occurs in {@link #testCase()}
+ * @return
+ *
+ * @since
+ */
+ public boolean rollbackAllways() {
+ return false;
+ }
+
+ /**
+ * Override <code>before</code> if there is behavior that needs to be performed
+ * prior to {@link #testCase()} being called.
+ *
+ *
+ * @since
+ */
+ public void before() {
+ }
+
+ /**
+ * Override <code>after</code> if there is behavior that needs to be performed
+ * after {@link #testCase()} being called.
+ *
+ *
+ * @since
+ */
+ public void after() {
+ }
+
+
+ @Override
+ public void validateTestCase() throws Exception {
+
+ }
+
+
+ /**
+ * At end of each test, perfoom any cleanup that your test requires.
+ * Note: Do not cleanup any connections. That is performed by
+ * the {@link TransactionContainer#runTransaction(TransactionQueryTest)} at the end of the test.
+ */
+ public void cleanup() {
+
+ }
+
+ @Override
+ public XAConnection getXAConnection() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+
+}
Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/AbstractQueryTransactionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/QueryExecution.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/QueryExecution.java (rev 0)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/QueryExecution.java 2009-10-06 15:13:18 UTC (rev 1525)
@@ -0,0 +1,21 @@
+package org.teiid.test.framework.query;
+
+import java.sql.Connection;
+
+import com.metamatrix.jdbc.api.AbstractQueryTest;
+
+/**
+ * The QueryExecution class can be used to query the source directly. The intended use
+ * of this class is for validating results after the execution of a test case.
+ *
+ * @see AbstractQueryTransactionTest regarding creating a testcase to validate behavior.
+ * @author vanhalbert
+ *
+ */
+public class QueryExecution extends AbstractQueryTest {
+
+ public QueryExecution(Connection conn) {
+ super(conn);
+ }
+
+}
Property changes on: trunk/test-integration/db/src/main/java/org/teiid/test/framework/query/QueryExecution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 2 months
teiid SVN: r1524 - trunk/test-integration/db/src/main/resources.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-10-06 11:09:43 -0400 (Tue, 06 Oct 2009)
New Revision: 1524
Modified:
trunk/test-integration/db/src/main/resources/default-config.properties
trunk/test-integration/db/src/main/resources/xa-config.properties
Log:
Teiid 773 - changed to use the TeiidDataSource class
Modified: trunk/test-integration/db/src/main/resources/default-config.properties
===================================================================
--- trunk/test-integration/db/src/main/resources/default-config.properties 2009-10-06 15:07:03 UTC (rev 1523)
+++ trunk/test-integration/db/src/main/resources/default-config.properties 2009-10-06 15:09:43 UTC (rev 1524)
@@ -17,7 +17,8 @@
# properties for Teiid connection
##########################################
#driver=org.teiid.jdbc.TeiidDriver
-driver=com.metamatrix.jdbc.EmbeddedDataSource
+driver=org.teiid.jdbc.TeiidDataSource
+
URL=jdbc:metamatrix:Transaction@target/classes/transactions/transaction.properties;user=admin;password=teiid
User=admin
Password=teiid
Modified: trunk/test-integration/db/src/main/resources/xa-config.properties
===================================================================
--- trunk/test-integration/db/src/main/resources/xa-config.properties 2009-10-06 15:07:03 UTC (rev 1523)
+++ trunk/test-integration/db/src/main/resources/xa-config.properties 2009-10-06 15:09:43 UTC (rev 1524)
@@ -1,8 +1,6 @@
##########################################
# Common Properties for everybody
##########################################
-# local, xa, jndi
-transaction-type=xa
process-batch = 20
connector-batch = 20
@@ -14,7 +12,7 @@
##########################################
# properties for Teiid connection
##########################################
-driver=com.metamatrix.jdbc.EmbeddedDataSource
+driver=org.teiid.jdbc.TeiidDataSource
URL=jdbc:metamatrix:Transaction@target/classes/transactions/transaction.properties;user=admin;password=teiid
User=admin
Password=teiid
15 years, 2 months
teiid SVN: r1523 - trunk/test-integration/db/src/main/resources.
by teiid-commits@lists.jboss.org
Author: vhalbert(a)redhat.com
Date: 2009-10-06 11:07:03 -0400 (Tue, 06 Oct 2009)
New Revision: 1523
Modified:
trunk/test-integration/db/src/main/resources/configuration.xml
Log:
Teiid 773 - adding the testing of the datadirect drivers
Modified: trunk/test-integration/db/src/main/resources/configuration.xml
===================================================================
--- trunk/test-integration/db/src/main/resources/configuration.xml 2009-10-05 15:26:10 UTC (rev 1522)
+++ trunk/test-integration/db/src/main/resources/configuration.xml 2009-10-06 15:07:03 UTC (rev 1523)
@@ -268,7 +268,7 @@
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="sun.jdbc.odbc.JdbcOdbcDriver" IsRequired="true" />
<PropertyDefinition Name="URL" DisplayName="JDBC URL" ShortDescription="" DefaultValue="jdbc:odbc:Driver={MicroSoft Excel Driver (*.xls)};DBQ=<filePathToExcelFile>" IsRequired="true" />
</ComponentType>
- <!--
+
<ComponentType Name="Datadirect DB2 8 Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="JDBC Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" LastChangedDate="2008-10-31T10:26:19.928-06:00" CreatedBy="ConfigurationStartup" CreationDate="2008-10-31T10:26:19.928-06:00">
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" DefaultValue="com.metamatrix.jdbcx.db2.DB2DataSource" IsRequired="true" />
<PropertyDefinition Name="URL" DisplayName="JDBC URL" ShortDescription="" DefaultValue="jdbc:mmx:db2://<host>:50000;DatabaseName=<databasename>;CollectionID=<collectionid>;PackageName=<packagename>" IsRequired="true" />
@@ -294,7 +294,7 @@
<PropertyDefinition Name="IsXA" DisplayName="Is XA" ShortDescription="Is XA" DefaultValue="true" IsRequired="true" PropertyType="Boolean" />
<PropertyDefinition Name="SetCriteriaBatchSize" DisplayName="Max Values in IN Predicate" ShortDescription="Max number of values in an IN Predicate. Must be >= 0." DefaultValue="250" PropertyType="Integer" IsExpert="true" />
</ComponentType>
- --> <ComponentType Name="LDAP Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" LastChangedDate="2008-10-31T10:26:19.946-06:00" CreatedBy="ConfigurationStartup" CreationDate="2008-10-31T10:26:19.946-06:00">
+ <ComponentType Name="LDAP Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" LastChangedDate="2008-10-31T10:26:19.946-06:00" CreatedBy="ConfigurationStartup" CreationDate="2008-10-31T10:26:19.946-06:00">
<PropertyDefinition Name="ConnectorTypeClassPath" DisplayName="Connector Type Class Path" ShortDescription="Connector Type classpath (defined by system, do not modify)" DefaultValue="extensionjar:connector_patch.jar;extensionjar:connector-ldap-6.2.0-SNAPSHOT.jar;" IsModifiable="false" />
<PropertyDefinition Name="SearchDefaultBaseDN" DisplayName="Default Search Base DN" ShortDescription="Default Base DN for LDAP Searches" IsExpert="true" />
<PropertyDefinition Name="LdapAdminUserDN" DisplayName="Ldap Admin User DN" ShortDescription="User DN for the LDAP admin account." DefaultValue="cn=<>,ou=<>,dc=<>" IsRequired="true" />
15 years, 2 months
teiid SVN: r1522 - in trunk: client/src/main/java/com/metamatrix/jdbc/api and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-10-05 11:26:10 -0400 (Mon, 05 Oct 2009)
New Revision: 1522
Modified:
trunk/adminshell/src/main/resources/scripts/jdbc.bsh
trunk/client/src/main/java/com/metamatrix/jdbc/api/TextOutputVisitor.java
trunk/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml
Log:
TEIID-845 adding documentation and the ability to show a text plan
Modified: trunk/adminshell/src/main/resources/scripts/jdbc.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/jdbc.bsh 2009-10-05 14:44:52 UTC (rev 1521)
+++ trunk/adminshell/src/main/resources/scripts/jdbc.bsh 2009-10-05 15:26:10 UTC (rev 1522)
@@ -12,6 +12,7 @@
import java.sql.*;
import com.metamatrix.script.io.*;
import com.metamatrix.jdbc.api.*;
+import com.metamatrix.jdbc.*;
protected Connection getConnection() {
if (currentContext().internalConnection != void && currentContext().internalConnection != null) {
@@ -258,10 +259,18 @@
printResults(currentContext().internalResultSet, fileName);
}
-void showPlan() {
+void showPlan(boolean xml) {
+ if (currentContext().internalStatement == void || currentContext().internalStatement == null) {
+ print("Statement is null - execute then issue showPlan");
+ return;
+ }
PlanNode queryPlan = ((MMResultSet)currentContext().internalStatement).getPlanDescription();
if (queryPlan != null) {
- print(XMLOutputVisitor.convertToXML(queryPlan));
+ if (xml != null && xml) {
+ print(XMLOutputVisitor.convertToXML(queryPlan));
+ } else {
+ print(TextOutputVisitor.convertToText(queryPlan));
+ }
} else {
print("No plan provided - add OPTION SHOWPLAN");
}
Modified: trunk/client/src/main/java/com/metamatrix/jdbc/api/TextOutputVisitor.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/jdbc/api/TextOutputVisitor.java 2009-10-05 14:44:52 UTC (rev 1521)
+++ trunk/client/src/main/java/com/metamatrix/jdbc/api/TextOutputVisitor.java 2009-10-05 15:26:10 UTC (rev 1522)
@@ -161,5 +161,11 @@
protected void visitContainerProperty(PlanNode node, String propertyName, Collection propertyValue) {
}
+
+ public static String convertToText(PlanNode node, int initialTabs) {
+ TextOutputVisitor visitor = new TextOutputVisitor(new DefaultDisplayHelper(), initialTabs);
+ visitor.visit(node);
+ return visitor.getText();
+ }
}
Modified: trunk/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml
===================================================================
--- trunk/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml 2009-10-05 14:44:52 UTC (rev 1521)
+++ trunk/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml 2009-10-05 15:26:10 UTC (rev 1522)
@@ -38,15 +38,22 @@
/**
* Prints the previously executed ResultSet to system out, in the form required by the assert call. Usally in
* the interactive more the resultset is automatically read, so this applies only in the script mode.
- * @param comparemode - true - print in the format that can be used in the regression tests
- * - false - print to console
+ * @param comparePrint - true - print in the format that can be used in the regression tests
+ * - false - print to console
*/
-printResults(boolean true);
+printResults(boolean comparePrint);
/**
* Walks the ResultSet, but does not print any results. Good for performance testing. Usally in
* the interactive more the resultset is automatically read, so this applies only in the script mode.
*/
-walkResults()
+walkResults();
+
+/**
+ * Shows the plan associated with the last executed statement.
+ * @param xml - true - show in xml form
+ * - false - show in text form
+ */
+showPlan(boolean xml);
]]></programlisting>
</appendix>
\ No newline at end of file
15 years, 2 months
teiid SVN: r1521 - in trunk: adminshell/src/main/resources/scripts and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-10-05 10:44:52 -0400 (Mon, 05 Oct 2009)
New Revision: 1521
Added:
trunk/adminshell/src/main/java/com/metamatrix/script/shell/Util.java
Modified:
trunk/adminshell/src/main/resources/scripts/assert.bsh
trunk/adminshell/src/main/resources/scripts/jdbc.bsh
trunk/adminshell/src/main/resources/scripts/util.bsh
trunk/client-jdbc/src/main/java/com/metamatrix/script/io/ResultSetReader.java
trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectConverterUtil.java
Log:
TEIID-845 TEIID-866 TEIID-830 correcting the reported recount, changing the handling of statements to not assume resultsets, and added a utility method for showing the query plan.
Added: trunk/adminshell/src/main/java/com/metamatrix/script/shell/Util.java
===================================================================
--- trunk/adminshell/src/main/java/com/metamatrix/script/shell/Util.java (rev 0)
+++ trunk/adminshell/src/main/java/com/metamatrix/script/shell/Util.java 2009-10-05 14:44:52 UTC (rev 1521)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.script.shell;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.metamatrix.core.util.ObjectConverterUtil;
+import com.metamatrix.jdbc.util.MMJDBCURL;
+
+public class Util {
+
+ public static byte[] readBinaryFile(String fileName) throws IOException {
+ InputStream is = null;
+
+ if(fileName == null) {
+ throw new IOException("fileName is null");
+ }
+ try {
+ //try to load file from the classpath
+ is = Object.class.getResourceAsStream("/"+fileName);
+
+ byte[] result;
+ if (is == null) {
+ //load from "hardcoded" path
+ is = new FileInputStream(new File(fileName));
+ }
+
+
+ }catch(Exception e) {
+ if (is == null) {
+ try {
+ //load from "hardcoded" path
+ is = new FileInputStream(new File(fileName));
+ }catch(Exception e2) {
+
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ }
+
+ //convert to bytes
+ byte[] result = ObjectConverterUtil.convertToByteArray(is);
+ try {
+ is.close();
+ }catch(Exception e3) {
+ }
+ return result;
+ }
+
+ public static char[] readTextFile(String fileName) throws IOException {
+ if(fileName == null) {
+ throw new IOException("fileName is null");
+ }
+ char[] result = null;
+
+ try {
+ File file = new File(fileName);
+
+ // changed to use the ObectConverterUtil, instead of the
+ // convertToCharArray() method because it doesn't completely
+ // convert the file, the XML reader throws a malform exception
+ // the test case for ServerAdminImpl also the ObjectConverterUtil
+ // that's why this was changed to use it
+ result = ObjectConverterUtil.convertFileToCharArray(file, null);
+
+ }catch(Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ public static void cleanUpDirectory(String dirName, String[] filesToKeep){
+ File dir = new File(dirName);
+ if (dir.exists()) {
+ File[] files = dir.listFiles();
+ for (File f:files) {
+ if (f.getName().endsWith(".deleted")) {
+ continue;
+ }
+ boolean delete = true;
+ for (String keep:filesToKeep) {
+ if (f.getName().equalsIgnoreCase(keep)) {
+ delete = false;
+ break;
+ }
+ }
+ if (delete) f.delete();
+ }
+ }
+ }
+
+ public static char[] convertToCharArray(InputStream in) throws IOException {
+ return ObjectConverterUtil.convertToCharArray(in, Integer.MAX_VALUE, null);
+ }
+
+ public static String extractVDBName(String url) {
+ MMJDBCURL mmurl = new MMJDBCURL(url);
+ return mmurl.getVDBName();
+ }
+
+ public static String extractHost(String url) {
+ MMJDBCURL mmurl = new MMJDBCURL(url);
+ return mmurl.getConnectionURL();
+ }
+
+}
Property changes on: trunk/adminshell/src/main/java/com/metamatrix/script/shell/Util.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/adminshell/src/main/resources/scripts/assert.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/assert.bsh 2009-10-02 19:08:46 UTC (rev 1520)
+++ trunk/adminshell/src/main/resources/scripts/assert.bsh 2009-10-05 14:44:52 UTC (rev 1521)
@@ -1,185 +1,8 @@
import junit.framework.*;
+static import junit.framework.Assert.*;
import com.metamatrix.script.junit.*;
-// This file has all the assetion routines that JUnit Assert class provides
+// This file has all the assertion routines that JUnit Assert class provides
-void assertEquals(boolean expected, boolean actual) {
- Assert.assertEquals(expected, actual);
-}
-
-
-void assertEquals(byte expected, byte actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertEquals(char expected, char actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertEquals(
- double expected,
- double actual,
- double delta) {
- Assert.assertEquals(expected, actual, delta);
-}
-
-void assertEquals(
- float expected,
- float actual,
- float delta) {
- Assert.assertEquals(expected, actual, delta);
-}
-
-void assertEquals(int expected, int actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertEquals(Object expected, Object actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertEquals(
- String message,
- boolean expected,
- boolean actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(
- String message,
- byte expected,
- byte actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(
- String message,
- char expected,
- char actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(
- String message,
- double expected,
- double actual,
- double delta) {
- Assert.assertEquals(message, expected, actual, delta);
-}
-
-void assertEquals(
- String message,
- float expected,
- float actual,
- float delta) {
- Assert.assertEquals(message, expected, actual, delta);
-}
-
-void assertEquals(String message, int expected, int actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(
- String message,
- Object expected,
- Object actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(String expected, String actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertEquals(
- String message,
- String expected,
- String actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(
- String message,
- long expected,
- long actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(
- String message,
- short expected,
- short actual) {
- Assert.assertEquals(message, expected, actual);
-}
-
-void assertEquals(long expected, long actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertEquals(short expected, short actual) {
- Assert.assertEquals(expected, actual);
-}
-
-void assertFalse(boolean condition) {
- Assert.assertFalse(condition);
-}
-
-void assertFalse(String message, boolean condition) {
- Assert.assertFalse(message, condition);
-}
-
-void assertNotNull(Object object) {
- Assert.assertNotNull(object);
-}
-
-void assertNotNull(String message, Object object) {
- Assert.assertNotNull(message, object);
-}
-
-void assertNotSame(Object expected, Object actual) {
- Assert.assertNotSame(expected, actual);
-}
-
-void assertNotSame(
- String message,
- Object expected,
- Object actual) {
- Assert.assertNotSame(message, expected, actual);
-}
-
-void assertNull(Object object) {
- Assert.assertNull(object);
-}
-
-void assertNull(String message, Object object) {
- Assert.assertNull(message, object);
-}
-
-void assertSame(Object expected, Object actual) {
- Assert.assertSame(expected, actual);
-}
-
-void assertSame(
- String message,
- Object expected,
- Object actual) {
- Assert.assertSame(message, expected, actual);
-}
-
-void assertTrue(boolean condition) {
- Assert.assertTrue(condition);
-}
-
-void assertTrue(String message, boolean condition) {
- Assert.assertTrue(message, condition);
-}
-
-void fail() {
- Assert.fail();
-}
-
-void fail(String message) {
- Assert.fail(message);
-}
-
void runTests(String scriptName) {
BshTestSuite suite = new BshTestSuite(scriptName);
suite.addTest(scriptName); //$NON-NLS-1$
Modified: trunk/adminshell/src/main/resources/scripts/jdbc.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/jdbc.bsh 2009-10-02 19:08:46 UTC (rev 1520)
+++ trunk/adminshell/src/main/resources/scripts/jdbc.bsh 2009-10-05 14:44:52 UTC (rev 1521)
@@ -11,6 +11,7 @@
import java.sql.*;
import com.metamatrix.script.io.*;
+import com.metamatrix.jdbc.api.*;
protected Connection getConnection() {
if (currentContext().internalConnection != void && currentContext().internalConnection != null) {
@@ -144,26 +145,8 @@
/**
* Execute a Statement and save the ResultSet or update count.
*/
-void execute(String sql) throws SQLException {
- checkConnection();
-
- // close last statement and result set if necessary
- closeStatement();
-
- // create new statement
- currentContext().internalStatement = currentContext().internalConnection.createStatement();
- try {
- debug("Executing sql: " + sql);
- currentContext().internalResultSet = currentContext().internalStatement.executeQuery(sql);
- if (interactive()) {
- record("printResults();\n");
- printResults();
- }
- } catch(SQLException e) {
- closeStatement();
- debug(e);
- throw e;
- }
+void execute(String sql) throws SQLException {
+ execute(sql, null);
}
/**
@@ -187,10 +170,7 @@
try {
debug("Executing batch of : " + cmds.length);
currentContext().internalUpdatedList = currentContext().internalStatement.executeBatch();
- if (interactive()) {
- record("printResults();\n");
- printResults();
- }
+ print ("update counts: " + Arrays.toString(currentContext().internalUpdatedList));
} catch(SQLException e) {
closeStatement();
debug(e);
@@ -229,47 +209,31 @@
// close last statement and result set if necessary
closeStatement();
-
- if ( (sql.indexOf("?") != -1) && (params == null || params.length == 0)) {
- throw new SQLException ("Wrong!, No Parameters supplied to statement.");
- }
-
- sqlLow = sql.toLowerCase();
-
+
try {
- if (sqlLow.startsWith("select")) {
+ if (params != null) {
debug("Executing a prepared Statement:"+sql);
currentContext().internalStatement = currentContext().internalConnection.prepareStatement(sql);
setStatementDefaults();
setParameters(params);
- currentContext().internalResultSet = currentContext().internalStatement.executeQuery();
+ hasResultSet = currentContext().internalStatement.execute();
}
- else if (sqlLow.startsWith("update") || sqlLow.startsWith("delete") || sqlLow.startsWith("insert")) {
- debug("Executing a prepared statement:"+sql);
- currentContext().internalStatement = currentContext().internalConnection.prepareStatement(sql);
+ else {
+ debug("Executing statement:"+sql);
+ currentContext().internalStatement = currentContext().internalConnection.createStatement();
setStatementDefaults();
- setParameters(params);
- currentContext().internalResultSet = null;
- int row_affected = currentContext().internalStatement.executeUpdate();
- print (row_affected+" rows got affected.");
+ hasResultSet = currentContext().internalStatement.execute(sql);
}
- else if (sqlLow.startsWith("exec ") ) {
- sql = sql.substring(4);
-
- debug ("Executing a Callable statement:"+sql);
- currentContext().internalStatement = currentContext().internalConnection.prepareCall("{?=call " + sql + "}");
- setStatementDefaults();
- setParameters(params);
- currentContext().internalResultSet = currentContext().internalStatement.executeQuery();
- }
- else {
- throw new SQLException("Not a valid statement!, it must start with (Select|Insert|Update|Delete|Stored Proc)");
+ if (hasResultSet) {
+ currentContext().internalResultSet = currentContext().internalStatement.getResultSet();
+ if (interactive()) {
+ record("printResults();\n");
+ printResults();
+ }
+ } else {
+ currentContext().internalUpdateCount = currentContext().internalStatement.getUpdateCount();
+ print ("update count:" +currentContext().internalUpdateCount);
}
-
- if (interactive()) {
- record("printResults();\n");
- printResults();
- }
} catch(SQLException e) {
closeStatement();
debug(e);
@@ -294,6 +258,14 @@
printResults(currentContext().internalResultSet, fileName);
}
+void showPlan() {
+ PlanNode queryPlan = ((MMResultSet)currentContext().internalStatement).getPlanDescription();
+ if (queryPlan != null) {
+ print(XMLOutputVisitor.convertToXML(queryPlan));
+ } else {
+ print("No plan provided - add OPTION SHOWPLAN");
+ }
+}
void walkResults() {
rs = currentContext().internalResultSet;
@@ -311,11 +283,10 @@
print("ResultSet is null");
return;
}
- row = -1; // -1 to compensate for the header row.
- BufferedReader in = new BufferedReader(new ResultSetReader(results));
+ ResultSetReader reader = new ResultSetReader(results);
+ BufferedReader in = new BufferedReader(reader);
String line = in.readLine();
while(line != null) {
- row++;
if (comparePrint) {
line=line.replaceAll("\"", "\\\\\"");
print("\""+line+"\",");
@@ -325,7 +296,7 @@
}
line = in.readLine();
}
- print("Fetched "+row+" rows\n");
+ print("Fetched "+reader.getRowCount()+" rows\n");
}
private void printResults(ResultSet results, File resultsFile) throws SQLException {
@@ -333,17 +304,16 @@
print("ResultSet is null");
return;
}
- row = -1; // -1 to compensate for the header row.
- BufferedReader in = new BufferedReader(new ResultSetReader(results));
+ ResultSetReader reader = new ResultSetReader(results);
+ BufferedReader in = new BufferedReader(reader);
PrintWriter writer = new PrintWriter(new FileWriter(resultsFile));
String line = in.readLine();
while(line != null) {
- row++;
writer.println(line);
line = in.readLine();
}
writer.close();
- print("Wrote "+row+" rows to File="+resultsFile.getName()+"\n");
+ print("Wrote "+reader.getRowCount()+" rows to File="+resultsFile.getName()+"\n");
}
void assertRowCount(int expected) {
@@ -368,7 +338,8 @@
if(currentContext().internalStatement != void && currentContext().internalStatement != null) {
Statement stmt = currentContext().internalStatement;
closeResultSet();
-
+ currentContext().internalUpdateCount = -1;
+ currentContext().internalUpdatedList = null;
try {
debug("Closing statement...");
stmt.close();
Modified: trunk/adminshell/src/main/resources/scripts/util.bsh
===================================================================
--- trunk/adminshell/src/main/resources/scripts/util.bsh 2009-10-02 19:08:46 UTC (rev 1520)
+++ trunk/adminshell/src/main/resources/scripts/util.bsh 2009-10-05 14:44:52 UTC (rev 1521)
@@ -3,6 +3,8 @@
import com.metamatrix.core.util.*;
import java.lang.reflect.*;
import com.metamatrix.common.comm.exception.*;
+static import com.metamatrix.core.util.ObjectConverterUtil.*;
+static import com.metamatrix.script.shell.Util.*;
debug=false;
@@ -14,105 +16,6 @@
return currentContext().internalPrompt;
}
-byte[] readBinaryFile(String fileName) {
- InputStream is = null;
-
- if(fileName == null) {
- throw new IOException("fileName is null");
- }
- try {
- //try to load file from the classpath
- is = Object.class.getResourceAsStream("/"+fileName);
-
- byte[] result;
- if (is == null) {
- //load from "hardcoded" path
- is = new FileInputStream(new File(fileName));
- }
-
-
- }catch(Exception e) {
- if (is == null) {
- try {
- //load from "hardcoded" path
- is = new FileInputStream(new File(fileName));
- }catch(Exception e2) {
-
- e.printStackTrace();
- return null;
- }
- }
-
- }
-
- //convert to bytes
- result = convertToByteArray(is);
- try {
- is.close();
- }catch(Exception e3) {
- }
- return result;
-}
-
-char[] readTextFile(String fileName) {
- if(fileName == null) {
- throw new IOException("fileName is null");
- }
- char[] result = null;
-
- try {
- File file = new File(fileName);
-
- // changed to use the ObectConverterUtil, instead of the
- // convertToCharArray() method because it doesn't completely
- // convert the file, the XML reader throws a malform exception
- // the test case for ServerAdminImpl also the ObjectConverterUtil
- // that's why this was changed to use it
- result = ObjectConverterUtil.convertFileToCharArray(file, null);
-
- }catch(e) {
- e.printStackTrace();
- }
- return result;
-}
-
-byte[] convertToByteArray(InputStream in) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream(10 * 1024);
- int b = 0;
- while ((b = in.read()) != -1) {
- out.write(b);
- }
- return out.toByteArray();
-}
-
-char[] convertToCharArray(InputStream in) throws IOException {
- CharArrayWriter out = new CharArrayWriter(10 * 1024);
- int b = 0;
- while ((b = in.read()) != -1) {
- out.write(b);
- }
- return out.toCharArray();
-}
-
-cleanUpDirectory(String dirName, String[] filesToKeep){
- dir = new File(dirName);
- if (dir.exists()) {
- files = dir.listFiles();
- for (File f:files) {
- delete = true;
- for (String keep:filesToKeep) {
- if (f.getName().equalsIgnoreCase(keep)) {
- delete = false;
- }
- if (f.getName().endsWith(".deleted")) {
- delete = false;
- }
- }
- if (delete) f.delete();
- }
- }
-}
-
void checkAdmin() {
context = currentContext();
if (context == void || context == null) {
@@ -142,38 +45,6 @@
}
}
-String extractVDBName(url) {
- str = "jdbc:metamatrix:";
- strteiid = "jdbc:teiid:";
- if (url.startsWith(str)) {
- int at = url.indexOf("@");
- if (at != -1) {
- return url.substring(str.length(), at);
- }
- }
- else if (url.startsWith(strteiid)) {
- int at = url.indexOf("@");
- if (at != -1) {
- return url.substring(strteiid.length(), at);
- }
- }
- return "";
-}
-
-String extractHost(url) {
- str = "jdbc:metamatrix:";
- strteiid = "jdbc:teiid:";
- if (url.startsWith(str)) {
- int at = url.indexOf("@")+1;
- return url.substring(at, url.indexOf(";", at));
- }
- else if (url.startsWith(strteiid)) {
- int at = url.indexOf("@")+1;
- return url.substring(at, url.indexOf(";", at));
- }
- return "";
-}
-
class ExceptionHandler implements InvocationHandler{
Object impl;
ExceptionHandler(Object obj){
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/script/io/ResultSetReader.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/script/io/ResultSetReader.java 2009-10-02 19:08:46 UTC (rev 1520)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/script/io/ResultSetReader.java 2009-10-05 14:44:52 UTC (rev 1521)
@@ -60,6 +60,8 @@
boolean firstTime = true;
int[] columnTypes = null;
+ private int rowCount;
+
public ResultSetReader(ResultSet in) {
this.source = in;
}
@@ -103,6 +105,7 @@
// if you get here then we are ready to read the results.
if (source.next()) {
+ rowCount++;
StringBuffer sb = new StringBuffer();
// Walk through column values in this row
for (int col = 1; col <= columnCount; col++) {
@@ -133,6 +136,10 @@
return null;
}
+ public int getRowCount() {
+ return rowCount;
+ }
+
/**
* Get the first line from the result set. This is the resultset metadata line where
* we gather the column names and their types.
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectConverterUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectConverterUtil.java 2009-10-02 19:08:46 UTC (rev 1520)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectConverterUtil.java 2009-10-05 14:44:52 UTC (rev 1521)
@@ -45,7 +45,7 @@
private static final int DEFAULT_READING_SIZE = 8192;
- protected static byte[] convertToByteArray(final java.sql.Blob data) throws MetaMatrixCoreException {
+ protected static byte[] convertBlobToByteArray(final java.sql.Blob data) throws MetaMatrixCoreException {
try {
// Open a stream to read the BLOB data
InputStream l_blobStream = data.getBinaryStream();
@@ -82,7 +82,9 @@
} else if (data instanceof byte[]) {
return (byte[]) data;
} else if (data instanceof java.sql.Blob) {
- return convertToByteArray((java.sql.Blob) data);
+ return convertBlobToByteArray((java.sql.Blob) data);
+ } else if (data instanceof File) {
+ return convertFileToByteArray((File)data);
}
final Object[] params = new Object[]{data.getClass().getName()};
throw new MetaMatrixCoreException(CorePlugin.Util.getString("ObjectConverterUtil.Object_type_not_supported_for_object_conversion._3",params)); //$NON-NLS-1$
15 years, 2 months
teiid SVN: r1520 - in trunk: connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator and 4 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-10-02 15:08:46 -0400 (Fri, 02 Oct 2009)
New Revision: 1520
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java
Log:
TEIID-728 fix for inaccurate trim logic. No specific columns with a type of char or nchar are rtrimmed to produce consistent string forms.
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCBaseExecution.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -60,7 +60,6 @@
protected ExecutionContext context;
// Derived from properties
- protected boolean trimString;
protected int fetchSize;
protected int maxResultRows;
@@ -81,7 +80,6 @@
this.logger = logger;
this.context = context;
- trimString = PropertiesUtils.getBooleanProperty(props, JDBCPropertyNames.TRIM_STRINGS, false);
fetchSize = PropertiesUtils.getIntProperty(props, JDBCPropertyNames.FETCH_SIZE, context.getBatchSize());
maxResultRows = PropertiesUtils.getIntProperty(props, ConnectorPropertyNames.MAX_RESULT_ROWS, -1);
//if the connector work needs to throw an excpetion, set the size plus 1
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCProcedureExecution.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -24,9 +24,7 @@
import java.sql.CallableStatement;
import java.sql.Connection;
-import java.sql.ParameterMetaData;
import java.sql.SQLException;
-import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -37,7 +35,6 @@
import org.teiid.connector.api.DataNotAvailableException;
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.api.ProcedureExecution;
-import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.ICommand;
@@ -50,8 +47,6 @@
*/
public class JDBCProcedureExecution extends JDBCQueryExecution implements ProcedureExecution {
- private ParameterMetaData parameterMetaData;
-
/**
* @param connection
* @param sqlTranslator
@@ -82,11 +77,7 @@
try{
//create parameter index map
CallableStatement cstmt = getCallableStatement(sql);
- this.parameterMetaData = cstmt.getParameterMetaData();
this.results = sqlTranslator.executeStoredProcedure(cstmt, translatedComm);
- if (results != null) {
- initResultSetInfo();
- }
addStatementWarnings();
}catch(SQLException e){
throw new ConnectorException(e, JDBCPlugin.Util.getString("JDBCQueryExecution.Error_executing_query__1", sql)); //$NON-NLS-1$
@@ -135,12 +126,6 @@
private void addParameterValue(List<Object> result, int paramIndex,
IParameter parameter) throws SQLException {
Object value = sqlTranslator.retrieveValue((CallableStatement)this.statement, paramIndex, parameter.getType());
- if (value != null
- && TypeFacility.RUNTIME_TYPES.STRING.equals(value.getClass())
- && (trimString || (parameterMetaData != null && parameterMetaData
- .getParameterType(paramIndex) == Types.CHAR))) {
- value = trimString((String)value);
- }
result.add(value);
}
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCQueryExecution.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -28,9 +28,7 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
import java.sql.SQLException;
-import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -60,7 +58,6 @@
protected ConnectorEnvironment env;
protected ICommand command;
protected Class<?>[] columnDataTypes;
- private boolean[] trimColumn;
// ===========================================================================================================================
// Constructors
@@ -97,24 +94,11 @@
results = pstatement.executeQuery();
}
addStatementWarnings();
- initResultSetInfo();
-
} catch (SQLException e) {
throw new JDBCExecutionException(e, translatedComm);
}
}
- protected void initResultSetInfo() throws SQLException {
- trimColumn = new boolean[columnDataTypes.length];
- ResultSetMetaData rsmd = results.getMetaData();
- for(int i=0; i<columnDataTypes.length; i++) {
-
- if(columnDataTypes[i].equals(String.class)) {
- trimColumn[i] = trimString || rsmd.getColumnType(i+1) == Types.CHAR;
- }
- }
- }
-
@Override
public List<?> next() throws ConnectorException, DataNotAvailableException {
try {
@@ -125,9 +109,6 @@
for (int i = 0; i < columnDataTypes.length; i++) {
// Convert from 0-based to 1-based
Object value = sqlTranslator.retrieveValue(results, i+1, columnDataTypes[i]);
- if (trimColumn[i] && value instanceof String) {
- value = trimString((String)value);
- }
vals.add(value);
}
@@ -142,24 +123,6 @@
}
/**
- * Expects string to never be null
- * @param value Incoming value
- * @return Right trimmed value
- * @since 4.2
- */
- public static String trimString(String value) {
- for(int i=value.length()-1; i>=0; i--) {
- if(value.charAt(i) != ' ') {
- // end of trim, return what's left
- return value.substring(0, i+1);
- }
- }
-
- // All spaces, so trim it all
- return ""; //$NON-NLS-1$
- }
-
- /**
* @see org.teiid.connector.jdbc.JDBCBaseExecution#close()
*/
public void close() throws ConnectorException {
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/Translator.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -33,6 +33,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.text.MessageFormat;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
@@ -44,11 +45,14 @@
import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.api.SourceSystemFunctions;
import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.jdbc.JDBCCapabilities;
import org.teiid.connector.jdbc.JDBCPlugin;
import org.teiid.connector.jdbc.JDBCPropertyNames;
import org.teiid.connector.language.ICommand;
+import org.teiid.connector.language.IElement;
+import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IFunction;
import org.teiid.connector.language.ILanguageFactory;
import org.teiid.connector.language.ILanguageObject;
@@ -59,6 +63,7 @@
import org.teiid.connector.language.IParameter.Direction;
import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.util.ReflectionHelper;
/**
@@ -135,6 +140,7 @@
private volatile boolean initialConnection;
private String connectionTestQuery;
private int isValidTimeout = -1;
+ private boolean trimChar;
/**
* Initialize the SQLTranslator.
@@ -157,7 +163,8 @@
this.useComments = PropertiesUtils.getBooleanProperty(env.getProperties(), JDBCPropertyNames.USE_COMMENTS_SOURCE_QUERY, false);
this.usePreparedStatements = PropertiesUtils.getBooleanProperty(env.getProperties(), JDBCPropertyNames.USE_BIND_VARIABLES, false);
this.connectionTestQuery = env.getProperties().getProperty(JDBCPropertyNames.CONNECTION_TEST_QUERY, getDefaultConnectionTestQuery());
- this.isValidTimeout = PropertiesUtils.getIntProperty(env.getProperties(), JDBCPropertyNames.IS_VALID_TIMEOUT, -1);
+ this.isValidTimeout = PropertiesUtils.getIntProperty(env.getProperties(), JDBCPropertyNames.IS_VALID_TIMEOUT, -1);
+ this.trimChar = PropertiesUtils.getBooleanProperty(env.getProperties(), JDBCPropertyNames.TRIM_STRINGS, false);
}
/**
@@ -206,6 +213,16 @@
parts = translateCommand((ICommand)obj, context);
} else if (obj instanceof ILimit) {
parts = translateLimit((ILimit)obj, context);
+ } else if (obj instanceof IElement) {
+ IElement elem = (IElement)obj;
+ try {
+ if (trimChar && elem.getType() == TypeFacility.RUNTIME_TYPES.STRING
+ && ("char".equalsIgnoreCase(elem.getMetadataObject().getNativeType()) || "nchar".equalsIgnoreCase(elem.getMetadataObject().getNativeType()))) { //$NON-NLS-1$ //$NON-NLS-2$
+ return Arrays.asList(getLanguageFactory().createFunction(SourceSystemFunctions.RTRIM, new IExpression[] {elem}, TypeFacility.RUNTIME_TYPES.STRING));
+ }
+ } catch (ConnectorException e) {
+ throw new MetaMatrixRuntimeException(e);
+ }
}
return parts;
}
@@ -814,7 +831,12 @@
return NullOrder.LOW;
}
+ /**
+ *
+ * @return true if nulls high|low can be specified
+ */
public boolean supportsExplicitNullOrdering() {
return false;
}
+
}
Modified: trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
===================================================================
--- trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-10-02 19:08:46 UTC (rev 1520)
@@ -15,7 +15,7 @@
</PropertyDefinition>
<PropertyDefinition Name="ExtensionTranslationClass" DisplayName="Extension SQL Translation Class" ShortDescription="" DefaultValue="org.teiid.connector.jdbc.translator.Translator" IsExpert="true" />
<PropertyDefinition Name="ConnectionSource" DisplayName="Connection Source Class" ShortDescription="Driver, DataSource, or XADataSource class name" IsRequired="true" />
- <PropertyDefinition Name="TrimStrings" DisplayName="Trim string flag" ShortDescription="Right Trim fixed character types returned as Strings" DefaultValue="false" PropertyType="Boolean" IsExpert="true" />
+ <PropertyDefinition Name="TrimStrings" DisplayName="Trim string flag" ShortDescription="Right Trim fixed character types returned as Strings - note that the native type must be char or nchar and the source must support the rtrim function." DefaultValue="false" PropertyType="Boolean" IsExpert="true" />
<PropertyDefinition Name="UseCommentsInSourceQuery" DisplayName="Use informational comments in Source Queries" ShortDescription="This will embed /*comment*/ style comment with session/request id in source SQL query for informational purposes" DefaultValue="false" PropertyType="Boolean" IsExpert="true"/>
</ComponentType>
<ComponentType Name="Oracle Connector" ComponentTypeCode="2" Deployable="true" Deprecated="false" Monitorable="false" SuperComponentType="JDBC Connector" ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup" CreatedBy="ConfigurationStartup">
Modified: trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/engine/src/test/java/com/metamatrix/query/unittest/FakeMetadataFactory.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -2134,7 +2134,8 @@
DataTypeManager.DefaultDataTypes.BIG_INTEGER, DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
DataTypeManager.DefaultDataTypes.OBJECT };
- List bqt1SmallAe = createElements(bqt1SmallA, elemNames, elemTypes);
+ List<FakeMetadataObject> bqt1SmallAe = createElements(bqt1SmallA, elemNames, elemTypes);
+ bqt1SmallAe.get(1).putProperty(FakeMetadataObject.Props.NATIVE_TYPE, "char"); //$NON-NLS-1$
List bqt1SmallBe = createElements(bqt1SmallB, elemNames, elemTypes);
List bqt1MediumAe = createElements(bqt1MediumA, elemNames, elemTypes);
List bqt1MediumBe = createElements(bqt1MediumB, elemNames, elemTypes);
@@ -4166,9 +4167,9 @@
* @param types Array of element types
* @return List Ordered list of elements in the group
*/
- public static List createElements(FakeMetadataObject group, String[] names, String[] types) {
+ public static List<FakeMetadataObject> createElements(FakeMetadataObject group, String[] names, String[] types) {
String groupRoot = group.getName() + "."; //$NON-NLS-1$
- List elements = new ArrayList();
+ List<FakeMetadataObject> elements = new ArrayList<FakeMetadataObject>();
for(int i=0; i<names.length; i++) {
FakeMetadataObject element = createElement(groupRoot + names[i], group, types[i], i);
Modified: trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java
===================================================================
--- trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/extension/TestSQLConversionVisitor.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -29,39 +29,20 @@
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.jdbc.JDBCPropertyNames;
+import org.teiid.connector.jdbc.MetadataFactory;
import org.teiid.connector.jdbc.translator.SQLConversionVisitor;
-import org.teiid.connector.jdbc.translator.TranslatedCommand;
import org.teiid.connector.jdbc.translator.Translator;
-import org.teiid.connector.language.ICommand;
import org.teiid.connector.language.ILanguageObject;
import org.teiid.connector.metadata.runtime.RuntimeMetadata;
import org.teiid.dqp.internal.datamgr.impl.ExecutionContextImpl;
-import org.teiid.dqp.internal.datamgr.impl.FakeExecutionContextImpl;
-import org.teiid.dqp.internal.datamgr.language.LanguageBridgeFactory;
import org.teiid.dqp.internal.datamgr.language.TestDeleteImpl;
import org.teiid.dqp.internal.datamgr.language.TestInsertImpl;
import org.teiid.dqp.internal.datamgr.language.TestProcedureImpl;
import org.teiid.dqp.internal.datamgr.language.TestSelectImpl;
import org.teiid.dqp.internal.datamgr.language.TestUpdateImpl;
import org.teiid.dqp.internal.datamgr.language.TstLanguageBridgeFactory;
-import org.teiid.metadata.index.VDBMetadataFactory;
import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.query.metadata.QueryMetadataInterface;
-import com.metamatrix.query.resolver.QueryResolver;
-import com.metamatrix.query.rewriter.QueryRewriter;
-import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.GroupBy;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.Constant;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.Function;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
/**
*/
@@ -84,28 +65,23 @@
}
public String getTestVDB() {
- return UnitTestUtil.getTestDataPath() + "/partssupplier/PartsSupplier.vdb"; //$NON-NLS-1$
+ return MetadataFactory.PARTS_VDB;
}
- public ICommand helpTranslate(String vdbFileName, String sql) {
- TranslationUtility util = new TranslationUtility(vdbFileName);
- return util.parseCommand(sql);
- }
-
public void helpTestVisitor(String vdb, String input, String expectedOutput) {
helpTestVisitor(vdb, input, expectedOutput, false);
}
- public void helpTestVisitor(String vdb, String input, String expectedOutput, boolean useMetadata) {
- helpTestVisitor(vdb, input, expectedOutput, useMetadata, false);
- }
-
- public void helpTestVisitor(String vdb, String input, String expectedOutput, boolean useMetadata, boolean usePreparedStatement) {
- // Convert from sql to objects
- ICommand obj = helpTranslate(vdb, input);
-
- try {
- helpTestVisitorWithCommand(expectedOutput, obj, useMetadata, usePreparedStatement);
+ public void helpTestVisitor(String vdb, String input, String expectedOutput, boolean usePreparedStatement) {
+ try {
+ Translator trans = new Translator();
+ Properties p = new Properties();
+ if (usePreparedStatement) {
+ p.setProperty(JDBCPropertyNames.USE_BIND_VARIABLES, Boolean.TRUE.toString());
+ }
+ trans.initialize(EnvironmentUtility.createEnvironment(p, false));
+
+ MetadataFactory.helpTestVisitor(vdb, input, expectedOutput, trans);
} catch (ConnectorException e) {
throw new RuntimeException(e);
}
@@ -123,30 +99,6 @@
return visitor.toString();
}
- /**
- * @param expectedOutput
- * @param obj
- * @throws ConnectorException
- * @since 4.2
- */
- private void helpTestVisitorWithCommand(String expectedOutput,
- ICommand obj,
- boolean useMetadata,
- boolean usePreparedStatement) throws ConnectorException {
- // Apply function replacement
- Translator trans = new Translator();
- Properties p = new Properties();
- if (usePreparedStatement) {
- p.setProperty(JDBCPropertyNames.USE_BIND_VARIABLES, Boolean.TRUE.toString());
- }
- trans.initialize(EnvironmentUtility.createEnvironment(p, false));
-
- TranslatedCommand tc = new TranslatedCommand(new FakeExecutionContextImpl(), trans);
- tc.translateCommand(obj);
-
- assertEquals("Did not get correct sql", expectedOutput, tc.getSql()); //$NON-NLS-1$
- }
-
public void testSimple() {
helpTestVisitor(getTestVDB(),
"select part_name from parts", //$NON-NLS-1$
@@ -363,36 +315,10 @@
"UPDATE PARTS SET PART_WEIGHT = 'a' WHERE NULL <> NULL"); //$NON-NLS-1$
}
- public void testGroupByWithFunctions() throws Exception {
- QueryMetadataInterface metadata = VDBMetadataFactory.getVDBMetadata(getTestVDB());
-
- Select select = new Select();
- select.addSymbol(new ElementSymbol("part_name")); //$NON-NLS-1$
- From from = new From();
- from.addGroup(new GroupSymbol("parts")); //$NON-NLS-1$
- GroupBy groupBy = new GroupBy();
- Function function = new Function("concat", new Expression[] {new ElementSymbol("part_id"), new Constant("a")}); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- groupBy.addSymbol(function);
- Query query = new Query();
- query.setSelect(select);
- query.setFrom(from);
- query.setGroupBy(groupBy);
-
- QueryResolver.resolveCommand(query, metadata);
- Command command = QueryRewriter.rewrite(query, null, metadata, null);
-
- ICommand result = new LanguageBridgeFactory(metadata).translate(command);
-
- helpTestVisitorWithCommand("SELECT PARTS.PART_NAME FROM PARTS GROUP BY concat(PARTS.PART_ID, 'a')", result, //$NON-NLS-1$
- false,
- false);
- }
-
public void testPreparedStatementCreationWithUpdate() {
helpTestVisitor(getTestVDB(),
"update parts set part_weight = 'a' where part_weight < 5", //$NON-NLS-1$
"UPDATE PARTS SET PART_WEIGHT = ? WHERE PARTS.PART_WEIGHT < ?", //$NON-NLS-1$
- false,
true);
}
@@ -400,7 +326,6 @@
helpTestVisitor(getTestVDB(),
"insert into parts (part_weight) values (5)", //$NON-NLS-1$
"INSERT INTO PARTS (PART_WEIGHT) VALUES (?)", //$NON-NLS-1$
- false,
true);
}
@@ -408,7 +333,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_id not in ('x', 'y') and part_weight < 6", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE (PARTS.PART_ID NOT IN (?, ?)) AND (PARTS.PART_WEIGHT < ?)", //$NON-NLS-1$
- false,
true);
}
@@ -416,7 +340,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where part_name like '%foo'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_NAME LIKE ?", //$NON-NLS-1$
- false,
true);
}
@@ -428,7 +351,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where 'x' = 'y'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE 1 = ?", //$NON-NLS-1$
- false,
true);
}
@@ -440,7 +362,6 @@
helpTestVisitor(getTestVDB(),
"select part_name from parts where concat(part_name, 'x') = concat('y', part_weight)", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE concat(PARTS.PART_NAME, 'x') = concat('y', PARTS.PART_WEIGHT)", //$NON-NLS-1$
- false,
true);
}
@@ -448,7 +369,6 @@
helpTestVisitor(getTestVDB(),
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME='a' THEN 'b' ELSE 'c' END", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME = ? THEN 'b' ELSE 'c' END", //$NON-NLS-1$
- false,
true);
}
@@ -477,5 +397,14 @@
public void testVisitIProcedureWithComment() throws Exception {
String expected = "{ /*teiid sessionid:ConnectionID, requestid:RequestID.PartID*/ call sq3(?,?)}"; //$NON-NLS-1$
assertEquals(expected, getStringWithContext(TestProcedureImpl.example()));
- }
+ }
+
+ public void testTrimStrings() throws Exception {
+ Translator trans = new Translator();
+ Properties p = new Properties();
+ p.setProperty(JDBCPropertyNames.TRIM_STRINGS, Boolean.TRUE.toString());
+ trans.initialize(EnvironmentUtility.createEnvironment(p, false));
+
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, "select stringkey from bqt1.smalla", "SELECT rtrim(SmallA.StringKey) FROM SmallA", trans); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
Modified: trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java
===================================================================
--- trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java 2009-10-02 17:47:50 UTC (rev 1519)
+++ trunk/test-integration/common/src/test/java/com/metamatrix/connector/jdbc/util/TestJDBCExecutionHelper.java 2009-10-02 19:08:46 UTC (rev 1520)
@@ -29,7 +29,6 @@
import junit.framework.TestCase;
-import org.teiid.connector.jdbc.JDBCQueryExecution;
import org.teiid.connector.language.IQuery;
import org.teiid.connector.language.ISelect;
import org.teiid.dqp.internal.datamgr.language.LiteralImpl;
@@ -59,30 +58,5 @@
assertEquals( results[0], expectedResults[0]);
assertEquals( results[1], expectedResults[1]);
}
-
- public void helpTestTrimString(String value, String expected) {
- String actual = JDBCQueryExecution.trimString(value);
- assertEquals("Did not get a match, expected=[" + expected + "', actual=[" + actual + "]", expected, actual); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testTrimEmpty() {
- helpTestTrimString("", ""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- public void testTrimNoWhitespace() {
- helpTestTrimString("abc", "abc"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testTrimSome() {
- helpTestTrimString("abc ", "abc"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDontTrimLeft() {
- helpTestTrimString(" abc ", " abc"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testDontTrimInternal() {
- helpTestTrimString("a b c ", "a b c"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
}
15 years, 2 months
teiid SVN: r1519 - trunk/documentation/reference/src/main/docbook/en-US/content.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-10-02 13:47:50 -0400 (Fri, 02 Oct 2009)
New Revision: 1519
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml
Log:
TEIID-850 fixing misspellings
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml 2009-10-02 00:36:59 UTC (rev 1518)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/procedures.xml 2009-10-02 17:47:50 UTC (rev 1519)
@@ -315,7 +315,7 @@
</example>
</sect2>
<sect2>
- <title>Examle Virtual Procedures</title>
+ <title>Example Virtual Procedures</title>
<para>This example is a LOOP that walks through a cursored table and uses CONTINUE and BREAK.</para>
<example>
<title>Virtual Procedure Using LOOP, CONTINUE, BREAK
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2009-10-02 00:36:59 UTC (rev 1518)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2009-10-02 17:47:50 UTC (rev 1519)
@@ -699,7 +699,7 @@
MAKEDEP and MAKENOTDEP are hints used to control
<link linkend="dependent_join">dependent join</link>
behavior. They should only be used in situations where the optimizer
- does not chose the most optimal plan based upon query structure,
+ does not choose the most optimal plan based upon query structure,
metadata, and costing information.
</para>
</note>
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml 2009-10-02 00:36:59 UTC (rev 1518)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml 2009-10-02 17:47:50 UTC (rev 1519)
@@ -84,7 +84,7 @@
</entry>
</row>
<row>
- <entry>PESSIMITIC</entry>
+ <entry>PESSIMISTIC</entry>
<entry>
Will automatically wrap commands in a transaction, but only if
the command seems to be
15 years, 2 months
teiid SVN: r1518 - in trunk: runtime/src/main/java/com/metamatrix/platform/security/session/service and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-10-01 20:36:59 -0400 (Thu, 01 Oct 2009)
New Revision: 1518
Modified:
trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java
trunk/runtime/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java
trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
Log:
TEIID-867 local clients now by-pass ping altogether
Modified: trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java 2009-10-01 21:23:46 UTC (rev 1517)
+++ trunk/engine/src/main/java/com/metamatrix/platform/security/api/service/SessionServiceInterface.java 2009-10-02 00:36:59 UTC (rev 1518)
@@ -156,4 +156,6 @@
*/
public void register(SessionListener listener);
+ public void setLocalSession(MetaMatrixSessionID sessionID);
+
}
Modified: trunk/runtime/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java 2009-10-01 21:23:46 UTC (rev 1517)
+++ trunk/runtime/src/main/java/com/metamatrix/platform/security/session/service/SessionServiceImpl.java 2009-10-02 00:36:59 UTC (rev 1518)
@@ -345,4 +345,12 @@
this.sessionListener = listener;
}
+ @Override
+ public void setLocalSession(MetaMatrixSessionID sessionID) {
+ MetaMatrixSessionInfo info = this.sessionCache.get(sessionID);
+ if (info != null) {
+ info.setLastPingTime(Long.MAX_VALUE);
+ }
+ }
+
}
Modified: trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2009-10-01 21:23:46 UTC (rev 1517)
+++ trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2009-10-02 00:36:59 UTC (rev 1518)
@@ -27,8 +27,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Properties;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -56,57 +54,25 @@
private boolean shutdown;
private DQPWorkContext workContext;
private ClassLoader classLoader;
- ClientServiceRegistry clientServices;
- SessionServiceInterface sessionService;
- private Timer pingTimer;
+ private ClientServiceRegistry clientServices;
+ private SessionServiceInterface sessionService;
private ILogon logon;
-
-
public LocalServerConnection(Properties connectionProperties, ClientServiceRegistry clientServices, SessionServiceInterface sessionService) throws CommunicationException, ConnectionException{
-
this.clientServices = clientServices;
-
+ this.sessionService = sessionService;
//Initialize the workContext
workContext = new DQPWorkContext();
DQPWorkContext.setWorkContext(workContext);
-
- this.result = authenticate(connectionProperties);
-
this.classLoader = Thread.currentThread().getContextClassLoader();
-
- this.sessionService = sessionService;
-
this.logon = this.getService(ILogon.class);
- this.pingTimer = new Timer("LocalPing", true); //$NON-NLS-1$
-
- schedulePing();
+ this.result = authenticate(connectionProperties);
}
- private void schedulePing() {
- if (this.pingTimer != null) {
- this.pingTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- try {
- if (isOpen()) {
- logon.ping();
- return;
- }
- } catch (InvalidSessionException e) {
- shutdown(false);
- } catch (MetaMatrixComponentException e) {
- shutdown();
- }
- this.cancel();
- }
- }, PING_INTERVAL, PING_INTERVAL);
- }
- }
-
public synchronized LogonResult authenticate(Properties connProps) throws ConnectionException, CommunicationException {
try {
LogonResult logonResult = this.logon.logon(connProps);
+ this.sessionService.setLocalSession(logonResult.getSessionID());
return logonResult;
} catch (LogonException e) {
// Propagate the original message as it contains the message we want
15 years, 2 months