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 2012/08/14 01:49:13 UTC

svn commit: r1372670 - in /manifoldcf/trunk/framework: core/src/main/java/org/apache/manifoldcf/core/database/ core/src/main/java/org/apache/manifoldcf/core/interfaces/ pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/

Author: kwright
Date: Mon Aug 13 23:49:13 2012
New Revision: 1372670

URL: http://svn.apache.org/viewvc?rev=1372670&view=rev
Log:
Fix NPE from the hopcount fix I committed earlier today.

Modified:
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java?rev=1372670&r1=1372669&r2=1372670&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java Mon Aug 13 23:49:13 2012
@@ -33,7 +33,10 @@ public class DBInterfaceMySQL extends Da
   public static final String mysqlClientProperty = "org.apache.manifoldcf.mysql.client";
   
   private static final String _driver = "com.mysql.jdbc.Driver";
-  
+
+  // Once we enter the serializable realm, STOP any additional transactions from doing anything at all.
+  protected int serializableDepth = 0;
+
   protected String cacheKey;
 
   public DBInterfaceMySQL(IThreadContext tc, String databaseName, String userName, String password)
@@ -1001,9 +1004,16 @@ public class DBInterfaceMySQL extends Da
   public void beginTransaction()
     throws ManifoldCFException
   {
-    super.beginTransaction(TRANSACTION_READCOMMITTED);
+    beginTransaction(TRANSACTION_ENCLOSING);
   }
 
+  protected int getActualTransactionType()
+  {
+    if (th == null)
+      return -1;
+    return th.getTransactionType();
+  }
+  
   /** Begin a database transaction.  This method call MUST be paired with an endTransaction() call,
   * or database handles will be lost.  If the transaction should be rolled back, then signalRollback() should
   * be called before the transaction is ended.
@@ -1016,7 +1026,40 @@ public class DBInterfaceMySQL extends Da
   public void beginTransaction(int transactionType)
     throws ManifoldCFException
   {
-    super.beginTransaction(TRANSACTION_READCOMMITTED);
+    if (getCurrentTransactionType() == TRANSACTION_SERIALIZED)
+    {
+      serializableDepth++;
+      return;
+    }
+
+    if (transactionType == TRANSACTION_ENCLOSING)
+    {
+      transactionType = getCurrentTransactionType();
+    }
+
+    switch (transactionType)
+    {
+    case TRANSACTION_REPEATABLEREAD:
+      if (transactionType != getActualTransactionType())
+        // Must precede actual transaction start
+        performModification("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ",null,null);
+      super.beginTransaction(transactionType);
+      break;
+    case TRANSACTION_READCOMMITTED:
+      if (transactionType != getActualTransactionType())
+        // Must precede actual transaction start
+        performModification("SET TRANSACTION ISOLATION LEVEL READ COMMITTED",null,null);
+      super.beginTransaction(transactionType);
+      break;
+    case TRANSACTION_SERIALIZED:
+      if (transactionType != getActualTransactionType())
+        // Must precede actual transaction start
+        performModification("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE",null,null);
+      super.beginTransaction(TRANSACTION_SERIALIZED);
+      break;
+    default:
+      throw new ManifoldCFException("Bad transaction type: "+Integer.toString(transactionType));
+    }
   }
 
   /** Abstract method to start a transaction */
@@ -1046,7 +1089,29 @@ public class DBInterfaceMySQL extends Da
       throw reinterpretException(e);
     }
   }
-  
+
+  /** Signal that a rollback should occur on the next endTransaction().
+  */
+  public void signalRollback()
+  {
+    if (serializableDepth == 0)
+      super.signalRollback();
+  }
+
+  /** End a database transaction, either performing a commit or a rollback (depending on whether
+  * signalRollback() was called within the transaction).
+  */
+  public void endTransaction()
+    throws ManifoldCFException
+  {
+    if (serializableDepth > 0)
+    {
+      serializableDepth--;
+      return;
+    }
+    super.endTransaction();
+  }
+
   /** Abstract method to roll back a transaction */
   protected void rollbackCurrentTransaction()
     throws ManifoldCFException

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java?rev=1372670&r1=1372669&r2=1372670&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java Mon Aug 13 23:49:13 2012
@@ -38,6 +38,7 @@ public interface IDBInterface
   public static int TRANSACTION_ENCLOSING = 0;
   public static int TRANSACTION_READCOMMITTED = 1;
   public static int TRANSACTION_SERIALIZED = 2;
+  public static int TRANSACTION_REPEATABLEREAD = 3;
 
   /** Initialize.  This method is called once per JVM instance, in order to set up
   * database communication.

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java?rev=1372670&r1=1372669&r2=1372670&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java (original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java Mon Aug 13 23:49:13 2012
@@ -503,7 +503,8 @@ public class HopCount extends org.apache
         }
         for (int i = 0; i < rval.length; i++)
         {
-          if (changeMap.get(targetDocumentIDHashes[i]).booleanValue())
+          Boolean x = changeMap.get(targetDocumentIDHashes[i]);
+          if (x != null && x.booleanValue())
             rval[i] = true;
         }