[teiid-commits] teiid SVN: r1553 - trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Nov 16 15:57:16 EST 2009


Author: vhalbert at redhat.com
Date: 2009-11-16 15:57:15 -0500 (Mon, 16 Nov 2009)
New Revision: 1553

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/ConnectionStrategyFactory.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java
   trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java
Log:
Teiid 773 - cleanup and refactoring so that the assumption is there will be 2 datasources required in order to run the test.    

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-11-16 20:56:58 UTC (rev 1552)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategy.java	2009-11-16 20:57:15 UTC (rev 1553)
@@ -9,9 +9,7 @@
 import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Properties;
 
 import javax.sql.XAConnection;
@@ -23,26 +21,24 @@
 import org.teiid.test.framework.ConfigPropertyNames.CONNECTION_STRATEGY_PROPS;
 import org.teiid.test.framework.datasource.DataSource;
 import org.teiid.test.framework.datasource.DataSourceFactory;
+import org.teiid.test.framework.datasource.DataSourceMgr;
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
+import com.metamatrix.common.util.PropertiesUtils;
 
+
 public abstract class ConnectionStrategy {
+     
     
-    private Map<String, ConnectionStrategy> driversources = null;
-    private Map<String, ConnectionStrategy> datasourcesources = null;
-    private Map<String, ConnectionStrategy> jeesources = null;
-
-    
-    private Map<String, DataSource> datasources = null;
-    
+    private Properties env = null;
     private DataSourceFactory dsFactory;
     
-    
-    public ConnectionStrategy(Properties props, DataSourceFactory dsFactory) throws QueryTestFailedException {
-    	this.env = props;
-    	this.dsFactory = dsFactory;
-   	
+
+    public ConnectionStrategy(Properties props, DataSourceFactory dsf) {
+	this.env = PropertiesUtils.clone(props);
+	
+	this.dsFactory = dsf;
     }
     
     /*
@@ -56,42 +52,12 @@
     public abstract Connection getConnection() throws QueryTestFailedException;
     
     /**
-     * Implement shutdown of your type of connecton
-     * 
-     *
      * @since
      */
-    public void shutdown() {
-        if (driversources != null) {
-        	shutDownSources(driversources);
-        	driversources = null;
-        }
-        
-        if (datasourcesources != null) {
-        	shutDownSources(datasourcesources);
-        	datasourcesources = null;
-        }
-        
-        if (jeesources != null) {
-        	shutDownSources(jeesources);
-        	jeesources = null;
-        }
+    public void shutdown() {       
+        this.dsFactory.cleanup();
     }
     
-    private void shutDownSources(Map<String, ConnectionStrategy> sources) {
-       	for (Iterator<String> it=sources.keySet().iterator(); it.hasNext();  ){	        		
-        		ConnectionStrategy cs = sources.get(it.next());
-        		try {
-        			cs.shutdown();
-        		} catch (Exception e) {
-        			
-        		}
-        		
-        	}
-        	sources.clear();
-
-    }
-
     public Connection getAdminConnection() throws QueryTestFailedException{
     	return null;
     }
@@ -106,22 +72,14 @@
         return null;
     }
     
+
     
-    private Properties env = null;
     
-    
     public Properties getEnvironment() {
     	return env;
     }
     
-    public int getNumberAvailableDataSources() {
-    	return this.dsFactory.getNumberAvailableDataSources();
-    }
-    
-    public Map<String, DataSource> getDataSources() {
-    	return this.datasources;
-    }
-    
+   
     class CloseInterceptor implements InvocationHandler {
 
         Connection conn;
@@ -144,8 +102,6 @@
    
     void configure() throws QueryTestFailedException  {
     	
-    	datasources = new HashMap<String, DataSource>(3);
-    	
     	String ac = this.env.getProperty(CONNECTION_STRATEGY_PROPS.AUTOCOMMIT, "true");
     	this.autoCommit = Boolean.getBoolean(ac);
     	
@@ -162,22 +118,15 @@
         	}
             
             Admin admin = (Admin)c.getAdminAPI();
-        
-//            Properties p = new Properties();
-//            if (this.env.getProperty(PROCESS_BATCH) != null) {
-//                p.setProperty("metamatrix.buffer.processorBatchSize", this.env.getProperty(PROCESS_BATCH)); //$NON-NLS-1$
-//            }
-//            
-//            if (this.env.getProperty(CONNECTOR_BATCH) != null) {
-//                p.setProperty("metamatrix.buffer.connectorBatchSize", this.env.getProperty(CONNECTOR_BATCH)); //$NON-NLS-1$
-//            }
             
             setupVDBConnectorBindings(admin);
             
             admin.restart();
+            
+            int sleep = 5;
  
-            System.out.println("Bouncing the system..(wait 15 seconds)"); //$NON-NLS-1$
-            Thread.sleep(1000*15);
+            System.out.println("Bouncing the system..(wait " + sleep + " seconds)"); //$NON-NLS-1$
+            Thread.sleep(1000*sleep);
         //    Thread.sleep(1000*60);
             System.out.println("done."); //$NON-NLS-1$
 
@@ -221,9 +170,8 @@
 	        	org.teiid.test.framework.datasource.DataSource ds = this.dsFactory.getDatasource(useName, m.getName());
 	        	
 	        	if (ds != null) {
-		        	datasources.put(m.getName(), ds);
 
-	                System.out.println("Set up Connector Binding (model:mapping:type): " + m.getName() + ":" + useName + ":"  + ds.getConnectorType()); //$NON-NLS-1$
+	        	    System.out.println("Set up Connector Binding (model:mapping:type): " + m.getName() + ":" + useName + ":"  + ds.getConnectorType()); //$NON-NLS-1$
 
 		        	AdminOptions ao = new AdminOptions(AdminOptions.OnConflict.OVERWRITE);
 		        	ao.addOption(AdminOptions.BINDINGS_IGNORE_DECRYPT_ERROR);
@@ -248,70 +196,64 @@
     	
     }
     
-    public synchronized ConnectionStrategy createDriverStrategy(String identifier, Properties props) throws QueryTestFailedException  {
-    	if (driversources == null) {
-    		driversources = new HashMap<String, ConnectionStrategy>();
-    	}
-    	
-     	if (identifier == null) {
-     			return new DriverConnection(props, dsFactory);
-     	}
-     	
-     	ConnectionStrategy strategy = null;
-     	if (driversources.containsKey(identifier)) {
-     		strategy = driversources.get(identifier);
-     	} else {
-     		strategy = new DriverConnection(props, dsFactory);
-     		driversources.put(identifier, strategy);
-     	}	     	
-   	
-       	return strategy;
-    
+    public synchronized Connection createDriverConnection(String identifier) throws QueryTestFailedException  {
+
+	DataSource ds = null;
+	if (identifier != null) {
+	    ds = DataSourceMgr.getInstance().getDataSource(identifier);
+	}
+	if (ds == null) {
+	    	throw new TransactionRuntimeException(
+			"Program Error: DataSource is not mapped to Identifier " + identifier);
+	}
+	
+	Connection conn = ds.getConnection();
+	
+	if (conn != null) return conn;
+	
+	ConnectionStrategy cs = null;
+	if (identifier == null) {
+	    cs = new DriverConnection(ds.getProperties(), this.dsFactory);
+ 		
+ 	} else {
+ 	    cs = new DriverConnection(ds.getProperties(), this.dsFactory);
+ 	}
+	
+	ds.setConnection(cs);
+	
+	return ds.getConnection();
+ 
+	
     }
+
     
-    public synchronized ConnectionStrategy createDataSourceStrategy(String identifier, Properties props) throws QueryTestFailedException  {	     	
-    	if (datasourcesources == null) {
-    		datasourcesources = new HashMap<String, ConnectionStrategy>();
-    	}
-    	
-     	if (identifier == null) {
-    		return new DataSourceConnection(props, dsFactory);
-     	}
-     	
-     	ConnectionStrategy strategy = null;
-     	if (datasourcesources.containsKey(identifier)) {
-     		strategy = datasourcesources.get(identifier);
-     	} else {
-     		strategy = new DataSourceConnection(props, dsFactory);
-     		datasourcesources.put(identifier, strategy);
-     	}
-       	
-       	return strategy;
-    
+    public synchronized XAConnection createDataSourceConnection(String identifier) throws QueryTestFailedException  {	     	
+	
+	DataSource ds = null;
+	if (identifier != null) {
+	    ds = DataSourceMgr.getInstance().getDataSource(identifier);
+	}
+	if (ds == null) {
+	    	throw new TransactionRuntimeException(
+			"Program Error: DataSource is not mapped to Identifier " + identifier);
+	}
+	
+	XAConnection conn = ds.getXAConnection();
+	
+	if (conn != null) return conn;
+	
+	ConnectionStrategy cs = null;
+	if (identifier == null) {
+	    cs = new DriverConnection(ds.getProperties(), this.dsFactory);
+	} else {
+	    cs = new DriverConnection(ds.getProperties(), this.dsFactory);
+	}
+	
+	ds.setXAConnection(cs);
+	
+	return ds.getXAConnection();
+	
+
     }
     
-    public synchronized ConnectionStrategy createJEEStrategy(String identifier, Properties props) throws QueryTestFailedException  {
-    	if (jeesources == null) {
-    		jeesources = new HashMap<String, ConnectionStrategy>();
-    	}
-    	
-     	if (identifier == null) {
-    		return new JEEConnection(props, dsFactory);
-     	}
-     	
-     	ConnectionStrategy strategy = null;
-     	if (jeesources.containsKey(identifier)) {
-     		strategy = jeesources.get(identifier);
-     	} else {
-     		strategy = new JEEConnection(props, dsFactory);
-     		jeesources.put(identifier, strategy);
-     	}
-       	
-       	return strategy;
-    
-    }
-  
-        
- 
-   
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java	2009-11-16 20:56:58 UTC (rev 1552)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/ConnectionStrategyFactory.java	2009-11-16 20:57:15 UTC (rev 1553)
@@ -21,10 +21,11 @@
 public class ConnectionStrategyFactory {
 	
     
-	    public static ConnectionStrategy createConnectionStrategy(ConfigPropertyLoader configprops, DataSourceFactory dsFactory) throws QueryTestFailedException {
+	    public static ConnectionStrategy createConnectionStrategy(ConfigPropertyLoader configprops) throws QueryTestFailedException {
 	     	ConnectionStrategy strategy = null;
 	     	Properties props = configprops.getProperties();
-            
+	     	DataSourceFactory factory = new DataSourceFactory(configprops);
+           
 	        String type = props.getProperty(ConfigPropertyNames.CONNECTION_TYPE, ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION);
 	        if (type == null) {
 	        	throw new RuntimeException("Property " + ConfigPropertyNames.CONNECTION_TYPE + " was specified");
@@ -32,15 +33,15 @@
 	        
 	        if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION)) {
 	        	// pass in null to create new strategy
-	                strategy = new DriverConnection(props, dsFactory);
+	                strategy = new DriverConnection(props, factory);
 	                System.out.println("Created Driver Strategy");
 	        }
 	        else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DATASOURCE_CONNECTION)) {
-	            strategy = new DataSourceConnection(props, dsFactory);
+	            strategy = new DataSourceConnection(props, factory);
 	            System.out.println("Created DataSource Strategy");
 	        }
 	        else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.JNDI_CONNECTION)) {
-	            strategy = new JEEConnection(props, dsFactory);
+	            strategy = new JEEConnection(props, factory);
 	            System.out.println("Created JEE Strategy");
 	        }   
 	        
@@ -60,7 +61,7 @@
 			
 			ConfigPropertyLoader config = ConfigPropertyLoader.createInstance();
 			
-			DataSourceFactory factory = new DataSourceFactory(config);
+			new DataSourceFactory(config);
 
 		}
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java	2009-11-16 20:56:58 UTC (rev 1552)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DataSourceConnection.java	2009-11-16 20:57:15 UTC (rev 1553)
@@ -22,135 +22,136 @@
 
 public class DataSourceConnection extends ConnectionStrategy {
 
-	public static final String DS_USER = "user"; //$NON-NLS-1$
+    public static final String DS_USER = "user"; //$NON-NLS-1$
 
-	// need both user variables because Teiid uses 'user' and connectors use
-	// 'username'
-	public static final String DS_USERNAME = JDBCPropertyNames.USERNAME; //$NON-NLS-1$
-	public static final String DS_PASSWORD = JDBCPropertyNames.PASSWORD; //$NON-NLS-1$
+    // need both user variables because Teiid uses 'user' and connectors use
+    // 'username'
+    public static final String DS_USERNAME = JDBCPropertyNames.USERNAME; //$NON-NLS-1$
+    public static final String DS_PASSWORD = JDBCPropertyNames.PASSWORD; //$NON-NLS-1$
 
-	// the driver is only used for making direct connections to the source, the
-	// connector type will provide the JDBCPropertyNames.CONNECTION_SOURCE
-	// driver class
-	public static final String DS_DRIVER = "driver"; //$NON-NLS-1$
+    // the driver is only used for making direct connections to the source, the
+    // connector type will provide the JDBCPropertyNames.CONNECTION_SOURCE
+    // driver class
+    public static final String DS_DRIVER = "driver"; //$NON-NLS-1$
 
-	public static final String DS_SERVERNAME = "ServerName"; //$NON-NLS-1$
-	public static final String DS_SERVERPORT = "PortNumber"; //$NON-NLS-1$
-	public static final String DS_JNDINAME = "ds-jndiname"; //$NON-NLS-1$
-	public static final String DS_DATABASENAME = "DatabaseName"; //$NON-NLS-1$
-	public static final String DS_APPLICATION_NAME = "application-name"; //$NON-NLS-1$
+    public static final String DS_SERVERNAME = "ServerName"; //$NON-NLS-1$
+    public static final String DS_SERVERPORT = "PortNumber"; //$NON-NLS-1$
+    public static final String DS_JNDINAME = "ds-jndiname"; //$NON-NLS-1$
+    public static final String DS_DATABASENAME = "DatabaseName"; //$NON-NLS-1$
+    public static final String DS_APPLICATION_NAME = "application-name"; //$NON-NLS-1$
 
-	private String driver = null;
-	private String username = null;
-	private String pwd = null;
-	private String applName = null;
-	private String databaseName = null;
-	private String serverName = null;
-	private String portNumber = null;
+    private String driver = null;
+    private String username = null;
+    private String pwd = null;
+    private String applName = null;
+    private String databaseName = null;
+    private String serverName = null;
+    private String portNumber = null;
 
-	private XAConnection xaConnection;
+    private XAConnection xaConnection;
 
-	public DataSourceConnection(Properties props, DataSourceFactory dsFactory)
-			throws QueryTestFailedException {
-		super(props, dsFactory);
+    public DataSourceConnection(Properties props,
+	    DataSourceFactory dsf) throws QueryTestFailedException {
+	super(props, dsf);
+    }
+
+    public void validate() {
+	databaseName = this.getEnvironment().getProperty(DS_DATABASENAME);
+	if (databaseName == null || databaseName.length() == 0) {
+	    throw new TransactionRuntimeException("Property " + DS_DATABASENAME
+		    + " was not specified");
 	}
 
-	public void validate() {
-		databaseName = this.getEnvironment().getProperty(DS_DATABASENAME);
-		if (databaseName == null || databaseName.length() == 0) {
-			throw new TransactionRuntimeException("Property " + DS_DATABASENAME
-					+ " was not specified");
-		}
+	serverName = this.getEnvironment().getProperty(DS_SERVERNAME);
+	if (serverName == null || serverName.length() == 0) {
+	    throw new TransactionRuntimeException("Property " + DS_SERVERNAME
+		    + " was not specified");
+	}
 
-		serverName = this.getEnvironment().getProperty(DS_SERVERNAME);
-		if (serverName == null || serverName.length() == 0) {
-			throw new TransactionRuntimeException("Property " + DS_SERVERNAME
-					+ " was not specified");
-		}
+	this.portNumber = this.getEnvironment().getProperty(DS_SERVERPORT);
 
-		this.portNumber = this.getEnvironment().getProperty(DS_SERVERPORT);
+	this.applName = this.getEnvironment().getProperty(DS_APPLICATION_NAME);
 
-		this.applName = this.getEnvironment().getProperty(DS_APPLICATION_NAME);
+	this.driver = this.getEnvironment().getProperty(DS_DRIVER);
+	if (this.driver == null || this.driver.length() == 0) {
+	    throw new TransactionRuntimeException("Property " + DS_DRIVER
+		    + " was not specified");
+	}
 
-		this.driver = this.getEnvironment().getProperty(DS_DRIVER);
-		if (this.driver == null || this.driver.length() == 0) {
-			throw new TransactionRuntimeException("Property " + DS_DRIVER
-					+ " was not specified");
-		}
+	this.username = this.getEnvironment().getProperty(DS_USER);
+	if (username == null) {
+	    this.username = this.getEnvironment().getProperty(DS_USERNAME);
+	}
+	this.pwd = this.getEnvironment().getProperty(DS_PASSWORD);
 
-		this.username = this.getEnvironment().getProperty(DS_USER);
-		if (username == null) {
-			this.username = this.getEnvironment().getProperty(DS_USERNAME);
-		}
-		this.pwd = this.getEnvironment().getProperty(DS_PASSWORD);
+    }
 
+    public Connection getConnection() throws QueryTestFailedException {
+	try {
+	    return getXAConnection().getConnection();
+	} catch (QueryTestFailedException qtf) {
+	    throw qtf;
+	} catch (Exception e) {
+	    e.printStackTrace();
+	    throw new QueryTestFailedException(e);
 	}
+    }
 
-	public Connection getConnection() throws QueryTestFailedException {
-		try {
-			return getXAConnection().getConnection();
-		} catch (QueryTestFailedException qtf) {
-			throw qtf;
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw new QueryTestFailedException(e);
-		}
+    public synchronized XAConnection getXAConnection()
+	    throws QueryTestFailedException {
+	if (xaConnection == null) {
+	    validate();
+	    try {
+		xaConnection = createConnection();
+	    } catch (Exception e) {
+		throw new QueryTestFailedException(e);
+	    }
 	}
+	return xaConnection;
+    }
 
-	public synchronized XAConnection getXAConnection()
-			throws QueryTestFailedException {
-		if (xaConnection == null) {
-			validate();
-			try {
-				xaConnection = createConnection();
-			} catch (Exception e) {
-				throw new QueryTestFailedException(e);
-			}
-		}
-		return xaConnection;
-	}
+    private XAConnection createConnection() throws SQLException,
+	    InstantiationException, IllegalAccessException,
+	    ClassNotFoundException {
+	System.out
+		.println("Creating Datasource Connection: \"" + this.serverName + " - " + this.databaseName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
 
-	private XAConnection createConnection() throws SQLException,
-			InstantiationException, IllegalAccessException,
-			ClassNotFoundException {
-		System.out
-				.println("Creating Datasource Connection: \"" + this.serverName + " - " + this.databaseName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+	BaseDataSource dataSource = (BaseDataSource) Class.forName(this.driver)
+		.newInstance();
 
-		BaseDataSource dataSource = (BaseDataSource) Class.forName(this.driver)
-				.newInstance();
+	dataSource.setDatabaseName(this.databaseName);
+	if (this.applName != null) {
+	    dataSource.setApplicationName(this.applName);
+	}
 
-		dataSource.setDatabaseName(this.databaseName);
-		if (this.applName != null) {
-			dataSource.setApplicationName(this.applName);
-		}
+	if (dataSource instanceof EmbeddedDataSource) {
+	    ((EmbeddedDataSource) dataSource).setBootstrapFile(this.serverName);
+	} else {
+	    ((TeiidDataSource) dataSource).setServerName(this.serverName);
+	    ((TeiidDataSource) dataSource).setPortNumber(Integer
+		    .parseInt(this.portNumber));
+	}
 
-		if (dataSource instanceof EmbeddedDataSource) {
-			((EmbeddedDataSource) dataSource).setBootstrapFile(this.serverName);
-		} else {
-			((TeiidDataSource) dataSource).setServerName(this.serverName);
-			((TeiidDataSource) dataSource).setPortNumber(Integer
-					.parseInt(this.portNumber));
-		}
-
-		if (this.username != null) {
-			dataSource.setUser(this.username);
-			dataSource.setPassword(this.pwd);
-		}
-
-		return ((XADataSource) dataSource).getXAConnection();
+	if (this.username != null) {
+	    dataSource.setUser(this.username);
+	    dataSource.setPassword(this.pwd);
 	}
 
-	public void shutdown() {
-		super.shutdown();
-		try {
+	return ((XADataSource) dataSource).getXAConnection(this.username,
+		this.pwd);
+    }
 
-			if (this.xaConnection != null) {
-				this.xaConnection.close();
-			}
-		} catch (SQLException e) {
-			// ignore..
-		}
+    public void shutdown() {
+	super.shutdown();
+	try {
 
-		this.xaConnection = null;
+	    if (this.xaConnection != null) {
+		this.xaConnection.close();
+	    }
+	} catch (SQLException e) {
+	    // ignore..
 	}
+
+	this.xaConnection = null;
+    }
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java	2009-11-16 20:56:58 UTC (rev 1552)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/DriverConnection.java	2009-11-16 20:57:15 UTC (rev 1553)
@@ -14,131 +14,135 @@
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
+/**
+ * The DriverConnection strategy that can get connections in standalone mode or
+ * embedded mode.
+ */
+public class DriverConnection extends ConnectionStrategy {
 
+    public static final String DS_USER = "user"; //$NON-NLS-1$
 
-/** 
- * The DriverConnection strategy that can get connections in standalone mode
- * or embedded mode. 
- */
-public class DriverConnection extends ConnectionStrategy{
-	
-	   public static final String DS_USER = "user"; //$NON-NLS-1$
-	    
-	    // need both user variables because Teiid uses 'user' and connectors use 'username'
-	    public static final String DS_USERNAME = JDBCPropertyNames.USERNAME; //$NON-NLS-1$
-	    public static final String DS_PASSWORD = JDBCPropertyNames.PASSWORD;     //$NON-NLS-1$
-	    
-	    // the driver is only used for making direct connections to the source, the 
-	    // connector type will provide the JDBCPropertyNames.CONNECTION_SOURCE driver class
-	    public static final String DS_DRIVER = "driver"; //$NON-NLS-1$
-	 
-	    public static final String DS_URL = JDBCPropertyNames.URL;     //$NON-NLS-1$
-	    public static final String DS_APPLICATION_NAME = "application-name"; //$NON-NLS-1$
-	    
-     
+    // need both user variables because Teiid uses 'user' and connectors use
+    // 'username'
+    public static final String DS_USERNAME = JDBCPropertyNames.USERNAME; //$NON-NLS-1$
+    public static final String DS_PASSWORD = JDBCPropertyNames.PASSWORD; //$NON-NLS-1$
+
+    // the driver is only used for making direct connections to the source, the
+    // connector type will provide the JDBCPropertyNames.CONNECTION_SOURCE
+    // driver class
+    public static final String DS_DRIVER = "driver"; //$NON-NLS-1$
+
+    public static final String DS_URL = JDBCPropertyNames.URL; //$NON-NLS-1$
+    public static final String DS_APPLICATION_NAME = "application-name"; //$NON-NLS-1$
+
     private String url = null;
     private String driver = null;
     private String username = null;
     private String pwd = null;
-    
+
     private Connection connection;
 
-        
-    public DriverConnection(Properties props, DataSourceFactory dsFactory) throws QueryTestFailedException {
-    	   super(props, dsFactory);
-    	   validate();
+
+    public DriverConnection(Properties props,
+	    DataSourceFactory dsf) throws QueryTestFailedException {
+	super(props, dsf);
+	validate();
     }
-    
-	public void validate()  {
 
-    	String urlProp = this.getEnvironment().getProperty(DS_URL);
-    	if (urlProp == null || urlProp.length() == 0) {
-    		throw new TransactionRuntimeException("Property " + DS_URL + " was not specified");
-    	}
-       StringBuffer urlSB = new StringBuffer(urlProp);
-        
-       String appl = this.getEnvironment().getProperty(DS_APPLICATION_NAME);
-        if (appl != null) {
-            urlSB.append(";");
-            urlSB.append("ApplicationName").append("=").append(appl);
-        }
-        
-        url = urlSB.toString();
-        
-        driver = this.getEnvironment().getProperty(DS_DRIVER);
-    	if (driver == null || driver.length() == 0) {
-    		throw new TransactionRuntimeException("Property " + DS_DRIVER + " was not specified");
-    	}
-    	
-    	   // need both user variables because Teiid uses 'user' and connectors use 'username'
+    public void validate() {
 
-    	this.username = this.getEnvironment().getProperty(DS_USER);
-    	if (username == null) {
-    		this.username = this.getEnvironment().getProperty(DS_USERNAME);
-    	}
-    	this.pwd = this.getEnvironment().getProperty(DS_PASSWORD);
-    	
-        try {
-            // Load jdbc driver
-            Class.forName(driver);
-        } catch (ClassNotFoundException e) {
-        	throw new TransactionRuntimeException(e);
-        }
-       	
+	String urlProp = this.getEnvironment().getProperty(DS_URL);
+	if (urlProp == null || urlProp.length() == 0) {
+	    throw new TransactionRuntimeException("Property " + DS_URL
+		    + " was not specified");
 	}
+	StringBuffer urlSB = new StringBuffer(urlProp);
 
-	public synchronized Connection getConnection() throws QueryTestFailedException {
-        if (this.connection != null) {
-        	try {
-				if (!this.connection.isClosed()) {
-					return this.connection;
-				}
-			} catch (SQLException e) {
+	String appl = this.getEnvironment().getProperty(DS_APPLICATION_NAME);
+	if (appl != null) {
+	    urlSB.append(";");
+	    urlSB.append("ApplicationName").append("=").append(appl);
+	}
 
-			}
-        	
-        }
-		
-        this.connection = getJDBCConnection(this.driver, this.url, this.username, this.pwd); 
-        return this.connection;
-    }    
-   
-    
-    private Connection getJDBCConnection(String driver, String url, String user, String passwd) throws QueryTestFailedException {
+	url = urlSB.toString();
 
-        System.out.println("Creating Driver Connection: \"" + url + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+	driver = this.getEnvironment().getProperty(DS_DRIVER);
+	if (driver == null || driver.length() == 0) {
+	    throw new TransactionRuntimeException("Property " + DS_DRIVER
+		    + " was not specified");
+	}
 
-        Connection conn;
-        try {
-            // Create a connection
-        	if (user != null && user.length() > 0) {
-        		conn = DriverManager.getConnection(url, user, passwd); 
-        	} else {
-        		conn = DriverManager.getConnection(url);
-        	}
-        	
-      
-        } catch (SQLException e) {
-        	throw new QueryTestFailedException(e);
-        } catch (Throwable t) {
-        	t.printStackTrace();
-        	throw new QueryTestFailedException(t.getMessage());
-        }
-        return conn;
-      
+	// need both user variables because Teiid uses 'user' and connectors use
+	// 'username'
+
+	this.username = this.getEnvironment().getProperty(DS_USER);
+	if (username == null) {
+	    this.username = this.getEnvironment().getProperty(DS_USERNAME);
+	}
+	this.pwd = this.getEnvironment().getProperty(DS_PASSWORD);
+
+	try {
+	    // Load jdbc driver
+	    Class.forName(driver);
+	} catch (ClassNotFoundException e) {
+	    throw new TransactionRuntimeException(e);
+	}
+
     }
-            
+
+    public synchronized Connection getConnection()
+	    throws QueryTestFailedException {
+	if (this.connection != null) {
+	    try {
+		if (!this.connection.isClosed()) {
+		    return this.connection;
+		}
+	    } catch (SQLException e) {
+
+	    }
+
+	}
+
+	this.connection = getJDBCConnection(this.driver, this.url,
+		this.username, this.pwd);
+	return this.connection;
+    }
+
+    private Connection getJDBCConnection(String driver, String url,
+	    String user, String passwd) throws QueryTestFailedException {
+
+	System.out.println("Creating Driver Connection: \"" + url + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+
+	Connection conn;
+	try {
+	    // Create a connection
+	    if (user != null && user.length() > 0) {
+		conn = DriverManager.getConnection(url, user, passwd);
+	    } else {
+		conn = DriverManager.getConnection(url);
+	    }
+
+	} catch (SQLException e) {
+	    throw new QueryTestFailedException(e);
+	} catch (Throwable t) {
+	    t.printStackTrace();
+	    throw new QueryTestFailedException(t.getMessage());
+	}
+	return conn;
+
+    }
+
     public void shutdown() {
-		super.shutdown();
-    	if (this.connection != null) {
-    		try {
-    			this.connection.close();
-    		} catch (Exception e) {
-				//ignore
-			}
-       	}
-    	
-    	this.connection = null;
-           
+	super.shutdown();
+	if (this.connection != null) {
+	    try {
+		this.connection.close();
+	    } catch (Exception e) {
+		// ignore
+	    }
+	}
+
+	this.connection = null;
+
     }
 }

Modified: trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java
===================================================================
--- trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java	2009-11-16 20:56:58 UTC (rev 1552)
+++ trunk/test-integration/db/src/main/java/org/teiid/test/framework/connection/JEEConnection.java	2009-11-16 20:57:15 UTC (rev 1553)
@@ -14,56 +14,56 @@
 import org.teiid.test.framework.exception.QueryTestFailedException;
 import org.teiid.test.framework.exception.TransactionRuntimeException;
 
+/**
+ * JEE (JNDI) Connection Strategy, when the test is run inside an application
+ * server. Make sure all the jndi names are set correctly in the properties
+ * file.
+ */
+public class JEEConnection extends ConnectionStrategy {
 
+    public static final String DS_JNDINAME = "ds-jndiname"; //$NON-NLS-1$
 
-/** 
- * JEE (JNDI) Connection Strategy, when the test is run inside an application server. Make
- * sure all the jndi names are set correctly in the properties file.
- */
-public class JEEConnection extends ConnectionStrategy{
-	
-	 public static final String DS_JNDINAME = "ds-jndiname"; //$NON-NLS-1$
-	
-	private String jndi_name = null;
-	
-	
-	public JEEConnection(Properties props, DataSourceFactory dsFactory) throws QueryTestFailedException {
-    	   super(props, dsFactory);
+    private String jndi_name = null;
+
+
+    public JEEConnection(Properties props,
+	    DataSourceFactory dsf) throws QueryTestFailedException {
+	super(props, dsf);
     }
 
     public Connection getConnection() throws QueryTestFailedException {
-    	validate();
-        try {
-            InitialContext ctx = new InitialContext();
-            DataSource source = (DataSource)ctx.lookup(jndi_name);
-            
+	validate();
+	try {
+	    InitialContext ctx = new InitialContext();
+	    DataSource source = (DataSource) ctx.lookup(jndi_name);
 
-            if (source == null) {
-                String msg = "Unable to find jndi source " + jndi_name;//$NON-NLS-1$
+	    if (source == null) {
+		String msg = "Unable to find jndi source " + jndi_name;//$NON-NLS-1$
 
-                QueryTestFailedException mme = new QueryTestFailedException(msg);//$NON-NLS-1$
-                throw mme;
-            }            
-            Connection conn = source.getConnection();
-            return conn;
-        } catch (QueryTestFailedException qtfe) {
-        	throw qtfe;
-        } catch (Exception e) {
-            throw new QueryTestFailedException(e);
-        }
-    }    
-            
+		QueryTestFailedException mme = new QueryTestFailedException(msg);//$NON-NLS-1$
+		throw mme;
+	    }
+	    Connection conn = source.getConnection();
+	    return conn;
+	} catch (QueryTestFailedException qtfe) {
+	    throw qtfe;
+	} catch (Exception e) {
+	    throw new QueryTestFailedException(e);
+	}
+    }
+
     public void shutdown() {
-		super.shutdown();
-        // no connection management here; app server takes care of these..
+	super.shutdown();
+	// no connection management here; app server takes care of these..
     }
 
-	public void validate()  {
-		// TODO Auto-generated method stub
-		
-		jndi_name = getEnvironment().getProperty(DS_JNDINAME);
-    	if (jndi_name == null || jndi_name.length() == 0) {
-    		throw new TransactionRuntimeException("Property " + DS_JNDINAME + " was not specified");
-    	}
-	} 
+    public void validate() {
+	// TODO Auto-generated method stub
+
+	jndi_name = getEnvironment().getProperty(DS_JNDINAME);
+	if (jndi_name == null || jndi_name.length() == 0) {
+	    throw new TransactionRuntimeException("Property " + DS_JNDINAME
+		    + " was not specified");
+	}
+    }
 }



More information about the teiid-commits mailing list