manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1201399 - in /incubator/lcf/trunk: ./ framework/ framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/ framework/core/src/main/java/org/apache/manifoldcf/core/database/ framework/core/src/test/java/org/apache/manifoldcf/core/t...
Date Sun, 13 Nov 2011 03:22:27 GMT
Author: kwright
Date: Sun Nov 13 03:22:26 2011
New Revision: 1201399

URL: http://svn.apache.org/viewvc?rev=1201399&view=rev
Log:
Fix fo CONNECTORS-209.  Add support for external HSQLDB instances.

Added:
    incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java   (with props)
    incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java   (with props)
    incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java   (with props)
    incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java   (with props)
    incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java   (with props)
    incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java   (with props)
Modified:
    incubator/lcf/trunk/CHANGES.txt
    incubator/lcf/trunk/build.xml
    incubator/lcf/trunk/framework/   (props changed)
    incubator/lcf/trunk/framework/build.xml
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
    incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java

Modified: incubator/lcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/CHANGES.txt?rev=1201399&r1=1201398&r2=1201399&view=diff
==============================================================================
--- incubator/lcf/trunk/CHANGES.txt (original)
+++ incubator/lcf/trunk/CHANGES.txt Sun Nov 13 03:22:26 2011
@@ -3,6 +3,12 @@ $Id$
 
 ======================= 0.4-dev =====================
 
+CONNECTORS-209: Add support for remote HSQLDB instances.  There are
+now configuration parameters for specifying protocol, server, and instance
+name, which if specified cause the HSQLDB driver to communicate to the
+specified remote instance.
+(Karl Wright)
+
 CONNECTORS-289: Wrong version of the OpenCMIS InMemory Server war in the page How to build and deploy
 (Piergiorgio Lucidi)
 

Modified: incubator/lcf/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/build.xml?rev=1201399&r1=1201398&r2=1201399&view=diff
==============================================================================
--- incubator/lcf/trunk/build.xml (original)
+++ incubator/lcf/trunk/build.xml Sun Nov 13 03:22:26 2011
@@ -27,6 +27,7 @@
         <delete dir="test-output"/>
         <delete dir="test-postgresql-output"/>
         <delete dir="test-HSQLDB-output"/>
+        <delete dir="test-HSQLDBext-output"/>
         <ant dir="site" target="clean"/>
         <ant dir="framework" target="clean"/>
         <delete dir="framework/lib"/>
@@ -199,6 +200,10 @@
         <ant dir="framework" target="run-tests-HSQLDB"/>
     </target>
 
+    <target name="run-tests-HSQLDBext-framework" depends="setup-framework">
+        <ant dir="framework" target="run-tests-HSQLDBext"/>
+    </target>
+
     <target name="setup-activedirectory-connector" depends="build-framework">
         <mkdir dir="connectors/activedirectory/lib"/>
         <copy todir="connectors/activedirectory/lib">
@@ -3291,7 +3296,7 @@
 
     <target name="test-pg" depends="run-tests-postgresql-framework,run-tests-postgresql-open-connectors,run-tests-postgresql-lgpl-connectors,run-tests-postgresql-proprietary-connectors,end-to-end-tests-postgresql"/>
 
-    <target name="test-hs" depends="run-tests-HSQLDB-framework,run-tests-HSQLDB-open-connectors,run-tests-HSQLDB-lgpl-connectors,run-tests-HSQLDB-proprietary-connectors,end-to-end-tests-HSQLDB"/>
+    <target name="test-hs" depends="run-tests-HSQLDB-framework,run-tests-HSQLDBext-framework,run-tests-HSQLDB-open-connectors,run-tests-HSQLDB-lgpl-connectors,run-tests-HSQLDB-proprietary-connectors,end-to-end-tests-HSQLDB"/>
 
     <target name="load-dr" depends="end-to-end-loadtests-derby"/>
 

Propchange: incubator/lcf/trunk/framework/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Nov 13 03:22:26 2011
@@ -6,3 +6,4 @@ target
 test-output
 test-output-postgresql
 test-output-HSQLDB
+test-output-HSQLDBext

Propchange: incubator/lcf/trunk/framework/
------------------------------------------------------------------------------
--- svn:ignores (added)
+++ svn:ignores Sun Nov 13 03:22:26 2011
@@ -0,0 +1 @@
+test-output-HSQLDBext

Added: incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java?rev=1201399&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java (added)
+++ incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java Sun Nov 13 03:22:26 2011
@@ -0,0 +1,117 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.agents.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.agents.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a testing base class that is responsible for setting up/tearing down the agents framework. */
+public class BaseHSQLDBext extends org.apache.manifoldcf.core.tests.BaseHSQLDBext
+{
+  
+  @Before
+  public void setUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      System.out.println("Warning: Preclean failed: "+e.getMessage());
+    }
+    try
+    {
+      localSetUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localSetUp()
+    throws Exception
+  {
+    super.localSetUp();
+    
+    // Install the agents tables
+    initialize();
+    ManifoldCF.initializeEnvironment();
+    IThreadContext tc = ThreadContextFactory.make();
+    ManifoldCF.installTables(tc);
+  }
+  
+  @After
+  public void cleanUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localCleanUp()
+    throws Exception
+  {
+    initialize();
+    if (isInitialized())
+    {
+      // Test the uninstall
+      ManifoldCF.initializeEnvironment();
+      IThreadContext tc = ThreadContextFactory.make();
+      
+      Exception currentException = null;
+      try
+      {
+        ManifoldCF.deinstallTables(tc);
+      }
+      catch (Exception e)
+      {
+        if (currentException != null)
+          currentException = e;
+      }
+      try
+      {
+        super.localCleanUp();
+      }
+      catch (Exception e)
+      {
+        if (currentException != null)
+          currentException = e;
+      }
+      if (currentException != null)
+        throw currentException;
+    }
+  }
+  
+}

Propchange: incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/BaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java?rev=1201399&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java (added)
+++ incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java Sun Nov 13 03:22:26 2011
@@ -0,0 +1,41 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.agents.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.agents.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a very basic sanity check */
+public class SanityHSQLDBextTest extends BaseHSQLDBext
+{
+  
+  @Test
+  public void sanityCheck()
+    throws Exception
+  {
+    // If we get this far, it must mean that the setup was successful, which is all that I'm shooting for in this test.
+  }
+  
+
+}

Propchange: incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/agents/src/test/java/org/apache/manifoldcf/agents/tests/SanityHSQLDBextTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/trunk/framework/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/build.xml?rev=1201399&r1=1201398&r2=1201399&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/build.xml (original)
+++ incubator/lcf/trunk/framework/build.xml Sun Nov 13 03:22:26 2011
@@ -23,6 +23,7 @@
         <delete dir="test-output"/>
         <delete dir="test-output-postgresql"/>
         <delete dir="test-output-HSQLDB"/>
+        <delete dir="test-output-HSQLDBext"/>
     </target>
     
     <target name="doc">
@@ -645,6 +646,31 @@
         </junit>
     </target>
 
+    <target name="run-tests-HSQLDBext" depends="compile-tests">
+        <mkdir dir="test-output-HSQLDBext"/>
+        <junit fork="true" maxmemory="128m" dir="test-output-HSQLDBext" outputtoformatters="true" showoutput="true" haltonfailure="true">
+            <classpath>
+                <fileset dir="lib">
+                    <include name="*.jar"/>
+                </fileset>
+                <pathelement location="build/core/classes"/>
+                <pathelement location="build/ui-core/classes"/>
+                <pathelement location="build/agents/classes"/>
+                <pathelement location="build/pull-agent/classes"/>
+                <pathelement location="build/authority-servlet/classes"/>
+                <pathelement location="build/api-servlet/classes"/>
+                <pathelement location="build/core-tests/classes"/>
+                <pathelement location="build/agents-tests/classes"/>
+                <pathelement location="build/pull-agent-tests/classes"/>
+            </classpath>
+            <formatter type="brief" usefile="false"/>
+
+            <test name="org.apache.manifoldcf.agents.tests.SanityHSQLDBextTest" todir="test-output-HSQLDBext"/>
+            <test name="org.apache.manifoldcf.crawler.tests.SanityHSQLDBextTest" todir="test-output-HSQLDBext"/>
+            <!-- MHL -->
+        </junit>
+    </target>
+
     <target name="run-script-interpreter" depends="script-engine">
         <java classname="org.apache.manifoldcf.scriptengine.ScriptParser" fork="true" dir="dist/script-engine" maxmemory="128M">
           <classpath>

Modified: incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java?rev=1201399&r1=1201398&r2=1201399&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java (original)
+++ incubator/lcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java Sun Nov 13 03:22:26 2011
@@ -78,16 +78,18 @@ public class ConnectionFactory
 
         // Logging.db.debug("adding pool alias [" + database + "]");
         // I had to up the timeout from one hour to 3 due to the webconnector keeping some connections open a very long time...
+	//System.out.println("jdbcUrl = '"+jdbcUrl+"', userName='"+userName+"', password='"+password+"'");
         _pool.addAlias(database, jdbcDriver, jdbcUrl,
           userName, password,
           maxDBConnections,
-          300,                    // Idle timeout: idle time before closing connection: 5 minutes
-        timeoutValue,   // Checkout timeout: Time a thread can have connection checked out: 24 hours
-        30,                     // Number of times you can check out a connection before it gets closed: 30
-        false);
+          300,                      // Idle timeout: idle time before closing connection: 5 minutes
+          timeoutValue,         // Checkout timeout: Time a thread can have connection checked out: 24 hours
+          30,                       // Number of times you can check out a connection before it gets closed: 30
+          false);
         cp = _pool.getPool(database);
       }
       rval = getConnectionWithRetries(ConnectionPoolManager.URL_PREFIX + database, null, null);
+      //rval = getConnectionWithRetries(ConnectionPoolManager.URL_PREFIX + database, userName, password);
 
       // Enter it in the pool so we can figure out whether it closed
       // synchronized (checkedOutConnections)

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=1201399&r1=1201398&r2=1201399&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 Sun Nov 13 03:22:26 2011
@@ -31,25 +31,96 @@ public class DBInterfaceHSQLDB extends D
 {
   public static final String _rcsid = "@(#)$Id$";
 
-  private static final String _url = "jdbc:hsqldb:file:";
+  private static final String _localUrl = "jdbc:hsqldb:file:";
+  private static final String _remoteUrl = "jdbc:hsqldb:";
   private static final String _driver = "org.hsqldb.jdbcDriver";
 
+  private static Map<String,String> legalProtocolValues;
+  static
+  {
+    legalProtocolValues = new HashMap<String,String>();
+    legalProtocolValues.put("hsql","hsql");
+    legalProtocolValues.put("http","http");
+    legalProtocolValues.put("https","https");
+  }
+  
   public final static String databasePathProperty = "org.apache.manifoldcf.hsqldbdatabasepath";
-
+  public final static String databaseProtocolProperty = "org.apache.manifoldcf.hsqldbdatabaseprotocol";
+  public final static String databaseServerProperty = "org.apache.manifoldcf.hsqldbdatabaseserver";
+  public final static String databasePortProperty = "org.apache.manifoldcf.hsqldbdatabaseport";
+  public final static String databaseInstanceProperty = "org.apache.manifoldcf.hsqldbdatabaseinstance";
+  
   protected String cacheKey;
-  // Postgresql serializable transactions are broken in that transactions that occur within them do not in fact work properly.
-  // So, once we enter the serializable realm, STOP any additional transactions from doing anything at all.
   protected int serializableDepth = 0;
-
+  protected boolean isRemote;
+  protected String schemaName;
+  
   public DBInterfaceHSQLDB(IThreadContext tc, String databaseName, String userName, String password)
     throws ManifoldCFException
   {
-    super(tc,_url+getFullDatabasePath(databaseName),_driver,getFullDatabasePath(databaseName),userName,password);
+    super(tc,getJDBCString(databaseName),_driver,getDatabaseString(databaseName),userName,password);
     cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
+    this.isRemote = ManifoldCF.getProperty(databaseProtocolProperty) != null;
     this.userName = userName;
     this.password = password;
+    if (this.isRemote)
+      schemaName = databaseName;
+    else
+      schemaName = null;
   }
 
+  protected void setupSchema()
+    throws ManifoldCFException
+  {
+    if (schemaName != null)
+    {
+      String localSchemaName = schemaName;
+      schemaName = null;
+      try
+      {
+        performModification("SET SCHEMA "+localSchemaName,null,null);
+        localSchemaName = null;
+      }
+      finally
+      {
+        schemaName = localSchemaName;
+      }
+    }
+  }
+
+  protected static String getJDBCString(String databaseName)
+    throws ManifoldCFException
+  {
+    // For local, we use the database name as the name of the database files.
+    // For remote, we connect to an instance specified by a different property, and use the database name as the schema name.
+    String protocol = ManifoldCF.getProperty(databaseProtocolProperty);
+    if (protocol == null)
+      return _localUrl+getFullDatabasePath(databaseName);
+    
+    // Remote instance.  Build the URL.
+    if (legalProtocolValues.get(protocol) == null)
+      throw new ManifoldCFException("The value of the '"+databaseProtocolProperty+"' property was illegal; try hsql, http, or https");
+    String server = ManifoldCF.getProperty(databaseServerProperty);
+    if (server == null)
+      throw new ManifoldCFException("HSQLDB remote mode requires '"+databaseServerProperty+"' property, containing a server name or IP address");
+    String port = ManifoldCF.getProperty(databasePortProperty);
+    if (port != null && port.length() > 0)
+      server += ":"+port;
+    String instanceName = ManifoldCF.getProperty(databaseInstanceProperty);
+    if (instanceName != null && instanceName.length() > 0)
+      server += "/" + instanceName;
+    return _remoteUrl + protocol + "://" + server;
+  }
+  
+  protected static String getDatabaseString(String databaseName)
+    throws ManifoldCFException
+  {
+    String protocol = ManifoldCF.getProperty(databaseProtocolProperty);
+    if (protocol == null)
+      return getFullDatabasePath(databaseName);
+    return databaseName;
+  }
+  
   protected static String getFullDatabasePath(String databaseName)
     throws ManifoldCFException
   {
@@ -68,17 +139,20 @@ public class DBInterfaceHSQLDB extends D
   public void openDatabase()
     throws ManifoldCFException
   {
-    try
-    {
-      // Force a load of the appropriate JDBC driver
-      Class.forName(_driver).newInstance();
-      DriverManager.getConnection(_url+databaseName,userName,password).close();
-    }
-    catch (Exception e)
+    if (!isRemote)
     {
-      throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.SETUP_ERROR);
+      try
+      {
+        // Force a load of the appropriate JDBC driver
+        Class.forName(_driver).newInstance();
+        DriverManager.getConnection(_localUrl+databaseName,userName,password).close();
+      }
+      catch (Exception e)
+      {
+        throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.SETUP_ERROR);
+      }
+      performModification("SET DATABASE TRANSACTION CONTROL MVCC",null,null);
     }
-    performModification("SET DATABASE TRANSACTION CONTROL MVCC",null,null);
   }
   
   /** Uninitialize.  This method is called during JVM shutdown, in order to close
@@ -87,28 +161,31 @@ public class DBInterfaceHSQLDB extends D
   public void closeDatabase()
     throws ManifoldCFException
   {
-    try
-    {
-      // Force a load of the appropriate JDBC driver
-      Class.forName(_driver).newInstance();
-    }
-    catch (Exception e)
+    if (!isRemote)
     {
-      throw new ManifoldCFException(e.getMessage(),e);
-    }
+      try
+      {
+        // Force a load of the appropriate JDBC driver
+        Class.forName(_driver).newInstance();
+      }
+      catch (Exception e)
+      {
+        throw new ManifoldCFException(e.getMessage(),e);
+      }
 
-    // For the shutdown itself, eat the exception
-    try
-    {
-      Connection c = DriverManager.getConnection(_url+databaseName,userName,password);
-      Statement s = c.createStatement();
-      s.execute("SHUTDOWN");
-      c.close();
-    }
-    catch (Exception e)
-    {
-      // Never any exception!
-      e.printStackTrace();
+      // For the shutdown itself, eat the exception
+      try
+      {
+        Connection c = DriverManager.getConnection(_localUrl+databaseName,userName,password);
+        Statement s = c.createStatement();
+        s.execute("SHUTDOWN");
+        c.close();
+      }
+      catch (Exception e)
+      {
+        // Never any exception!
+        e.printStackTrace();
+      }
     }
   }
 
@@ -517,7 +594,53 @@ public class DBInterfaceHSQLDB extends D
   public void createUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
     throws ManifoldCFException
   {
-    performModification("SET FILES SCALE 512",null,null);
+    if (isRemote)
+    {
+      // Create a connection using the admin credentials
+      Database masterDatabase = new DBInterfaceHSQLDB(context,"administration",adminUserName,adminPassword);
+      ArrayList params = new ArrayList();
+      // First, look for user
+      params.add(userName);
+      IResultSet userResult = masterDatabase.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_USERS WHERE USER_NAME=?",params,
+        null,null,null,true,-1,null,null);
+      if (userResult.getRowCount() == 0)
+      {
+        // Create the user
+	masterDatabase.executeQuery("CREATE USER "+quoteString(userName)+" PASSWORD "+quoteString(password),null,
+          null,invalidateKeys,null,false,0,null,null);
+      }
+      
+      // Now, look for schema
+      params.clear();
+      params.add(databaseName);
+      IResultSet schemaResult = masterDatabase.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_SCHEMAS WHERE TABLE_SCHEM=?",params,
+        null,null,null,true,-1,null,null);
+      if (schemaResult.getRowCount() == 0)
+      {
+        // Create the schema
+	masterDatabase.executeQuery("CREATE SCHEMA "+databaseName+" AUTHORIZATION "+quoteString(userName),null,
+          null,invalidateKeys,null,false,0,null,null);
+      }
+    }
+    else
+      performModification("SET FILES SCALE 512",null,null);
+  }
+
+  private static String quoteString(String password)
+  {
+    StringBuilder sb = new StringBuilder();
+    sb.append("\"");
+    int i = 0;
+    while (i < password.length())
+    {
+      char x = password.charAt(i);
+      if (x == '\"')
+        sb.append("\"");
+      sb.append(x);
+      i++;
+    }
+    sb.append("\"");
+    return sb.toString();
   }
 
   /** Drop user and database.
@@ -528,20 +651,39 @@ public class DBInterfaceHSQLDB extends D
   public void dropUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
     throws ManifoldCFException
   {
-    File f = new File(databaseName + ".properties");
-    if (f.exists())
+    if (isRemote)
     {
-      // Try to guarantee that all connections are discarded before we shut the database down.  Otherwise we get pool warnings from bitstream.
-      ConnectionFactory.releaseAll();
-      // Make sure database is shut down.
-      closeDatabase();
-      // Now, it's OK to delete
-      singleDelete(f);
-      singleDelete(new File(databaseName + ".data"));
-      singleDelete(new File(databaseName + ".lck"));
-      singleDelete(new File(databaseName + ".log"));
-      singleDelete(new File(databaseName + ".script"));
-      recursiveDelete(new File(databaseName + ".tmp"));
+      // Drop the schema, then the user
+      Database masterDatabase = new DBInterfaceHSQLDB(context,"administration",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);
+      }
+      catch (ManifoldCFException e)
+      {
+        throw reinterpretException(e);
+      }
+    }
+    else
+    {
+      File f = new File(databaseName + ".properties");
+      if (f.exists())
+      {
+        // Try to guarantee that all connections are discarded before we shut the database down.  Otherwise we get pool warnings from bitstream.
+        ConnectionFactory.releaseAll();
+        // Make sure database is shut down.
+        closeDatabase();
+        // Now, it's OK to delete
+        singleDelete(f);
+        singleDelete(new File(databaseName + ".data"));
+        singleDelete(new File(databaseName + ".lck"));
+        singleDelete(new File(databaseName + ".log"));
+        singleDelete(new File(databaseName + ".script"));
+        recursiveDelete(new File(databaseName + ".tmp"));
+      }
     }
   }
   
@@ -616,6 +758,7 @@ public class DBInterfaceHSQLDB extends D
   public void performModification(String query, List params, StringSet invalidateKeys)
     throws ManifoldCFException
   {
+    setupSchema();
     try
     {
       executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
@@ -778,6 +921,7 @@ public class DBInterfaceHSQLDB extends D
   public IResultSet performQuery(String query, List params, StringSet cacheKeys, String queryClass)
     throws ManifoldCFException
   {
+    setupSchema();
     try
     {
       return executeQuery(query,params,cacheKeys,null,queryClass,true,-1,null,null);
@@ -802,6 +946,7 @@ public class DBInterfaceHSQLDB extends D
     int maxResults, ILimitChecker returnLimit)
     throws ManifoldCFException
   {
+    setupSchema();
     try
     {
       return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,null,returnLimit);
@@ -827,6 +972,7 @@ public class DBInterfaceHSQLDB extends D
     int maxResults, ResultSpecification resultSpec, ILimitChecker returnLimit)
     throws ManifoldCFException
   {
+    setupSchema();
     try
     {
       return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);

Added: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java?rev=1201399&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java (added)
+++ incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java Sun Nov 13 03:22:26 2011
@@ -0,0 +1,231 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.core.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.core.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+import java.lang.reflect.*;
+
+/** This is a testing base class that is responsible for setting up/tearing down the core HSQLDB remote database. */
+public class BaseHSQLDBext
+{
+  protected File currentPath = null;
+  protected File configFile = null;
+  protected File loggingFile = null;
+  protected File logOutputFile = null;
+
+  protected DatabaseThread databaseThread = null;
+  
+  protected void initialize()
+    throws Exception
+  {
+    if (currentPath == null)
+    {
+      // Start "remote" hsqldb instance
+      startDatabase();
+      
+      currentPath = new File(".").getCanonicalFile();
+
+      // First, write a properties file and a logging file, in the current directory.
+      configFile = new File("properties.xml").getCanonicalFile();
+      loggingFile = new File("logging.ini").getCanonicalFile();
+      logOutputFile = new File("manifoldcf.log").getCanonicalFile();
+
+      // Set a system property that will point us to the proper place to find the properties file
+      System.setProperty("org.apache.manifoldcf.configfile",configFile.getCanonicalFile().getAbsolutePath());
+    }
+  }
+  
+  protected boolean isInitialized()
+  {
+    return configFile.exists();
+  }
+  
+  @Before
+  public void setUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      System.out.println("Warning: Preclean error: "+e.getMessage());
+    }
+    try
+    {
+      localSetUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+
+  protected void localSetUp()
+    throws Exception
+  {
+    // Initialize
+    initialize();
+    String currentPathString = currentPath.getAbsolutePath();
+    writeFile(loggingFile,
+      "log4j.appender.MAIN.File="+logOutputFile.getAbsolutePath().replaceAll("\\\\","/")+"\n" +
+      "log4j.rootLogger=WARN, MAIN\n" +
+      "log4j.appender.MAIN=org.apache.log4j.RollingFileAppender\n" +
+      "log4j.appender.MAIN.layout=org.apache.log4j.PatternLayout\n" +
+      "log4j.appender.MAIN.layout.ConversionPattern=%5p %d{ISO8601} (%t) - %m%n\n"
+    );
+
+    writeFile(configFile,
+      "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
+      "<configuration>\n"+
+      "  <property name=\"org.apache.manifoldcf.databaseimplementationclass\" value=\"org.apache.manifoldcf.core.database.DBInterfaceHSQLDB\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.hsqldbdatabaseprotocol\" value=\"hsql\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.hsqldbdatabaseserver\" value=\"localhost\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.hsqldbdatabaseinstance\" value=\"xdb\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.database.maxquerytime\" value=\"30\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.crawler.threads\" value=\"30\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.crawler.expirethreads\" value=\"10\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.crawler.cleanupthreads\" value=\"10\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.crawler.deletethreads\" value=\"10\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.database.maxhandles\" value=\"80\"/>\n" +
+      "  <property name=\"org.apache.manifoldcf.logconfigfile\" value=\""+loggingFile.getAbsolutePath().replaceAll("\\\\","/")+"\"/>\n" +
+      "</configuration>\n");
+
+    ManifoldCF.initializeEnvironment();
+    IThreadContext tc = ThreadContextFactory.make();
+    
+    // Create the database
+    ManifoldCF.createSystemDatabase(tc,"sa","");
+
+  }
+  
+  @After
+  public void cleanUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localCleanUp()
+    throws Exception
+  {
+    initialize();
+    if (isInitialized())
+    {
+      ManifoldCF.initializeEnvironment();
+      IThreadContext tc = ThreadContextFactory.make();
+      
+      // Remove the database
+      ManifoldCF.dropSystemDatabase(tc,"sa","");
+      
+      // Get rid of the property and logging files.
+      logOutputFile.delete();
+      configFile.delete();
+      loggingFile.delete();
+      
+      ManifoldCF.resetEnvironment();
+      stopDatabase();
+    }
+  }
+
+  protected void startDatabase()
+    throws Exception
+  {
+    databaseThread = new DatabaseThread();
+    databaseThread.start();
+  }
+  
+  protected void stopDatabase()
+    throws Exception
+  {
+    while (true)
+    {
+      if (!databaseThread.isAlive())
+        break;
+      databaseThread.interrupt();
+      Thread.yield();
+    }
+    databaseThread.join();
+  }
+  
+  protected static void writeFile(File f, String fileContents)
+    throws IOException
+  {
+    OutputStream os = new FileOutputStream(f);
+    try
+    {
+      Writer w = new OutputStreamWriter(os,"utf-8");
+      try
+      {
+        w.write(fileContents);
+      }
+      finally
+      {
+        w.close();
+      }
+    }
+    finally
+    {
+      os.close();
+    }
+  }
+  
+  protected static class DatabaseThread extends Thread
+  {
+    public DatabaseThread()
+    {
+      setName("Database runner thread");
+    }
+    
+    public void run()
+    {
+      // We need to do the equivalent of:
+      // java -cp ../lib/hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb
+      try
+      {
+        Class x = Class.forName("org.hsqldb.Server");
+        String[] args = new String[]{"-database.0","file:extdb;hsqldb.tx=mvcc;hsqldb.cache_file_scale=512","-dbname.0","xdb"};
+        Method m = x.getMethod("main",String[].class);
+        m.invoke(null,(Object)args);
+      }
+      catch (Exception e)
+      {
+        e.printStackTrace();
+      }
+    }
+    
+  }
+  
+}

Propchange: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/core/src/test/java/org/apache/manifoldcf/core/tests/BaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java?rev=1201399&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java (added)
+++ incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java Sun Nov 13 03:22:26 2011
@@ -0,0 +1,120 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.crawler.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.crawler.interfaces.*;
+import org.apache.manifoldcf.crawler.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a testing base class that is responsible for setting up/tearing down the agents framework. */
+public class BaseHSQLDBext extends org.apache.manifoldcf.agents.tests.BaseHSQLDBext
+{
+  
+  @Before
+  public void setUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      System.out.println("Warning: Preclean failed: "+e.getMessage());
+    }
+    try
+    {
+      localSetUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localSetUp()
+    throws Exception
+  {
+    super.localSetUp();
+    
+    // Install the agents tables
+    initialize();
+    ManifoldCF.initializeEnvironment();
+    IThreadContext tc = ThreadContextFactory.make();
+    IAgentManager mgr = AgentManagerFactory.make(tc);
+    mgr.registerAgent("org.apache.manifoldcf.crawler.system.CrawlerAgent");
+  }
+  
+  @After
+  public void cleanUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localCleanUp()
+    throws Exception
+  {
+    initialize();
+    if (isInitialized())
+    {
+      // Test the uninstall
+      ManifoldCF.initializeEnvironment();
+      IThreadContext tc = ThreadContextFactory.make();
+      
+      Exception currentException = null;
+      try
+      {
+        IAgentManager mgr = AgentManagerFactory.make(tc);
+        mgr.unregisterAgent("org.apache.manifoldcf.crawler.system.CrawlerAgent");
+      }
+      catch (Exception e)
+      {
+        if (currentException != null)
+          currentException = e;
+      }
+      try
+      {
+        super.localCleanUp();
+      }
+      catch (Exception e)
+      {
+        if (currentException != null)
+          currentException = e;
+      }
+      if (currentException != null)
+        throw currentException;
+    }
+  }
+
+}

Propchange: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/BaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java?rev=1201399&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java (added)
+++ incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java Sun Nov 13 03:22:26 2011
@@ -0,0 +1,330 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.crawler.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.crawler.interfaces.*;
+import org.apache.manifoldcf.authorities.interfaces.*;
+import org.apache.manifoldcf.core.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a testing base class that is responsible for setting up/tearing down the agents framework. */
+public class ConnectorBaseHSQLDBext extends org.apache.manifoldcf.crawler.tests.BaseHSQLDBext
+{
+  
+  protected String[] getConnectorClasses()
+  {
+    return new String[0];
+  }
+  
+  protected String[] getConnectorNames()
+  {
+    return new String[0];
+  }
+  
+  protected String[] getAuthorityClasses()
+  {
+    return new String[0];
+  }
+  
+  protected String[] getAuthorityNames()
+  {
+    return new String[0];
+  }
+  
+  protected String[] getOutputClasses()
+  {
+    return new String[0];
+  }
+  
+  protected String[] getOutputNames()
+  {
+    return new String[0];
+  }
+  
+  @Before
+  public void setUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      System.out.println("Warning: Preclean failed: "+e.getMessage());
+    }
+    try
+    {
+      localSetUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localSetUp()
+    throws Exception
+  {
+    
+    super.localSetUp();
+    
+    // Register the connector we're testing
+    initialize();
+    ManifoldCF.initializeEnvironment();
+    IThreadContext tc = ThreadContextFactory.make();
+
+    IDBInterface database = DBInterfaceFactory.make(tc,
+      ManifoldCF.getMasterDatabaseName(),
+      ManifoldCF.getMasterDatabaseUsername(),
+      ManifoldCF.getMasterDatabasePassword());
+    
+    IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+    IAuthorityConnectorManager authMgr = AuthorityConnectorManagerFactory.make(tc);
+    IJobManager jobManager = JobManagerFactory.make(tc);
+    IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+    IOutputConnectorManager outputMgr = OutputConnectorManagerFactory.make(tc);
+    IOutputConnectionManager outputConnManager = OutputConnectionManagerFactory.make(tc);
+
+    // Deregistration should be done in a transaction
+    database.beginTransaction();
+    try
+    {
+      int i;
+      
+      String[] connectorClasses = getConnectorClasses();
+      String[] connectorNames = getConnectorNames();
+
+      i = 0;
+      while (i < connectorClasses.length)
+      {
+        // First, register connector
+        mgr.registerConnector(connectorNames[i],connectorClasses[i]);
+        // Then, signal to all jobs that might depend on this connector that they can switch state
+        // Find the connection names that come with this class
+        String[] connectionNames = connManager.findConnectionsForConnector(connectorClasses[i]);
+        // For each connection name, modify the jobs to note that the connector is now installed
+        jobManager.noteConnectorRegistration(connectionNames);
+        i++;
+      }
+      
+      String[] authorityClasses = getAuthorityClasses();
+      String[] authorityNames = getAuthorityNames();
+      
+      i = 0;
+      while (i < authorityClasses.length)
+      {
+        authMgr.registerConnector(authorityNames[i],authorityClasses[i]);
+        i++;
+      }
+      
+      String[] outputClasses = getOutputClasses();
+      String[] outputNames = getOutputNames();
+      
+      i = 0;
+      while (i < outputClasses.length)
+      {
+        // First, register connector
+        outputMgr.registerConnector(outputNames[i],outputClasses[i]);
+        // Then, signal to all jobs that might depend on this connector that they can switch state
+        // Find the connection names that come with this class
+        String[] connectionNames = outputConnManager.findConnectionsForConnector(outputClasses[i]);
+        // For all connection names, notify all agents of the registration
+        AgentManagerFactory.noteOutputConnectorRegistration(tc,connectionNames);
+        i++;
+      }
+      
+    }
+    catch (ManifoldCFException e)
+    {
+      database.signalRollback();
+      throw e;
+    }
+    catch (Error e)
+    {
+      database.signalRollback();
+      throw e;
+    }
+    finally
+    {
+      database.endTransaction();
+    }
+  }
+  
+  @After
+  public void cleanUp()
+    throws Exception
+  {
+    try
+    {
+      localCleanUp();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  protected void localCleanUp()
+    throws Exception
+  {
+    initialize();
+    if (isInitialized())
+    {
+      // Test the uninstall
+      ManifoldCF.initializeEnvironment();
+      IThreadContext tc = ThreadContextFactory.make();
+      
+      Exception currentException = null;
+      // First, tear down all jobs, connections, authority connections, and output connections.
+      try
+      {
+        IRepositoryConnectionManager connMgr = RepositoryConnectionManagerFactory.make(tc);
+        IAuthorityConnectionManager authConnMgr = AuthorityConnectionManagerFactory.make(tc);
+        IOutputConnectionManager outputMgr = OutputConnectionManagerFactory.make(tc);
+        
+        // Now, get a list of the repository connections
+        IRepositoryConnection[] connections = connMgr.getAllConnections();
+        int i = 0;
+        while (i < connections.length)
+        {
+          connMgr.delete(connections[i++].getName());
+        }
+
+        // Get a list of authority connections
+        IAuthorityConnection[] authorities = authConnMgr.getAllConnections();
+        i = 0;
+        while (i < authorities.length)
+        {
+          authConnMgr.delete(authorities[i++].getName());
+        }
+        
+        // Finally, get rid of output connections
+        IOutputConnection[] outputs = outputMgr.getAllConnections();
+        i = 0;
+        while (i < outputs.length)
+        {
+          outputMgr.delete(outputs[i++].getName());
+        }
+
+      }
+      catch (Exception e)
+      {
+        currentException = e;
+      }
+      try
+      {
+        IDBInterface database = DBInterfaceFactory.make(tc,
+          ManifoldCF.getMasterDatabaseName(),
+          ManifoldCF.getMasterDatabaseUsername(),
+          ManifoldCF.getMasterDatabasePassword());
+        
+        IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+        IAuthorityConnectorManager authMgr = AuthorityConnectorManagerFactory.make(tc);
+        IOutputConnectorManager outputMgr = OutputConnectorManagerFactory.make(tc);
+        IOutputConnectionManager outputConnManager = OutputConnectionManagerFactory.make(tc);
+        IJobManager jobManager = JobManagerFactory.make(tc);
+        IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+        
+        // Deregistration should be done in a transaction
+        database.beginTransaction();
+        try
+        {
+          int i;
+          
+          String[] connectorClasses = getConnectorClasses();
+
+          i = 0;
+          while (i < connectorClasses.length)
+          {
+            // Find the connection names that come with this class
+            String[] connectionNames = connManager.findConnectionsForConnector(connectorClasses[i]);
+            // For each connection name, modify the jobs to note that the connector is no longer installed
+            jobManager.noteConnectorDeregistration(connectionNames);
+            // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+            mgr.unregisterConnector(connectorClasses[i]);
+            i++;
+          }
+          
+          String[] authorityClasses = getAuthorityClasses();
+          
+          i = 0;
+          while (i < authorityClasses.length)
+          {
+            authMgr.unregisterConnector(authorityClasses[i]);
+            i++;
+          }
+          
+          String[] outputClasses = getOutputClasses();
+          
+          i = 0;
+          while (i < outputClasses.length)
+          {
+            // Find the connection names that come with this class
+            String[] connectionNames = outputConnManager.findConnectionsForConnector(outputClasses[i]);
+            // For all connection names, notify all agents of the deregistration
+            AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
+            // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+            outputMgr.unregisterConnector(outputClasses[i]);
+            i++;
+          }
+          
+        }
+        catch (ManifoldCFException e)
+        {
+          database.signalRollback();
+          throw e;
+        }
+        catch (Error e)
+        {
+          database.signalRollback();
+          throw e;
+        }
+        finally
+        {
+          database.endTransaction();
+        }
+      }
+      catch (Exception e)
+      {
+        if (currentException != null)
+          currentException = e;
+      }
+      try
+      {
+        super.localCleanUp();
+      }
+      catch (Exception e)
+      {
+        if (currentException != null)
+          currentException = e;
+      }
+      if (currentException != null)
+        throw currentException;
+    }
+  }
+
+}

Propchange: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/ConnectorBaseHSQLDBext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java?rev=1201399&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java (added)
+++ incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java Sun Nov 13 03:22:26 2011
@@ -0,0 +1,41 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.crawler.tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.agents.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a very basic sanity check */
+public class SanityHSQLDBextTest extends BaseHSQLDBext
+{
+  
+  @Test
+  public void sanityCheck()
+    throws Exception
+  {
+    // If we get this far, it must mean that the setup was successful, which is all that I'm shooting for in this test.
+  }
+  
+
+}

Propchange: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/pull-agent/src/test/java/org/apache/manifoldcf/crawler/tests/SanityHSQLDBextTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message