[teiid-commits] teiid SVN: r1303 - in trunk/connectors/connector-jdbc/src/main: resources/org/teiid/connector/jdbc and 1 other directory.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Tue Sep 1 17:42:42 EDT 2009
Author: rareddy
Date: 2009-09-01 17:42:42 -0400 (Tue, 01 Sep 2009)
New Revision: 1303
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc/i18n.properties
Log:
TEIID-805: JNDI based connection creation.
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-09-01 19:41:31 UTC (rev 1302)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCConnector.java 2009-09-01 21:42:42 UTC (rev 1303)
@@ -31,6 +31,8 @@
import java.util.Enumeration;
import java.util.Properties;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.sql.XADataSource;
@@ -62,6 +64,8 @@
@ConnectionPooling
public class JDBCConnector extends BasicConnector implements XAConnector, MetadataProvider {
+ private static final String JNDI = "JNDI:"; //$NON-NLS-1$
+
static final int NO_ISOLATION_LEVEL_SET = Integer.MIN_VALUE;
enum TransactionIsolationLevel {
@@ -227,59 +231,68 @@
protected void createDataSources(String dataSourceClassName, final Properties connectionProps) throws ConnectorException {
// create data source
- Object temp = null;
- try {
- temp = ReflectionHelper.create(dataSourceClassName, null, Thread.currentThread().getContextClassLoader());
- } catch (MetaMatrixCoreException e) {
- throw new ConnectorException(e,JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Unable_to_load_the_JDBC_driver_class_6", dataSourceClassName)); //$NON-NLS-1$
- }
-
- final String url = connectionProps.getProperty(JDBCPropertyNames.URL);
-
- if (temp instanceof Driver) {
- final Driver driver = (Driver)temp;
- // check URL if there is one
- if (url == null || url.trim().length() == 0) {
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_database_name_3")); //$NON-NLS-1$
- }
- validateURL(driver, url);
- this.ds = (DataSource)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {DataSource.class}, new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method,
- Object[] args) throws Throwable {
- if (method.getName().equals("getConnection")) { //$NON-NLS-1$
- Properties p = new Properties();
- String user = null;
- String password = null;
- if (args != null && args.length == 2) {
- user = (String)args[0];
- password = (String)args[1];
- } else {
- user = connectionProps.getProperty(JDBCPropertyNames.USERNAME);
- password = connectionProps.getProperty(JDBCPropertyNames.PASSWORD);
- }
- if (user != null) {
- p.put("user", user); //$NON-NLS-1$
- }
- if (password != null) {
- p.put("password", password); //$NON-NLS-1$
- }
- return driver.connect(url, p);
- }
- throw new UnsupportedOperationException("Driver DataSource proxy only provides Connections"); //$NON-NLS-1$
- }
- });
- } else {
- if (temp instanceof DataSource) {
- this.ds = (DataSource)temp;
- PropertiesUtils.setBeanProperties(this.ds, connectionProps, null);
- } else if (temp instanceof XADataSource) {
- this.xaDs = (XADataSource)temp;
- PropertiesUtils.setBeanProperties(this.xaDs, connectionProps, null);
- } else {
- throw new ConnectorException(JDBCPlugin.Util.getString("JDBCConnector.invalid_source", dataSourceClassName)); //$NON-NLS-1$
- }
- }
+ if (dataSourceClassName.startsWith(JNDI)) {
+ try {
+ InitialContext ic = new InitialContext();
+ this.ds = (DataSource) ic.lookup(dataSourceClassName.substring(JNDI.length()));
+ } catch (NamingException e) {
+ throw new ConnectorException(e,JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Unable_to_find_jndi_ds", dataSourceClassName.substring(JNDI.length()))); //$NON-NLS-1$
+ }
+ } else {
+ Object temp = null;
+ try {
+ temp = ReflectionHelper.create(dataSourceClassName, null, Thread.currentThread().getContextClassLoader());
+ } catch (MetaMatrixCoreException e) {
+ throw new ConnectorException(e,JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Unable_to_load_the_JDBC_driver_class_6", dataSourceClassName)); //$NON-NLS-1$
+ }
+
+ final String url = connectionProps.getProperty(JDBCPropertyNames.URL);
+
+ if (temp instanceof Driver) {
+ final Driver driver = (Driver)temp;
+ // check URL if there is one
+ if (url == null || url.trim().length() == 0) {
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCSourceConnectionFactory.Missing_JDBC_database_name_3")); //$NON-NLS-1$
+ }
+ validateURL(driver, url);
+ this.ds = (DataSource)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {DataSource.class}, new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method,
+ Object[] args) throws Throwable {
+ if (method.getName().equals("getConnection")) { //$NON-NLS-1$
+ Properties p = new Properties();
+ String user = null;
+ String password = null;
+ if (args != null && args.length == 2) {
+ user = (String)args[0];
+ password = (String)args[1];
+ } else {
+ user = connectionProps.getProperty(JDBCPropertyNames.USERNAME);
+ password = connectionProps.getProperty(JDBCPropertyNames.PASSWORD);
+ }
+ if (user != null) {
+ p.put("user", user); //$NON-NLS-1$
+ }
+ if (password != null) {
+ p.put("password", password); //$NON-NLS-1$
+ }
+ return driver.connect(url, p);
+ }
+ throw new UnsupportedOperationException("Driver DataSource proxy only provides Connections"); //$NON-NLS-1$
+ }
+ });
+ } else {
+ if (temp instanceof DataSource) {
+ this.ds = (DataSource)temp;
+ PropertiesUtils.setBeanProperties(this.ds, connectionProps, null);
+ } else if (temp instanceof XADataSource) {
+ this.xaDs = (XADataSource)temp;
+ PropertiesUtils.setBeanProperties(this.xaDs, connectionProps, null);
+ } else {
+ throw new ConnectorException(JDBCPlugin.Util.getString("JDBCConnector.invalid_source", dataSourceClassName)); //$NON-NLS-1$
+ }
+ }
+ }
if (this.ds instanceof XADataSource) {
this.xaDs = (XADataSource)this.ds;
}
Modified: trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc/i18n.properties
===================================================================
--- trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc/i18n.properties 2009-09-01 19:41:31 UTC (rev 1302)
+++ trunk/connectors/connector-jdbc/src/main/resources/org/teiid/connector/jdbc/i18n.properties 2009-09-01 21:42:42 UTC (rev 1303)
@@ -30,6 +30,7 @@
JDBCSourceConnectionFactory.til=Unsupported transaction isolation level "{0}".
JDBCSourceConnectionFactory.MissingProp=Missing required property: {0}
JDBCSourceXAConnecton.Connection_still_leased=Connection is still leased to connector worker. However, transaction ended, so terminating the lease.
+JDBCSourceConnectionFactory.Unable_to_find_jndi_ds=Failed to locate data source named {0} through JNDI lookup.
JDBCTranslator.Unexpected_exception_translating_results___8=Unexpected exception while translating results: {0}
JDBCTranslator.Unknown_error_translating_results___9=Unknown error translating results: {0}
More information about the teiid-commits
mailing list