ASF Bugzilla – Attachment 23640 Details for
Bug 47061
JDBCStore for saving sessions doesn't support datasource
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
JDBCStore.java patch 2
JDBCStore-2.patch (text/plain), 3.79 KB, created by
Steve Pugh
on 2009-05-11 02:46:48 UTC
(
hide
)
Description:
JDBCStore.java patch 2
Filename:
MIME Type:
Creator:
Steve Pugh
Created:
2009-05-11 02:46:48 UTC
Size:
3.79 KB
patch
obsolete
>--- JDBCStore.java Mon May 11 10:18:26 2009 >+++ JDBCStoreDS.java Mon May 11 10:24:51 2009 >@@ -38,6 +38,10 @@ > 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; > > /** > * Implementation of the <code>Store</code> interface that stores >@@ -72,6 +76,11 @@ > protected String threadName = "JDBCStore"; > > /** >+ * The connection datasource >+ */ >+ private String datasourceName = null; >+ >+ /** > * The connection username to use when trying to connect to the database. > */ > protected String connectionName = null; >@@ -101,6 +110,11 @@ > * Driver to use. > */ > protected String driverName = null; >+ >+ /** >+ * Data source to use. >+ */ >+ private DataSource datasource = null; > > // ------------------------------------------------------------- Table & cols > >@@ -217,6 +231,23 @@ > } > > /** >+ * Return the datasource name to use to connect to the database. >+ * >+ */ >+ public String getDatasourceName() { >+ return datasourceName; >+ } >+ >+ /** >+ * Set the datasource name to use to connect to the database. >+ * >+ * @param datasourceName datasource name >+ */ >+ public void setDatasourceName(String datasourceName) { >+ this.datasourceName = datasourceName; >+ } >+ >+ /** > * Set the driver for this Store. > * > * @param driverName The new driver >@@ -850,8 +881,50 @@ > * @exception SQLException if a database error occurs > */ > protected Connection open() throws SQLException { >+ if (datasourceName == null) { >+ dbConnection = openDirectConnection(); >+ } else { >+ dbConnection = openJNDIConnection(); >+ } >+ return dbConnection; >+ } > >+ /** >+ * Open (if necessary) and return a database connection for use by >+ * this Realm. >+ * >+ * @exception SQLException if a database error occurs >+ */ >+ protected Connection openJNDIConnection() throws SQLException { >+ > // Do nothing if there is a database connection already open >+ if (dbConnection != null && !dbConnection.isClosed()) >+ return (dbConnection); >+ >+ try { >+ Context initialContext = new InitialContext(); >+ if (datasource == null) { >+ manager.getContainer().getLogger().info("Lookup datasource " + datasourceName); >+ datasource = (DataSource)initialContext.lookup(datasourceName); >+ } >+ return datasource.getConnection(); >+ } catch (NamingException ex) { >+ throw new SQLException("Unable to get datasource " + >+ datasourceName + " : " + ex.getMessage()); >+ } >+ >+ } >+ >+ >+ /** >+ * Open (if necessary) and return a database connection for use by >+ * this Realm. >+ * >+ * @exception SQLException if a database error occurs >+ */ >+ protected Connection openDirectConnection() throws SQLException { >+ >+ // Do nothing if there is a database connection already open > if (dbConnection != null) > return (dbConnection); > >@@ -955,7 +1028,9 @@ > * @param conn The connection to be released > */ > protected void release(Connection conn) { >- ; >+ if (datasourceName != null) { >+ close(conn); >+ } > } > > /** >@@ -965,7 +1040,9 @@ > super.start(); > > // Open connection to the database >- this.dbConnection = getConnection(); >+ if (datasourceName == null) { >+ this.dbConnection = getConnection(); >+ } > } > > /**
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 47061
:
23518
|
23521
|
23639
| 23640 |
23778