Author: kwright
Date: Fri Aug 14 01:03:18 2015
New Revision: 1695808

URL: http://svn.apache.org/r1695808
Log:
Fix for CONNECTORS-1226.

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/framework/build.xml
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
    
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java

Modified: manifoldcf/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Fri Aug 14 01:03:18 2015
@@ -3,6 +3,11 @@ $Id$
 
 ======================= 2.2-dev =====================
 
+CONNECTORS-1226: PostgreSQL does not implement the isValid()
+JDBC method in the driver we include, so make sure when we call it
+we don't fail if we get an exception.  Related to CONNECTORS-1202.
+(Karl Wright)
+
 CONNECTORS-1224: Upgrade to Hadoop 2.6.0.
 (Shinichiro Abe)
 

Modified: manifoldcf/trunk/framework/build.xml
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/build.xml?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- manifoldcf/trunk/framework/build.xml (original)
+++ manifoldcf/trunk/framework/build.xml Fri Aug 14 01:03:18 2015
@@ -1849,6 +1849,7 @@
                 <pathelement location="build/ui-core/classes"/>
                 <pathelement location="build/agents/classes"/>
                 <pathelement location="build/pull-agent/classes"/>
+                <pathelement location="build/connector-common/classes"/>
                 <pathelement location="build/authority-servlet/classes"/>
                 <pathelement location="build/api-servlet/classes"/>
                 <pathelement location="build/core-tests/classes"/>
@@ -1872,6 +1873,7 @@
                 <pathelement location="build/ui-core/classes"/>
                 <pathelement location="build/agents/classes"/>
                 <pathelement location="build/pull-agent/classes"/>
+                <pathelement location="build/connector-common/classes"/>
                 <pathelement location="build/authority-servlet/classes"/>
                 <pathelement location="build/api-servlet/classes"/>
                 <pathelement location="build/core-tests/classes"/>
@@ -1895,6 +1897,7 @@
                 <pathelement location="build/ui-core/classes"/>
                 <pathelement location="build/agents/classes"/>
                 <pathelement location="build/pull-agent/classes"/>
+                <pathelement location="build/connector-common/classes"/>
                 <pathelement location="build/authority-servlet/classes"/>
                 <pathelement location="build/api-servlet/classes"/>
                 <pathelement location="build/core-tests/classes"/>
@@ -1919,6 +1922,7 @@
                 <pathelement location="build/ui-core/classes"/>
                 <pathelement location="build/agents/classes"/>
                 <pathelement location="build/pull-agent/classes"/>
+                <pathelement location="build/connector-common/classes"/>
                 <pathelement location="build/authority-servlet/classes"/>
                 <pathelement location="build/api-servlet/classes"/>
                 <pathelement location="build/core-tests/classes"/>

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java
 Fri Aug 14 01:03:18 2015
@@ -102,6 +102,12 @@ public class ConnectionFactory
     c.release();
   }
 
+  public static void flush()
+  {
+    if (poolManager != null)
+      poolManager.flush();
+  }
+  
   public static void releaseAll()
   {
     if (poolManager != null)
@@ -191,7 +197,18 @@ public class ConnectionFactory
       
       thisPool.shutdown();
     }
-      
+    
+    public void flush()
+    {
+      synchronized (poolExistenceLock)
+      {
+        if (_pool != null)
+        {
+          _pool.flush();
+        }
+      }
+    }
+    
       /*
       // Cleanup strategy is to close everything that can easily be closed, 
but leave around connections that are so busy that they will not close within a 
certain amount of
       // time.  To do that, we spin up a thread for each connection, which 
attempts to close that connection, and then wait until either 15 seconds 
passes, or all the threads

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
 Fri Aug 14 01:03:18 2015
@@ -564,6 +564,8 @@ public class DBInterfacePostgreSQL exten
         null,null,null,true,-1,null,null);
       if (set.getRowCount() == 0)
       {
+        // Special for Postgresql
+        masterDatabase.prepareForDatabaseCreate();
        masterDatabase.executeQuery("CREATE DATABASE "+databaseName+" OWNER "+
          userName+" ENCODING 
'utf8'",null,null,invalidateKeys,null,false,0,null,null);
       }

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
 Fri Aug 14 01:03:18 2015
@@ -131,6 +131,19 @@ public abstract class Database
     return rawLabelName;
   }
   
+  /** Prepare database for database creation step.
+  * In order to do this, all connections to the back end must be closed.  
Since we have a pool, and a local
+  * connection, these all need to be cleaned up.
+  */
+  public void prepareForDatabaseCreate()
+    throws ManifoldCFException
+  {
+    if (connection != null) {
+      throw new ManifoldCFException("Can't do a database create within a 
transaction");
+    }
+    ConnectionFactory.flush();
+  }
+  
   /** Execute arbitrary database query, and optionally cache the result.  
Cached results are
   * returned for this operation if they are valid and appropriate.  Note that 
any cached results
   * returned were only guaranteed to be pertinent at the time the cached 
result was obtained; the

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
 Fri Aug 14 01:03:18 2015
@@ -83,7 +83,17 @@ public class ConnectionPool
             throw new InterruptedException("Pool already closed");
           rval = freeConnections[--freePointer];
           freeConnections[freePointer] = null;
-          if (!rval.isValid(1)) {
+          boolean isValid = true;
+          try
+          {
+            isValid = rval.isValid(1);
+          }
+          catch (SQLException e)
+          {
+            // Ignore this; we just can't check if handle is valid I guess.
+            // (Postgresql doesn't implement this method so it fails always)
+          }
+          if (!isValid) {
             // If the connection is invalid, drop it on the floor, and get a 
new one.
             activeConnections--;
             rval.close();
@@ -178,6 +188,27 @@ public class ConnectionPool
     }
   }
   
+  /** Flush the pool.
+  */
+  public synchronized void flushPool()
+  {
+    for (int i = 0 ; i < freePointer ; i++)
+    {
+      try
+      {
+        freeConnections[i].close();
+      }
+      catch (SQLException e)
+      {
+        Logging.db.warn("Error closing pooled connection: "+e.getMessage(),e);
+      }
+      freeConnections[i] = null;
+      activeConnections--;
+    }
+    freePointer = 0;
+    notifyAll();
+  }
+  
   /** Close down the pool.
   */
   public synchronized void closePool()
@@ -243,6 +274,8 @@ public class ConnectionPool
     {
       synchronized (outstandingConnections)
       {
+        if (!outstandingConnections.contains(connection))
+          Logging.db.warn("Released a connection that wasn't tracked!!");
         outstandingConnections.remove(connection);
       }
     }

Modified: 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java?rev=1695808&r1=1695807&r2=1695808&view=diff
==============================================================================
--- 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
 (original)
+++ 
manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
 Fri Aug 14 01:03:18 2015
@@ -66,6 +66,20 @@ public class ConnectionPoolManager
     return cp;
   }
   
+  public void flush()
+  {
+    synchronized (this)
+    {
+      Iterator<String> iter = poolMap.keySet().iterator();
+      while (iter.hasNext())
+      {
+        String poolKey = iter.next();
+        ConnectionPool cp = poolMap.get(poolKey);
+        cp.flushPool();
+      }
+    }
+  }
+  
   public void shutdown()
   {
     //System.out.println("JDBC POOL SHUTDOWN CALLED");


Reply via email to