[Mulgara-svn] r117 - trunk/src/jar/resolver/java/org/mulgara/resolver

pag at mulgara.org pag at mulgara.org
Sun Oct 29 21:39:53 UTC 2006


Author: pag
Date: 2006-10-29 15:39:53 -0600 (Sun, 29 Oct 2006)
New Revision: 117

Modified:
   trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
   trunk/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java
Log:
Winding back revision 115 due to an incorrect branch being merged into the trunk

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2006-10-28 22:24:04 UTC (rev 116)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2006-10-29 21:39:53 UTC (rev 117)
@@ -143,7 +143,6 @@
   /** Symbolic transformations this instance should apply. */
   private final List symbolicTransformationList;
 
-  private WeakHashMap answers;  // Used as a set, all values are null.  Java doesn't provide a WeakHashSet.
   //
   // Constructor
   //
@@ -196,7 +195,6 @@
     // before the end of the transaction fix.
     this.outstandingAnswers         = outstandingAnswers;
     this.symbolicTransformationList = symbolicTransformationList;
-    this.answers                    = new WeakHashMap();
   }
 
   //
@@ -943,10 +941,7 @@
 
     // Complete the numerical phase of resolution
     Tuples tuples = localQuery.resolve();
-    MulgaraTransaction xa = new MulgaraTransaction(null, this);
-    result = new TransactionalAnswer(new MulgaraTransaction(null, this), new SubqueryAnswer(this, systemResolver, tuples, query.getVariableList()));
-    xa.tempDeactivate();  // FIXME: Only necessary while we introduce the manager.
-    answers.put(result, null);
+    result = new SubqueryAnswer(this, systemResolver, tuples, query.getVariableList());
     tuples.close();
     localQuery.close();
 
@@ -989,14 +984,4 @@
     mutableLocalQueryImpl.close();
   }
 
-  void close() throws QueryException {
-    try {
-      Iterator i = answers.keySet().iterator();
-      while (i.hasNext()) {
-        ((TransactionalAnswer)i.next()).sessionClose();
-      }
-    } catch (TuplesException et) {
-      throw new QueryException("Error force-closing answers", et);
-    }
-  }
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-28 22:24:04 UTC (rev 116)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-29 21:39:53 UTC (rev 117)
@@ -204,8 +204,6 @@
    */
   private ContentHandlerManager contentHandlers;
 
-  private MulgaraTransactionManager manager;
-
   //
   // Constructor
   //
@@ -338,8 +336,6 @@
                                         outstandingAnswers,
                                         symbolicTransformationList
                                       );
-    // FIXME: This will eventually be passed as a parameter from Database.
-    this.manager                    = new MulgaraTransactionManager(null);
 
     if (logger.isDebugEnabled()) {
       logger.debug("Constructed DatabaseSession");
@@ -756,31 +752,27 @@
 
   public void close() throws QueryException {
     logger.info("Closing session");
-    try {
-      if (!autoCommit) {
-        logger.warn("Closing session while holding write-lock");
+    if (!autoCommit) {
+      logger.warn("Closing session while holding write-lock");
 
-        try {
-          resumeTransactionalBlock();
-        } catch (Throwable th) {
-          releaseWriteLock();
-          throw new QueryException("Error while resuming transaction in close", th);
-        }
+      try {
+        resumeTransactionalBlock();
+      } catch (Throwable th) {
+        releaseWriteLock();
+        throw new QueryException("Error while resuming transaction in close", th);
+      }
 
-        try {
-          rollbackTransactionalBlock(
-              new QueryException("Attempt to close session whilst in transaction"));
-        } finally {
-          endTransactionalBlock("Failed to release write-lock in close");
-        }
-      } else {
-        if (this.transaction != null) {
-          resumeTransactionalBlock();
-          endPreviousQueryTransaction();
-        }
+      try {
+        rollbackTransactionalBlock(
+            new QueryException("Attempt to close session whilst in transaction"));
+      } finally {
+        endTransactionalBlock("Failed to release write-lock in close");
       }
-    } finally {
-      operationContext.close();
+    } else {
+      if (this.transaction != null) {
+        resumeTransactionalBlock();
+        endPreviousQueryTransaction();
+      }
     }
   }
 
@@ -1401,7 +1393,4 @@
     }
   }
 
-  OperationContext getOperationContext() {
-    return operationContext;
-  }
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java	2006-10-28 22:24:04 UTC (rev 116)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransaction.java	2006-10-29 21:39:53 UTC (rev 117)
@@ -80,7 +80,6 @@
   private Throwable rollbackCause;
 
   public MulgaraTransaction(MulgaraTransactionManager manager, OperationContext context) {
-    report("Creating Transaction");
     this.manager = manager;
     this.context = context;
 
@@ -97,14 +96,12 @@
 
 //    FIXME: need this added to context. Allows context to cleanup caches at end of transaction.
 //    this.transaction.enlistResource(context.getXAResource());
-    report("Created Transaction");
   }
 
   // FIXME: Not yet certain I have the error handling right here.
   // Need to clarify semantics and ensure the error conditions are 
   // properly handled.
   private synchronized void activate() throws MulgaraTransactionException {
-    report("Activating Transaction");
     if (currentThread == null) {
       currentThread = Thread.currentThread();
     } else if (!currentThread.equals(Thread.currentThread())) {
@@ -112,84 +109,57 @@
     }
 
     if (inuse == 0) {
-      report("Resuming transaction");
-//      try {
-//        manager.transactionResumed(this);
-//      } catch (Throwable th) {
-//        logger.warn("Error resuming transaction: ", th);
-//        failTransaction();
-//        throw new MulgaraTransactionException("Error resuming transaction", th);
-//      }
+      try {
+        manager.transactionResumed(this);
+      } catch (Throwable th) {
+        logger.warn("Error resuming transaction: ", th);
+        failTransaction();
+        throw new MulgaraTransactionException("Error resuming transaction", th);
+      }
     }
 
     inuse++;
-
-    report("Activated transaction");
   }
 
 
-  public synchronized void tempDeactivate() throws MulgaraTransactionException {
-    deactivate();
-  }
-
   // FIXME: Not yet certain I have the error handling right here.
   // Need to clarify semantics and ensure the error conditions are 
   // properly handled.
   private synchronized void deactivate() throws MulgaraTransactionException {
-    report("Deactivating transaction");
 
     inuse--;
 
     if (inuse < 0) {
-        throw new MulgaraTransactionException("Mismatched activate/deactivate.  inuse < 0: " + inuse);
-//      throw implicitRollback(
-//          new MulgaraTransactionException("Mismatched activate/deactivate.  inuse < 0: " + inuse));
-    } else if (using < 0) {
-        throw new MulgaraTransactionException("Reference Failure.  using < 0: " + using);
+      throw implicitRollback(
+          new MulgaraTransactionException("Mismatched activate/deactivate.  inuse < 0: " + inuse));
     }
 
     if (inuse == 0) {
       if (using == 0) {
-        report("Completing Transaction");
         // END TRANSACTION HERE.  But commit might fail.
-//        manager.transactionComplete(this);
-          manager = null;
-          transaction = null;
+        manager.transactionComplete(this);
       } else {
-        report("Suspending Transaction");
         // What happens if suspend fails?
         // Rollback and terminate transaction.
         // JTA isn't entirely unambiguous as to the long-term stability of the original
         // transaction object - can suspend return a new object?
-//        this.transaction = manager.transactionSuspended(this);
+        this.transaction = manager.transactionSuspended(this);
       }
       currentThread = null;
     }
-    report("Deactivated Transaction");
   }
 
   // Do I want to check for currentThread here?  Do I want a seperate check() method to 
   // cover precondition checks against currentThread?
-  void reference() throws MulgaraTransactionException {
-    report("Referencing Transaction");
-    if (inuse < 1) {
-        throw new MulgaraTransactionException("Mismatched activate/deactivate.  inuse < 1: " + inuse);
-    } else if (using < 0) {
-        throw new MulgaraTransactionException("Reference Failure.  using < 0: " + using);
-    }
+  void reference() {
     using++;
-    report("Referenced Transaction");
   }
 
   void dereference() throws MulgaraTransactionException {
-    report("Dereferencing Transaction");
-    if (inuse < 1) {
-        throw new MulgaraTransactionException("Mismatched activate/deactivate.  inuse < 1: " + inuse);
-    } else if (using < 1) {
-        throw new MulgaraTransactionException("Reference Failure.  using < 1: " + using);
-    }
     using--;
-    report("Dereferenced Transaction");
+    if (using < 0) {
+      throw implicitRollback(new MulgaraTransactionException("ERROR: Transaction dereferenced more times than referenced!"));
+    }
   }
 
   void execute(Operation operation,
@@ -212,22 +182,15 @@
   /** Should rename this 'wrap' */
   AnswerOperationResult execute(AnswerOperation ao) throws TuplesException {
 //    FIXME: activate/deactivate won't work until we have MTMgr operational.
-    report("Executing Operation");
+//    activate();
     try {
-      activate();
-      try {
-        ao.execute();
-        return ao.getResult();
-      } catch (Throwable th) {
-        throw new TuplesException("Error accessing Answer", th);
-  //      throw implicitRollback(th);
-      } finally {
-        deactivate();
-      }
-    } catch (MulgaraTransactionException em) {
-      throw new TuplesException("Transaction error", em);
+      ao.execute();
+      return ao.getResult();
+    } catch (Throwable th) {
+      throw new TuplesException("Error accessing Answer", th);
+//      throw implicitRollback(th);
     } finally {
-      report("Executed Operation");
+//      deactivate();
     }
   }
 
@@ -267,7 +230,7 @@
     } catch (Exception e) {
       throw new MulgaraTransactionException("Error while trying to commit", e);
     } finally {
-//      manager.transactionComplete(this);
+      manager.transactionComplete(this);
     }
   }
 
@@ -291,21 +254,4 @@
   protected Transaction getTransaction() {
     return transaction;
   }
-
-  protected void finalize() {
-    report("GC-finalize");
-    if (inuse != 0 || using != 0) {
-      logger.error("Referernce counting error in transaction, inuse=" + inuse + ", using=" + using);
-    }
-    if (manager != null || transaction != null) {
-      logger.error("Transaction not terminated properly");
-    }
-  }
-
-  private void report(String desc) {
-    if (logger.isInfoEnabled()) {
-      logger.info(desc + ": " + System.identityHashCode(this) +
-          ", inuse=" + inuse + ", using=" + using);
-    }
-  }
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java	2006-10-28 22:24:04 UTC (rev 116)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/MulgaraTransactionManager.java	2006-10-29 21:39:53 UTC (rev 117)
@@ -108,7 +108,8 @@
     }
 
 //    FIXME: Need to finish 1-N DS-OC and provide this method - should really be newOperationContext.
-    return new MulgaraTransaction(this, session.getOperationContext());
+//    return new MulgaraTransaction(this, session.getOperationContext());
+    return new MulgaraTransaction(this, null);
   }
 
 
@@ -205,7 +206,7 @@
 
   public synchronized void closingSession(Session session) throws MulgaraTransactionException {
     // Check if we hold the write lock, if we do then rollback and throw exception.
-    // Regardless we need to close all associated Answer objects
+    // Otherwise - no-op.
   }
 
   public void finalizeTransaction() {
@@ -276,7 +277,6 @@
       throw new MulgaraTransactionException("Commit Failed", e);
     } finally {
       activeTransactions.remove(Thread.currentThread());
-//    Remove transaction from Session's list.
     }
   }
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java	2006-10-28 22:24:04 UTC (rev 116)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java	2006-10-29 21:39:53 UTC (rev 117)
@@ -17,10 +17,6 @@
 
 package org.mulgara.resolver;
 
-// Third party packages
-import org.apache.log4j.Logger;
-
-// Local packages
 import org.mulgara.query.Answer;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
@@ -49,26 +45,15 @@
  */
 
 public class TransactionalAnswer implements Answer {
-  /** Logger.  */
-  private static final Logger logger =
-    Logger.getLogger(MulgaraTransaction.class.getName());
 
   private Answer answer;
 
   private MulgaraTransaction transaction;
 
-  public TransactionalAnswer(MulgaraTransaction transaction, Answer answer) throws TuplesException {
-    try {
-      report("Creating Answer");
-
-      this.answer = answer;
-      this.transaction = transaction;
-      transaction.reference();
-
-      report("Created Answer");
-    } catch (MulgaraTransactionException em) {
-      throw new TuplesException("Failed to associate with transaction", em);
-    }
+  public TransactionalAnswer(MulgaraTransaction transaction, Answer answer) {
+    this.answer = answer;
+    this.transaction = transaction;
+    transaction.reference();
   }
 
   public Object getObject(final int column) throws TuplesException {
@@ -96,24 +81,16 @@
   }
 
   public void close() throws TuplesException {
-    report("Closing Answer");
-    try {
-      transaction.execute(new AnswerOperation() {
-          public void execute() throws TuplesException {
-            answer.close();
-            try {
-              transaction.dereference();
-            } catch (MulgaraTransactionException em) {
-              throw new TuplesException("Error dereferencing transaction", em);
-            }
+    transaction.execute(new AnswerOperation() {
+        public void execute() throws TuplesException {
+          answer.close();
+          try {
+            transaction.dereference();
+          } catch (MulgaraTransactionException em) {
+            throw new TuplesException("Error dereferencing transaction", em);
           }
-        });
-    } finally {
-      // !!FIXME: Note - We will need to add checks for null to all operations.
-      transaction = null;
-      answer = null;    // Note this permits the gc of the answer.
-      report("Closed Answer");
-    }
+        }
+      });
   }
 
   public int getColumnIndex(final Variable column) throws TuplesException {
@@ -197,29 +174,6 @@
       return c;
     } catch (CloneNotSupportedException ec) {
       throw new IllegalStateException("Clone failed on Cloneable");
-    } catch (MulgaraTransactionException em) {
-      throw new IllegalStateException("Failed to associate with transaction", em);
     }
   }
-
-  private void report(String desc) {
-    if (logger.isInfoEnabled()) {
-      logger.info(desc + ": " + System.identityHashCode(this) + ", xa=" + System.identityHashCode(transaction));
-    }
-  }
-
-  public void finalize() {
-    report("GC-finalizing");
-    if (transaction != null) {
-      logger.error("TransactionalAnswer not closed");
-    }
-  }
-
-
-  void sessionClose() throws TuplesException {
-    if (answer != null) {
-      report("Session forced close");
-      close();
-    }
-  }
 }




More information about the Mulgara-svn mailing list