From: Patrick Schmitz Date: Thu, 20 Dec 2012 23:30:07 +0000 (-0800) Subject: CSPACE-5782 Replace DataSource getConnection with DriverManager.getConnection(),... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=2ff26066715d6cb0cc1149586c745bff52d9f212;p=tmp%2Fjakarta-migration.git CSPACE-5782 Replace DataSource getConnection with DriverManager.getConnection(), since former uses connection pool and so does not reflect changes to setUrl. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java b/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java index 50dd95f26..1ed4c4c5f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java @@ -29,6 +29,7 @@ import javax.naming.NamingException; import javax.sql.DataSource; import java.sql.DatabaseMetaData; import java.sql.Connection; +import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -139,10 +140,19 @@ public class JDBCTools { String urlTemplate = dataSource.getUrl(); String databaseName = getDatabaseName(repositoryName); String connectionUrl = urlTemplate.replace(URL_DATABASE_NAME, databaseName); - dataSource.setUrl(connectionUrl); + + // ATTENTION! + // Turns out the Tomcat BasicDataSource used a connection pool, so changing the url does not + // get you a corresponding connection. Use the more basic implementation for now, unless + // and until we do things right by creating additional JNDI data sources. + + //dataSource.setUrl(connectionUrl); + String user = dataSource.getUsername(); + String password = dataSource.getPassword(); try { - conn = dataSource.getConnection(); + //conn = dataSource.getConnection(); + conn = DriverManager.getConnection(connectionUrl, user, password); result = conn; if (logger.isTraceEnabled() == true && conn != null) { logger.trace(String.format("Connection made to repository = '%s' using datasource = '%s'", repositoryName, dataSourceName));