Skip to content

Commit

Permalink
[JBJCA-1331] Use connection-url to get database connection when conne…
Browse files Browse the repository at this point in the history
…ction properties for datasource-class is empty (#575)
  • Loading branch information
gaol authored and Stefano Maestri committed Sep 26, 2016
1 parent 3dec89d commit 94fe4b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Expand Up @@ -104,7 +104,7 @@ public Object createConnectionFactory(ConnectionManager cm) throws ResourceExcep
if (dataSourceClass == null && connectionURL == null && driverClass != null)
throw new ResourceException(bundle.connectionURLNull());

if (dataSourceClass != null && connectionProps.size() == 0)
if (dataSourceClass != null && connectionProps.size() == 0 && (driverClass == null || connectionURL == null))
throw new ResourceException(bundle.nonConnectionPropertyDefinedForDatasource(dataSourceClass));

return super.createConnectionFactory(cm);
Expand Down Expand Up @@ -308,7 +308,7 @@ private LocalManagedConnection createLocalManagedConnection(final String url, fi
Connection con = null;
try
{
if (dataSourceClass != null)
if (dataSourceClass != null && !copy.isEmpty())
{
DataSource d = getDataSource();
con = d.getConnection(copy.getProperty("user"), copy.getProperty("password"));
Expand Down
Expand Up @@ -194,4 +194,14 @@ public interface DeployersLogger extends BasicLogger
@LogMessage(level = INFO)
@Message(id = 20019, value = "Changed TransactionSupport for %s")
public void changedTransactionSupport(String jndiName);

/**
* Connection Properties for DataSource is empty.
*
* @param jndiName The JNDI name
* @param connURL The connection URL
*/
@LogMessage(level = WARN)
@Message(id = 20020, value = "Connection Properties for DataSource: '%s' is empty, try to use driver-class: '%s' and connection-url: '%s' to connect database")
public void connectionPropertiesEmpty(String jndiName, String driverClass, String connURL);
}
Expand Up @@ -768,6 +768,9 @@ else if (ds.getSecurity().getSecurityDomain() != null)
pp.prefill(subject, null, false);
}

if (ds.getDataSourceClass() != null && ds.getConnectionProperties().isEmpty() && ds.getConnectionUrl() != null)
getLogger().connectionPropertiesEmpty(jndiName, ds.getDriverClass(), ds.getConnectionUrl());

// ConnectionFactory
return mcf.createConnectionFactory(cm);
}
Expand Down

0 comments on commit 94fe4b8

Please sign in to comment.