[jboss-cvs] JBossAS SVN: r114533 - projects/jboss-jca/branches/Branch_1_0/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 15 06:10:31 EDT 2013
Author: tfonteyn
Date: 2013-10-15 06:10:30 -0400 (Tue, 15 Oct 2013)
New Revision: 114533
Modified:
projects/jboss-jca/branches/Branch_1_0/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java
Log:
[bz-1019186] allow the use of a datasource class when set instead of always using the hardcoded driver class
Modified: projects/jboss-jca/branches/Branch_1_0/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java 2013-10-11 03:14:01 UTC (rev 114532)
+++ projects/jboss-jca/branches/Branch_1_0/adapters/src/main/java/org/jboss/jca/adapters/jdbc/local/LocalManagedConnectionFactory.java 2013-10-15 10:10:30 UTC (rev 114533)
@@ -244,15 +244,34 @@
}
}
- private LocalManagedConnection getLocalManagedConnection(Properties props, Properties copy)
+ private LocalManagedConnection createLocalManagedConnection(String url, Properties props, Properties copy)
throws ResourceException
{
+ // We need to register with the DriverManager if there is a driver class no matter what
+ if (driverClass != null && !isDriverLoadedForURL(url))
+ {
+ try
+ {
+ getDriver(url);
+ }
+ catch (ResourceException re)
+ {
+ log.debug("Exception while registering driver", re);
+ }
+ }
+
Connection con = null;
try
{
- if (driverClass != null)
+ if (dataSourceClass != null)
{
- String url = getConnectionURL();
+ DataSource d = getDataSource();
+ con = d.getConnection(copy.getProperty("user"), copy.getProperty("password"));
+ if (con == null)
+ throw new ResourceException("Unable to create connection from datasource");
+ }
+ else if (driverClass != null)
+ {
Driver d = getDriver(url);
con = d.connect(url, copy);
if (con == null)
@@ -261,10 +280,7 @@
}
else
{
- DataSource d = getDataSource();
- con = d.getConnection(copy.getProperty("user"), copy.getProperty("password"));
- if (con == null)
- throw new ResourceException("Unable to create connection from datasource");
+ throw new ResourceException("Unable to create connection");
}
return new LocalManagedConnection(this, con, props, transactionIsolation, preparedStatementCacheSize);
@@ -286,6 +302,12 @@
}
}
+ private LocalManagedConnection getLocalManagedConnection(Properties props, Properties copy)
+ throws ResourceException
+ {
+ return createLocalManagedConnection(getConnectionURL(), props, copy);
+ }
+
private LocalManagedConnection getHALocalManagedConnection(Properties props, Properties copy)
throws ResourceException
{
@@ -298,34 +320,12 @@
if (trace)
log.tracef("Trying to create a connection to %s", url);
- Connection con = null;
try
{
- Driver d = getDriver(url);
- con = d.connect(url, copy);
- if (con == null)
- {
- log.warn("Wrong driver class [" + d.getClass() + "] for this connection URL: " + url);
- urlSelector.fail(url);
- }
- else
- {
- return new LocalManagedConnection(this, con, props, transactionIsolation, preparedStatementCacheSize);
- }
+ return createLocalManagedConnection(url, props, copy);
}
catch (Exception e)
{
- if (con != null)
- {
- try
- {
- con.close();
- }
- catch (Throwable ignored)
- {
- // Ignore
- }
- }
log.warn("Failed to create connection for " + url + ": " + e.getMessage());
urlSelector.fail(url);
}
More information about the jboss-cvs-commits
mailing list