import java.util.ArrayList;
import java.util.Properties;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
import org.apache.catalina.Container;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Loader;
*/
protected String driverName = null;
+ /**
+ * name of the JNDI resource
+ */
+ protected String dataSourceName = null;
+
+ /**
+ * DataSource to use
+ */
+ protected DataSource dataSource = null;
+
// ------------------------------------------------------------- Table & cols
/**
return (this.sessionLastAccessedCol);
}
+ /**
+ * Set the JNDI name of a DataSource-factory to use for db access
+ *
+ * @param dataSourceName The JNDI name of the DataSource-factory
+ */
+ public void setDataSourceName(String dataSourceName) {
+ if (dataSourceName == null || "".equals(dataSourceName.trim())) {
+ manager.getContainer().getLogger().warn(
+ sm.getString(getStoreName() + ".missingDataSourceName"));
+ return;
+ }
+ this.dataSourceName = dataSourceName;
+ }
+
+ /**
+ * Return the name of the JNDI DataSource-factory
+ */
+ public String getDataSourceName() {
+ return this.dataSourceName;
+ }
+
// --------------------------------------------------------- Public Methods
/**
if (dbConnection != null)
return (dbConnection);
+ if (dataSourceName != null && dataSource == null) {
+ Context initCtx;
+ try {
+ initCtx = new InitialContext();
+ Context envCtx = (Context) initCtx.lookup("java:comp/env");
+ this.dataSource = (DataSource) envCtx.lookup(this.dataSourceName);
+ } catch (NamingException e) {
+ manager.getContainer().getLogger().error(
+ sm.getString(getStoreName() + ".wrongDataSource",
+ this.dataSourceName), e);
+ }
+ }
+
+ if (dataSource != null) {
+ dbConnection = dataSource.getConnection();
+ return dbConnection;
+ }
+
// Instantiate our database driver if necessary
if (driver == null) {
try {
JDBCStore.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.
JDBCStore.checkConnectionSQLException=A SQL exception occurred {0}
JDBCStore.checkConnectionClassNotFoundException=JDBC driver class not found {0}
+JDBCStore.wrongDataSource=Can't open JNDI DataSource [{0}]
+JDBCStore.missingDataSourceName=No valid JNDI name was given.
managerBase.createRandom=Created random number generator for session ID generation in {0}ms.
managerBase.createSession.ise=createSession: Too many active sessions
managerBase.sessionTimeout=Invalid session timeout setting {0}
session table.</p>
</attribute>
+ <attribute name="dataSourceName" required="false">
+ <p>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 <code>connectionURL</code>
+ and <code>driverName</code> will be ignored.</p>
+ </attribute>
+
<attribute name="driverName" required="true">
<p>Java class name of the JDBC driver to be used.</p>
</attribute>