}
try {
- if (preparedRemoveSql == null) {
- String removeSql = "DELETE FROM " + sessionTable
- + " WHERE " + sessionIdCol + " = ? AND "
- + sessionAppCol + " = ?";
- preparedRemoveSql = _conn.prepareStatement(removeSql);
- }
-
- preparedRemoveSql.setString(1, id);
- preparedRemoveSql.setString(2, getName());
- preparedRemoveSql.execute();
+ remove(id, _conn);
// Break out after the finally block
numberOfTries = 0;
} catch (SQLException e) {
}
/**
+ * Remove the Session with the specified session identifier from
+ * this Store, if present. If no such Session is present, this method
+ * takes no action.
+ *
+ * @param id Session identifier of the Session to be removed
+ * @param _conn open connection to be used
+ * @throws SQLException if an error occurs while talking to the database
+ */
+ private void remove(String id, Connection _conn) throws SQLException {
+ if (preparedRemoveSql == null) {
+ String removeSql = "DELETE FROM " + sessionTable
+ + " WHERE " + sessionIdCol + " = ? AND "
+ + sessionAppCol + " = ?";
+ preparedRemoveSql = _conn.prepareStatement(removeSql);
+ }
+
+ preparedRemoveSql.setString(1, id);
+ preparedRemoveSql.setString(2, getName());
+ preparedRemoveSql.execute();
+ }
+
+ /**
* Remove all of the Sessions in this Store.
*
* @exception IOException if an input/output error occurs
return;
}
- // If sessions already exist in DB, remove and insert again.
- // TODO:
- // * Check if ID exists in database and if so use UPDATE.
- remove(session.getIdInternal());
-
try {
+ // If sessions already exist in DB, remove and insert again.
+ // TODO:
+ // * Check if ID exists in database and if so use UPDATE.
+ remove(session.getIdInternal(), _conn);
+
bos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(new BufferedOutputStream(bos));
* @return <code>Connection</code> 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"));
}
}
ex.toString()));
}
- return dbConnection;
+ return conn;
}
/**
}
if (dataSource != null) {
- dbConnection = dataSource.getConnection();
- return dbConnection;
+ return dataSource.getConnection();
}
// Instantiate our database driver if necessary
}
/**
- * 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);
+ }
}
/**
@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();
}