View | Details | Raw Unified | Return to bug 51264
Collapse All | Expand All

(-)a/java/org/apache/catalina/session/JDBCStore.java (+57 lines)
Lines 33-38 import java.sql.SQLException; Link Here
33
import java.util.ArrayList;
33
import java.util.ArrayList;
34
import java.util.Properties;
34
import java.util.Properties;
35
35
36
import javax.naming.Context;
37
import javax.naming.InitialContext;
38
import javax.naming.NamingException;
39
import javax.sql.DataSource;
40
36
import org.apache.catalina.Container;
41
import org.apache.catalina.Container;
37
import org.apache.catalina.LifecycleException;
42
import org.apache.catalina.LifecycleException;
38
import org.apache.catalina.Loader;
43
import org.apache.catalina.Loader;
Lines 102-107 public class JDBCStore extends StoreBase { Link Here
102
     */
107
     */
103
    protected String driverName = null;
108
    protected String driverName = null;
104
109
110
    /**
111
     * name of the JNDI resource
112
     */
113
    protected String dataSourceName = null;
114
115
    /**
116
     * DataSource to use
117
     */
118
    protected DataSource dataSource = null;
119
105
    // ------------------------------------------------------------- Table & cols
120
    // ------------------------------------------------------------- Table & cols
106
121
107
    /**
122
    /**
Lines 436-441 public class JDBCStore extends StoreBase { Link Here
436
        return (this.sessionLastAccessedCol);
451
        return (this.sessionLastAccessedCol);
437
    }
452
    }
438
453
454
    /**
455
     * Set the JNDI name of a DataSource-factory to use for db access
456
     *
457
     * @param dataSourceName The JNDI name of the DataSource-factory
458
     */
459
	public void setDataSourceName(String dataSourceName) {
460
		if (dataSourceName == null || "".equals(dataSourceName.trim())) {
461
			manager.getContainer()
462
					.getLogger()
463
					.warn(sm.getString(getStoreName()
464
							+ ".missingDataSourceName"));
465
			return;
466
		}
467
		this.dataSourceName = dataSourceName;
468
	}
469
470
    /**
471
     * Return the name of the JNDI DataSource-factory
472
     */
473
    public String getDataSourceName() {
474
         return this.dataSourceName;
475
    }
476
439
    // --------------------------------------------------------- Public Methods
477
    // --------------------------------------------------------- Public Methods
440
478
441
    /**
479
    /**
Lines 866-871 public class JDBCStore extends StoreBase { Link Here
866
        if (dbConnection != null)
904
        if (dbConnection != null)
867
            return (dbConnection);
905
            return (dbConnection);
868
906
907
        if (dataSourceName != null && dataSource == null) {
908
        	Context initCtx;
909
    		try {
910
    			initCtx = new InitialContext();
911
    			Context envCtx = (Context) initCtx.lookup("java:comp/env");
912
    			this.dataSource = (DataSource) envCtx.lookup(this.dataSourceName);
913
    		} catch (NamingException e) {
914
    			manager.getContainer()
915
    					.getLogger()
916
    					.error(sm.getString(getStoreName() + ".wrongDataSource",
917
    							this.dataSourceName, e));
918
    		}
919
        }
920
        
921
        if (dataSource != null) {
922
        	dbConnection = dataSource.getConnection();
923
        	return dbConnection;
924
        }
925
869
        // Instantiate our database driver if necessary
926
        // Instantiate our database driver if necessary
870
        if (driver == null) {
927
        if (driver == null) {
871
            try {
928
            try {
(-)a/java/org/apache/catalina/session/LocalStrings.properties (+2 lines)
Lines 27-32 JDBCStore.checkConnectionDBClosed=The database connection is null or was found t Link Here
27
JDBCStore.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.
27
JDBCStore.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.
28
JDBCStore.checkConnectionSQLException=A SQL exception occurred {0}
28
JDBCStore.checkConnectionSQLException=A SQL exception occurred {0}
29
JDBCStore.checkConnectionClassNotFoundException=JDBC driver class not found {0}
29
JDBCStore.checkConnectionClassNotFoundException=JDBC driver class not found {0}
30
JDBCStore.wrongDataSource=Can not open JNDI DataSource {0}: {1}
31
JDBCStore.missingDataSourceName=No valid JNDI name was given.
30
managerBase.createRandom=Created random number generator for session ID generation in {0}ms.
32
managerBase.createRandom=Created random number generator for session ID generation in {0}ms.
31
managerBase.createSession.ise=createSession: Too many active sessions
33
managerBase.createSession.ise=createSession: Too many active sessions
32
managerBase.sessionTimeout=Invalid session timeout setting {0}
34
managerBase.sessionTimeout=Invalid session timeout setting {0}
(-)a/webapps/docs/config/manager.xml (+8 lines)
Lines 355-360 Link Here
355
      driver to establish a connection to the database containing our
355
      driver to establish a connection to the database containing our
356
      session table.</p>
356
      session table.</p>
357
    </attribute>
357
    </attribute>
358
    
359
    <attribute name="dataSourceName" required="false">
360
      <p>Name of the JNDI resource for a JDBC DataSource-factory. If this
361
      option is given and a valid JDBC resource can be found, it will be
362
      used and any direct configuration of a JDBC connection via
363
      <code>connectionURL</code> and <code>driverName</code> will be
364
      ignored.</p>
365
    </attribute>
358
366
359
    <attribute name="driverName" required="true">
367
    <attribute name="driverName" required="true">
360
      <p>Java class name of the JDBC driver to be used.</p>
368
      <p>Java class name of the JDBC driver to be used.</p>

Return to bug 51264