ASF Bugzilla – Attachment 27084 Details for
Bug 51264
Context/Manager/Store configuration proposal
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Implements configuration option for jndi based DataSource.
jndi-name-for-jdbcstore.diff (text/plain), 4.46 KB, created by
Felix Schumacher
on 2011-05-28 14:34:24 UTC
(
hide
)
Description:
Implements configuration option for jndi based DataSource.
Filename:
MIME Type:
Creator:
Felix Schumacher
Created:
2011-05-28 14:34:24 UTC
Size:
4.46 KB
patch
obsolete
>diff --git a/java/org/apache/catalina/session/JDBCStore.java b/java/org/apache/catalina/session/JDBCStore.java >index 8a8943e..23d0389 100644 >--- a/java/org/apache/catalina/session/JDBCStore.java >+++ b/java/org/apache/catalina/session/JDBCStore.java >@@ -33,6 +33,11 @@ import java.sql.SQLException; > 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; >@@ -102,6 +107,16 @@ public class JDBCStore extends StoreBase { > */ > protected String driverName = null; > >+ /** >+ * name of the JNDI resource >+ */ >+ protected String dataSourceName = null; >+ >+ /** >+ * DataSource to use >+ */ >+ protected DataSource dataSource = null; >+ > // ------------------------------------------------------------- Table & cols > > /** >@@ -436,6 +451,29 @@ public class JDBCStore extends StoreBase { > 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 > > /** >@@ -866,6 +904,25 @@ public class JDBCStore extends StoreBase { > 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 { >diff --git a/java/org/apache/catalina/session/LocalStrings.properties b/java/org/apache/catalina/session/LocalStrings.properties >index 9ef362f..6ab1889 100644 >--- a/java/org/apache/catalina/session/LocalStrings.properties >+++ b/java/org/apache/catalina/session/LocalStrings.properties >@@ -27,6 +27,8 @@ JDBCStore.checkConnectionDBClosed=The database connection is null or was found t > 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 not open JNDI DataSource {0}: {1} >+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} >diff --git a/webapps/docs/config/manager.xml b/webapps/docs/config/manager.xml >index 01a0edc..d619d56 100644 >--- a/webapps/docs/config/manager.xml >+++ b/webapps/docs/config/manager.xml >@@ -355,6 +355,14 @@ > driver to establish a connection to the database containing our > 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>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51264
: 27084 |
27125
|
27127