[Mulgara-svn] r96 - branches/xafix/src/jar/resolver/java/org/mulgara/resolver

andrae at mulgara.org andrae at mulgara.org
Fri Oct 6 03:53:04 UTC 2006


Author: andrae
Date: 2006-10-05 22:53:03 -0500 (Thu, 05 Oct 2006)
New Revision: 96

Added:
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java
Modified:
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
Log:
Created TransactionalAnswer to provide guarenteed wrapping of operations against SubqueryAnswer within a transactional context.

Modified DatabaseSession to return a wrapped SubqueryAnswer from doQuery().


Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-05 23:24:35 UTC (rev 95)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-06 03:53:03 UTC (rev 96)
@@ -19,6 +19,7 @@
  * Contributor(s): N/A.
  *   SymbolicTransformation refactor contributed by Netymon Pty Ltd on behalf of
  *   The Australian Commonwealth Government under contract 4500507038.
+ *   TransactionalAnswer refactor contributed by Netymon Pty Ltd
  *
  * [NOTE: The text of this Exhibit A may differ slightly from the text
  * of the notices in the Source Code files of the Original Code. You
@@ -821,8 +822,8 @@
 
       // Complete the numerical phase of resolution
       Tuples tuples = localQuery.resolve();
-      result = new SubqueryAnswer(databaseSession, systemResolver, tuples,
-          query.getVariableList());
+      result = new TransactionalAnswer(
+          new SubqueryAnswer(databaseSession, systemResolver, tuples, query.getVariableList()));
       tuples.close();
       localQuery.close();
     }

Added: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java	2006-10-05 23:24:35 UTC (rev 95)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/TransactionalAnswer.java	2006-10-06 03:53:03 UTC (rev 96)
@@ -0,0 +1,187 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.rosenlaw.com/OSL3.0.htm
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * This file is an original work developed by Netymon Pty Ltd
+ * (http://www.netymon.com, mailto:mail at netymon.com). Portions created
+ * by Netymon Pty Ltd are Copyright (c) 2006 Netymon Pty Ltd.
+ * All Rights Reserved.
+ */
+
+package org.mulgara.resolver;
+
+import org.mulgara.query.Answer;
+import org.mulgara.query.TuplesException;
+import org.mulgara.query.Variable;
+
+/**
+ * A transactional answer.  
+ * Wraps all calls to the enclosed answer object, ensuring all calls are made
+ * within an activated transactional context.  Also ensures that that context
+ * is deactivated upon returning from the outer-call.
+ *
+ * @created 2006-10-06
+ *
+ * @author <a href="mailto:andrae at netymon.com">Andrae Muys</a>
+ *
+ * @version $Revision: $
+ *
+ * @modified $Date: $
+ *
+ * @maintenanceAuthor $Author: $
+ *
+ * @company <A href="mailto:mail at netymon.com">Netymon Pty Ltd</A>
+ *
+ * @copyright &copy;2006 <a href="http://www.netymon.com/">Netymon Pty Ltd</a>
+ *
+ * @licence Open Software License v3.0</a>
+ */
+public class TransactionalAnswer implements Answer {
+
+  private Answer answer;
+
+  private Thread currentThread;
+
+  public TransactionalAnswer(Answer answer) {
+    this.answer = answer;
+  }
+
+  public Object getObject(int column) throws TuplesException {
+    pre();
+    try {
+      return answer.getObject(column);
+    } finally {
+      post();
+    }
+  }
+
+  public Object getObject(String columnName) throws TuplesException {
+    pre();
+    try {
+      return answer.getObject(columnName);
+    } finally {
+      post();
+    }
+  }
+
+  public void beforeFirst() throws TuplesException {
+    pre();
+    try {
+      answer.beforeFirst();
+    } finally {
+      post();
+    }
+  }
+
+  public void close() throws TuplesException {
+    pre();
+    try {
+      answer.close();
+    } finally {
+      post();
+    }
+  }
+
+  public int getColumnIndex(Variable column) throws TuplesException {
+    pre();
+    try {
+      return answer.getColumnIndex(column);
+    } finally {
+      post();
+    }
+  }
+
+  public int getNumberOfVariables() {
+    pre();
+    try {
+      return answer.getNumberOfVariables();
+    } finally {
+      post();
+    }
+  }
+
+  public Variable[] getVariables() {
+    pre();
+    try {
+      return answer.getVariables();
+    } finally {
+      post();
+    }
+  }
+
+  public boolean isUnconstrained() throws TuplesException {
+    pre();
+    try {
+      return answer.isUnconstrained();
+    } finally {
+      post();
+    }
+  }
+
+  public long getRowCount() throws TuplesException {
+    pre();
+    try {
+      return answer.getRowCount();
+    } finally {
+      post();
+    }
+  }
+
+  public long getRowUpperBound() throws TuplesException {
+    pre();
+    try {
+      return answer.getRowUpperBound();
+    } finally {
+      post();
+    }
+  }
+
+  public int getRowCardinality() throws TuplesException {
+    pre();
+    try {
+      return answer.getRowCardinality();
+    } finally {
+      post();
+    }
+  }
+
+  public boolean next() throws TuplesException {
+    pre();
+    try {
+      return answer.next();
+    } finally {
+      post();
+    }
+  }
+
+  public Object clone() {
+    try {
+      TransactionalAnswer c = (TransactionalAnswer)super.clone();
+      c.answer = (Answer)this.answer.clone();
+
+      return c;
+    } catch (CloneNotSupportedException ec) {
+      throw new IllegalStateException("Clone failed on Cloneable");
+    }
+  }
+
+  public void pre() {
+    // TM.obtainTransaction();
+    if (this.currentThread == null) {
+      this.currentThread = Thread.currentThread();
+    } else if (!Thread.currentThread().equals(this.currentThread)) {
+      throw new IllegalStateException("Concurrent access to TransactionalAnswer forbidded");
+    }
+  }
+
+  public void post() {
+    // TM.releaseTransaction();
+  }
+}




More information about the Mulgara-svn mailing list