From 45b52577f589a28dfded4194208d899850f7c67f Mon Sep 17 00:00:00 2001
From: markt Name of the JNDI resource for a JDBC DataSource-factory. If this option
is given and a valid JDBC resource can be found, it will be used and any
direct configuration of a JDBC connection via Connection if the connection succeeded
*/
protected Connection getConnection() {
+ Connection conn = null;
try {
- if (dbConnection == null || dbConnection.isClosed()) {
+ conn = open();
+ if (conn == null || conn.isClosed()) {
manager.getContainer().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBClosed"));
- open();
- if (dbConnection == null || dbConnection.isClosed()) {
+ conn = open();
+ if (conn == null || conn.isClosed()) {
manager.getContainer().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBReOpenFail"));
}
}
@@ -887,7 +902,7 @@ public class JDBCStore extends StoreBase {
ex.toString()));
}
- return dbConnection;
+ return conn;
}
/**
@@ -916,8 +931,7 @@ public class JDBCStore extends StoreBase {
}
if (dataSource != null) {
- dbConnection = dataSource.getConnection();
- return dbConnection;
+ return dataSource.getConnection();
}
// Instantiate our database driver if necessary
@@ -1014,13 +1028,15 @@ public class JDBCStore extends StoreBase {
}
/**
- * Release the connection, not needed here since the
- * connection is not associated with a connection pool.
+ * Release the connection, if it
+ * is associated with a connection pool.
*
* @param conn The connection to be released
*/
protected void release(Connection conn) {
- // NOOP
+ if (dataSource != null) {
+ close(conn);
+ }
}
/**
@@ -1033,8 +1049,10 @@ public class JDBCStore extends StoreBase {
@Override
protected synchronized void startInternal() throws LifecycleException {
- // Open connection to the database
- this.dbConnection = getConnection();
+ if (dataSource == null) {
+ // If not using a connection pool, open a connection to the database
+ this.dbConnection = getConnection();
+ }
super.startInternal();
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 2ebde24cb..ec7cb8659 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -46,6 +46,11 @@
connectionURL
- and driverName will be ignored.driverName will be ignored. Since this code uses prepared
+ statements, you might want to configure pooled prepared statements as
+ shown in the JNDI resources
+ HOW-TO.