You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/12/17 16:24:06 UTC
svn commit: r1215508 - in /incubator/lcf/trunk: CHANGES.txt
framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
Author: kwright
Date: Sat Dec 17 15:24:05 2011
New Revision: 1215508
URL: http://svn.apache.org/viewvc?rev=1215508&view=rev
Log:
Fix for CONNECTORS-330. Initialize each connection when we get it from the pool.
Modified:
incubator/lcf/trunk/CHANGES.txt
incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
Modified: incubator/lcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/CHANGES.txt?rev=1215508&r1=1215507&r2=1215508&view=diff
==============================================================================
--- incubator/lcf/trunk/CHANGES.txt (original)
+++ incubator/lcf/trunk/CHANGES.txt Sat Dec 17 15:24:05 2011
@@ -8,6 +8,13 @@ CONNECTORS-324: Maven build broken
======================= Release 0.4 =========================
+CONNECTORS-330: Add infrastructure that permits the database class
+to initialize a connection every time it is pulled from the pool. This is
+necessary to support HSQLDB, because a number of HSQLDB's states
+are actually maintained in the JDBC driver and thus cannot be managed
+well in a pooled connection paradigm.
+(Fred Toussi, Karl Wright)
+
CONNECTORS-321: Correct a problem with external HSQLDB databases
where the schema wasn't being reliably set for the session.
(Fred Toussi, Karl Wright)
Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java?rev=1215508&r1=1215507&r2=1215508&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java (original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java Sat Dec 17 15:24:05 2011
@@ -114,6 +114,20 @@ public class DBInterfaceHSQLDB extends D
return pathString + databaseName;
}
+ /** Initialize the connection (for HSQLDB).
+ * HSQLDB has a great deal of session state, and no way to pool individual connections based on it.
+ * So, every time we pull a connection off the pool we have to execute a number of statements on it
+ * before it can work reliably for us. This is the abstraction that permits that to happen.
+ *@param connection is the JDBC connection.
+ */
+ protected void initializeConnection(Connection connection)
+ throws ManifoldCFException
+ {
+ super.initializeConnection(connection);
+ // Set the schema
+ executeViaThread(connection,"SET SCHEMA "+schemaNameForQueries.toUpperCase(),null,false,-1,null,null);
+ }
+
/** Initialize. This method is called once per JVM instance, in order to set up
* database communication.
*/
@@ -578,7 +592,7 @@ public class DBInterfaceHSQLDB extends D
if (isRemote)
{
// Create a connection using the admin credentials
- Database masterDatabase = new DBInterfaceHSQLDB(context,"administration",adminUserName,adminPassword);
+ Database masterDatabase = new DBInterfaceHSQLDB(context,"PUBLIC",adminUserName,adminPassword);
ArrayList params = new ArrayList();
// First, look for user
params.add(userName);
@@ -599,10 +613,8 @@ public class DBInterfaceHSQLDB extends D
if (schemaResult.getRowCount() == 0)
{
// Create the schema
- masterDatabase.executeQuery("CREATE SCHEMA "+databaseName+" AUTHORIZATION "+quoteString(userName),null,
+ masterDatabase.executeQuery("CREATE SCHEMA "+databaseName.toUpperCase()+" AUTHORIZATION "+quoteString(userName),null,
null,invalidateKeys,null,false,0,null,null);
- masterDatabase.executeQuery("ALTER USER "+quoteString(userName)+" SET INITIAL SCHEMA "+databaseName,null,
- null,invalidateKeys,null,false,0,null,null);
}
}
else
@@ -637,13 +649,13 @@ public class DBInterfaceHSQLDB extends D
if (isRemote)
{
// Drop the schema, then the user
- Database masterDatabase = new DBInterfaceHSQLDB(context,"administration",adminUserName,adminPassword);
+ Database masterDatabase = new DBInterfaceHSQLDB(context,"PUBLIC",adminUserName,adminPassword);
try
{
// Drop schema
masterDatabase.executeQuery("DROP SCHEMA "+databaseName,null,null,invalidateKeys,null,false,0,null,null);
// Drop user
- masterDatabase.executeQuery("DROP USER "+userName,null,null,invalidateKeys,null,false,0,null,null);
+ masterDatabase.executeQuery("DROP USER "+quoteString(userName),null,null,invalidateKeys,null,false,0,null,null);
}
catch (ManifoldCFException e)
{
Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1215508&r1=1215507&r2=1215508&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java (original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java Sat Dec 17 15:24:05 2011
@@ -243,6 +243,8 @@ public abstract class Database
connection = ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password);
try
{
+ // Initialize the connection (for HSQLDB)
+ initializeConnection(connection);
// Start a transaction
startATransaction();
}
@@ -713,6 +715,8 @@ public abstract class Database
Connection tempConnection = ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password);
try
{
+ // Initialize the connection (for HSQLDB)
+ initializeConnection(tempConnection);
return executeViaThread(tempConnection,query,params,bResults,maxResults,spec,returnLimit);
}
catch (ManifoldCFException e)
@@ -733,6 +737,18 @@ public abstract class Database
// These are protected helper methods
+ /** Initialize the connection (for HSQLDB).
+ * HSQLDB has a great deal of session state, and no way to pool individual connections based on it.
+ * So, every time we pull a connection off the pool we have to execute a number of statements on it
+ * before it can work reliably for us. This is the abstraction that permits that to happen.
+ *@param connection is the JDBC connection.
+ */
+ protected void initializeConnection(Connection connection)
+ throws ManifoldCFException
+ {
+ // Default implementation does nothing; override to make special stuff happen.
+ }
+
/** Run a query. No caching is involved at all at this level.
* @param query String the query string
* @param bResults boolean whether to load the resultset or not