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

andrae at mulgara.org andrae at mulgara.org
Wed Oct 25 22:35:59 UTC 2006


Author: andrae
Date: 2006-10-25 17:35:58 -0500 (Wed, 25 Oct 2006)
New Revision: 112

Modified:
   trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java
   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/LocalQuery.java
Log:
Piece by piece moving all the non-session related code out of DatabaseSession.
Being careful this time to provide sufficient scaffolding that it continues to
compile, run, and pass the tests.

The ultimate goal is visible in the xafix branch - DatabaseSession should be
involved strictly in handling the Session interface.

Also as operations will be independent, we need OperationContext to become more
independent of DatabaseSession so that multiple contexts can safely co-exist.
Again see xafix for specifics.



Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java	2006-10-25 08:19:20 UTC (rev 111)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java	2006-10-25 22:35:58 UTC (rev 112)
@@ -109,7 +109,7 @@
    * @throws TuplesException  if there's trouble reading <var>tuples</var>
    */
   AppendAggregateTuples(ResolverSession session,
-      DatabaseSession databaseSession, Tuples tuples,
+      DatabaseOperationContext context, Tuples tuples,
       List variableList) throws TuplesException {
     if (logger.isDebugEnabled()) {
       logger.debug("Generating variable list for " + tuples + " and " +
@@ -165,7 +165,7 @@
 
         try {
           Query query = ((Count) element).getQuery();
-          localQueryList.add(new LocalQuery(query, session, databaseSession));
+          localQueryList.add(new LocalQuery(query, session, context));
         }
         catch (LocalizeException e) {
           throw new TuplesException(

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2006-10-25 08:19:20 UTC (rev 111)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2006-10-25 22:35:58 UTC (rev 112)
@@ -66,7 +66,10 @@
 import org.mulgara.resolver.spi.SymbolicTransformationContext;
 import org.mulgara.resolver.spi.SystemResolver;
 import org.mulgara.resolver.view.ViewMarker;
+import org.mulgara.resolver.view.SessionView;
 import org.mulgara.store.nodepool.NodePool;
+import org.mulgara.store.tuples.Tuples;
+import org.mulgara.store.tuples.TuplesOperations;
 
 /**
  * Services provided by {@link DatabaseSession} to invocations of the
@@ -81,7 +84,8 @@
  *   Technology, Inc</a>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-class DatabaseOperationContext implements OperationContext, SymbolicTransformationContext
+class DatabaseOperationContext implements OperationContext, SessionView,
+AnswerDatabaseSession, SymbolicTransformationContext
 {
   /**
    * Logger.
@@ -129,6 +133,7 @@
   private final URI                temporaryModelTypeURI;
   private final ResolverFactory    temporaryResolverFactory;
   private final TransactionManager transactionManager;
+  private final Set                outstandingAnswers;
 
   //
   // Constructor
@@ -148,7 +153,8 @@
                            List               securityAdapterList,
                            URI                temporaryModelTypeURI,
                            ResolverFactory    temporaryResolverFactory,
-                           TransactionManager transactionManager)
+                           TransactionManager transactionManager,
+                           Set                outstandingAnswers)
   {
     assert cachedModelSet             != null;
     assert cachedResolverFactorySet   != null;
@@ -176,6 +182,9 @@
     this.temporaryModelTypeURI      = temporaryModelTypeURI;
     this.temporaryResolverFactory   = temporaryResolverFactory;
     this.transactionManager         = transactionManager;
+    // Note this is only temporary - we will be eliminating outstandingAnswers
+    // before the end of the transaction fix.
+    this.outstandingAnswers         = outstandingAnswers;
   }
 
   //
@@ -329,7 +338,7 @@
       //        (specifically intervals), and distributed queries
       //        (specificially appended joins).
       if (resolver instanceof ViewMarker) {
-        ((ViewMarker) resolver).setSession(databaseSession);
+        ((ViewMarker) resolver).setSession(this);
       }
     }
     catch (ResolverFactoryException e) {
@@ -617,4 +626,260 @@
     }
   }
 
+  /**
+   * Resolve a localized constraint into the tuples which satisfy it.
+   *
+   * This method must be called within a transactional context.
+   *
+   * @deprecated Will be made package-scope as soon as the View kludge is resolved.
+   * @param constraint  a localized constraint
+   * @return the tuples satisfying the <var>constraint</var>
+   * @throws IllegalArgumentException if <var>constraint</var> is
+   *   <code>null</code>
+   * @throws QueryException if the <var>constraint</var> can't be resolved
+   */
+  public Tuples resolve(Constraint constraint) throws QueryException {
+    if (logger.isDebugEnabled()) {
+      logger.debug("Resolving " + constraint);
+    }
+
+    // Validate "constraint" parameter
+    if (constraint == null) {
+      throw new IllegalArgumentException("Null \"constraint\" parameter");
+    }
+
+    SystemResolver systemResolver = databaseSession.getSystemResolver();
+
+    ConstraintElement modelElem = constraint.getModel();
+    if (modelElem instanceof Variable) {
+      return resolveVariableModel(constraint);
+    } else if (modelElem instanceof LocalNode) {
+      long model = ((LocalNode) modelElem).getValue();
+      long realModel = getCanonicalModel(model);
+
+      // Make sure security adapters are satisfied
+      for (Iterator i = securityAdapterList.iterator(); i.hasNext();) {
+        SecurityAdapter securityAdapter = (SecurityAdapter) i.next();
+
+        // Lie to the user
+        if (!securityAdapter.canSeeModel(realModel, systemResolver)) {
+          try {
+            throw new QueryException(
+              "No such model " + systemResolver.globalize(realModel));
+          } catch (GlobalizeException e) {
+            logger.warn("Unable to globalize model " + realModel);
+            throw new QueryException("No such model");
+          }
+        }
+      }
+
+      for (Iterator i = securityAdapterList.iterator(); i.hasNext();) {
+        SecurityAdapter securityAdapter = (SecurityAdapter) i.next();
+
+        // Tell a different lie to the user
+        if (!securityAdapter.canResolve(realModel, systemResolver)) {
+          return TuplesOperations.empty();
+        }
+      }
+
+      // if the model was changed then update the constraint
+      if (model != realModel) {
+        constraint = ConstraintOperations.rewriteConstraintModel(new LocalNode(realModel), constraint);
+      }
+
+      // Evaluate the constraint
+      Tuples result = obtainResolver(
+          findModelResolverFactory(realModel), systemResolver).resolve(constraint);
+      assert result != null;
+
+      return result;
+    } else {
+      throw new QueryException("Non-localized model in resolve: " + modelElem);
+    }
+  }
+
+  /**
+  * Resolve a {@link Constraint} in the case where the model isn't fixed.
+  *
+  * This is mostly relevant in the case where the <code>in</code> clause takes
+  * a variable parameter.  It's tricky to resolve because external models may
+  * be accessible to the system, but aren't known to it unless they're named.
+  * The policy we take is to only consider internal models.
+  *
+  * @param constraint  a constraint with a {@link Variable}-valued model
+  *   element, never <code>null</code>
+  * @return the solutions to the <var>constraint</var> occurring in all
+  *   internal models, never <code>null</code>
+  * @throws QueryException if the solution can't be evaluated
+  */
+  private Tuples resolveVariableModel(Constraint constraint)
+    throws QueryException
+  {
+    assert constraint != null;
+    assert constraint.getElement(3) instanceof Variable;
+
+    SystemResolver systemResolver = databaseSession.getSystemResolver();
+
+    Tuples tuples = TuplesOperations.empty();
+
+    // This is the alternate code we'd use if we were to consult external
+    // models as well as internal models during the resolution of variable IN
+    // clauses:
+    //
+    //Iterator i = resolverFactoryList.iterator();
+
+    Iterator i = internalResolverFactoryMap.values().iterator();
+    while (i.hasNext()) {
+      ResolverFactory resolverFactory = (ResolverFactory) i.next();
+      assert resolverFactory != null;
+
+      // Resolve the constraint
+      Resolver resolver = obtainResolver(resolverFactory, systemResolver);
+      if (logger.isDebugEnabled()) {
+        logger.debug("Resolving " + constraint + " against " + resolver);
+      }
+      Resolution resolution = resolver.resolve(constraint);
+      assert resolution != null;
+
+      try {
+        // If this is a complete resolution of the constraint, we won't have to
+        // consider any of the other resolvers
+        if (resolution.isComplete()) {
+          if (logger.isDebugEnabled()) {
+            logger.debug("Returning complete resolution from " + resolver);
+          }
+          tuples.close();
+
+          return resolution;
+        } else {
+          // Append the resolution to the overall solutions
+          if (logger.isDebugEnabled()) {
+            logger.debug("Appending " + resolver);
+          }
+          Tuples oldTuples = tuples;
+          tuples = TuplesOperations.append(tuples, resolution);
+          oldTuples.close();
+        }
+      } catch (TuplesException e) {
+        throw new QueryException("Unable to resolve " + constraint, e);
+      }
+    }
+
+    if (logger.isDebugEnabled()) {
+      logger.debug("Resolved " + constraint + " to " +
+          TuplesOperations.formatTuplesTree(tuples));
+    }
+
+    return tuples;
+  }
+
+  public Answer innerQuery(Query query) throws QueryException {
+    // Validate "query" parameter
+    if (query == null) {
+      throw new IllegalArgumentException("Null \"query\" parameter");
+    }
+
+    if (logger.isInfoEnabled()) {
+      logger.info("Query: " + query);
+    }
+
+    boolean resumed = databaseSession.ensureTransactionResumed();
+    SystemResolver systemResolver = databaseSession.getSystemResolver();
+
+    Answer result = null;
+    try {
+      result = DatabaseSession.doQuery(databaseSession, systemResolver, query);
+    } catch (Throwable th) {
+      try {
+        logger.warn("Inner Query failed", th);
+        databaseSession.rollbackTransactionalBlock(th);
+      } finally {
+        databaseSession.endPreviousQueryTransaction();
+        logger.error("Inner Query should have thrown exception", th);
+        throw new IllegalStateException(
+            "Inner Query should have thrown exception");
+      }
+    }
+
+    try {
+      if (resumed) {
+        databaseSession.suspendTransactionalBlock();
+      }
+
+      return result;
+    } catch (Throwable th) {
+      databaseSession.endPreviousQueryTransaction();
+      logger.error("Failed to suspend Transaction", th);
+      throw new QueryException("Failed to suspend Transaction");
+    }
+  }
+
+  public void registerAnswer(SubqueryAnswer answer) {
+    if (logger.isDebugEnabled()) {
+      logger.debug("registering Answer: " + System.identityHashCode(answer));
+    }
+    outstandingAnswers.add(answer);
+  }
+
+  public void deregisterAnswer(SubqueryAnswer answer) throws QueryException {
+    if (logger.isDebugEnabled()) {
+      logger.debug("deregistering Answer: " + System.identityHashCode(answer));
+    }
+
+    if (!outstandingAnswers.contains(answer)) {
+      logger.info("Stale answer being closed");
+    } else {
+      outstandingAnswers.remove(answer);
+      if (databaseSession.autoCommit && outstandingAnswers.isEmpty()) {
+        if (databaseSession.transaction != null) {
+          databaseSession.resumeTransactionalBlock();
+        }
+        databaseSession.endTransactionalBlock("Could not commit query");
+      }
+    }
+  }
+
+  Tuples innerCount(LocalQuery localQuery) throws QueryException {
+    // Validate "query" parameter
+    if (localQuery == null) {
+      throw new IllegalArgumentException("Null \"query\" parameter");
+    }
+
+    if (logger.isInfoEnabled()) {
+      logger.info("Inner Count: " + localQuery);
+    }
+
+    boolean resumed = databaseSession.ensureTransactionResumed();
+    SystemResolver systemResolver = databaseSession.getSystemResolver();
+
+    Tuples result = null;
+    try {
+      LocalQuery lq = (LocalQuery)localQuery.clone();
+      DatabaseSession.transform(databaseSession, lq);
+      result = lq.resolve();
+      lq.close();
+    } catch (Throwable th) {
+      try {
+        logger.warn("Inner Query failed", th);
+        databaseSession.rollbackTransactionalBlock(th);
+      } finally {
+        databaseSession.endPreviousQueryTransaction();
+        logger.error("Inner Query should have thrown exception", th);
+        throw new IllegalStateException(
+            "Inner Query should have thrown exception");
+      }
+    }
+
+    try {
+      if (resumed) {
+        databaseSession.suspendTransactionalBlock();
+      }
+
+      return result;
+    } catch (Throwable th) {
+      databaseSession.endPreviousQueryTransaction();
+      logger.error("Failed to suspend Transaction", th);
+      throw new QueryException("Failed to suspend Transaction");
+    }
+  }
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-25 08:19:20 UTC (rev 111)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-25 22:35:58 UTC (rev 112)
@@ -54,7 +54,6 @@
 import org.mulgara.query.rdf.*;
 import org.mulgara.resolver.spi.*;
 import org.mulgara.resolver.spi.ResolverFactoryException;
-import org.mulgara.resolver.view.SessionView;
 import org.mulgara.rules.*;
 import org.mulgara.server.Session;
 import org.mulgara.store.nodepool.NodePool;
@@ -79,7 +78,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-class DatabaseSession implements Session, LocalSession, SessionView, AnswerDatabaseSession {
+class DatabaseSession implements Session, LocalSession {
   public static final boolean ASSERT_STATEMENTS = true;
   public static final boolean DENY_STATEMENTS = false;
 
@@ -162,7 +161,7 @@
   private final TransactionManager transactionManager;
 
   /** Session transaction */
-  private Transaction transaction;
+  Transaction transaction;
 
   /** The name of the rule loader to use */
   private String ruleLoaderClassName;
@@ -190,7 +189,7 @@
    * This defaults to <code>true</code> until modified by the
    * {@link #setAutoCommit} method.
    */
-  private boolean autoCommit = true;
+  boolean autoCommit = true;
   private boolean inFailedTransaction = false;
 
   /**
@@ -337,7 +336,8 @@
                                         securityAdapterList,
                                         temporaryModelTypeURI,
                                         temporaryResolverFactory,
-                                        transactionManager
+                                        transactionManager,
+                                        outstandingAnswers
                                       );
 
     if (logger.isDebugEnabled()) {
@@ -662,103 +662,6 @@
     return queryOperation.getAnswer();
   }
 
-  public Answer innerQuery(Query query) throws QueryException {
-    // Validate "query" parameter
-    if (query == null) {
-      throw new IllegalArgumentException("Null \"query\" parameter");
-    }
-
-    if (logger.isInfoEnabled()) {
-      logger.info("Query: " + query);
-    }
-
-    boolean resumed;
-
-    if (this.transaction != null) {
-      resumeTransactionalBlock();
-      resumed = true;
-    } else {
-      resumed = false;
-    }
-
-    Answer result = null;
-    try {
-      result = doQuery(this, systemResolver, query);
-    } catch (Throwable th) {
-      try {
-        logger.warn("Inner Query failed", th);
-        rollbackTransactionalBlock(th);
-      } finally {
-        endPreviousQueryTransaction();
-        logger.error("Inner Query should have thrown exception", th);
-        throw new IllegalStateException(
-            "Inner Query should have thrown exception");
-      }
-    }
-
-    try {
-      if (resumed) {
-        suspendTransactionalBlock();
-      }
-
-      return result;
-    } catch (Throwable th) {
-      endPreviousQueryTransaction();
-      logger.error("Failed to suspend Transaction", th);
-      throw new QueryException("Failed to suspend Transaction");
-    }
-  }
-
-  Tuples innerCount(LocalQuery localQuery) throws QueryException {
-    // Validate "query" parameter
-    if (localQuery == null) {
-      throw new IllegalArgumentException("Null \"query\" parameter");
-    }
-
-    if (logger.isInfoEnabled()) {
-      logger.info("Inner Count: " + localQuery);
-    }
-
-    boolean resumed;
-
-    if (this.transaction != null) {
-      resumeTransactionalBlock();
-      resumed = true;
-    } else {
-      resumed = false;
-    }
-
-    Tuples result = null;
-    try {
-      LocalQuery lq = (LocalQuery)localQuery.clone();
-      transform(this, lq);
-      result = lq.resolve();
-      lq.close();
-    } catch (Throwable th) {
-      try {
-        logger.warn("Inner Query failed", th);
-        rollbackTransactionalBlock(th);
-      } finally {
-        endPreviousQueryTransaction();
-        logger.error("Inner Query should have thrown exception", th);
-        throw new IllegalStateException(
-            "Inner Query should have thrown exception");
-      }
-    }
-
-    try {
-      if (resumed) {
-        suspendTransactionalBlock();
-      }
-
-      return result;
-    } catch (Throwable th) {
-      endPreviousQueryTransaction();
-      logger.error("Failed to suspend Transaction", th);
-      throw new QueryException("Failed to suspend Transaction");
-    }
-  }
-
   static Answer doQuery(DatabaseSession databaseSession,
                         SystemResolver  systemResolver,
                         Query           query) throws Exception
@@ -766,13 +669,13 @@
     Answer result;
 
     LocalQuery localQuery =
-      new LocalQuery(query, systemResolver, databaseSession);
+      new LocalQuery(query, systemResolver, databaseSession.operationContext);
 
     transform(databaseSession, localQuery);
 
     // Complete the numerical phase of resolution
     Tuples tuples = localQuery.resolve();
-    result = new SubqueryAnswer(databaseSession, systemResolver, tuples,
+    result = new SubqueryAnswer(databaseSession.operationContext, systemResolver, tuples,
         query.getVariableList());
     tuples.close();
     localQuery.close();
@@ -789,7 +692,7 @@
    * Perform in-place transformation of localQuery.
    * Note: we really want to convert this to a functional form eventually.
    */
-  private static void transform(DatabaseSession databaseSession, LocalQuery localQuery) throws Exception {
+  static void transform(DatabaseSession databaseSession, LocalQuery localQuery) throws Exception {
     // Start with the symbolic phase of resolution
     LocalQuery.MutableLocalQueryImpl mutableLocalQueryImpl =
       localQuery.new MutableLocalQueryImpl();
@@ -817,7 +720,7 @@
     mutableLocalQueryImpl.close();
   }
 
-  private void endPreviousQueryTransaction() throws QueryException {
+  void endPreviousQueryTransaction() throws QueryException {
     logger.debug("Clearing previous transaction");
 
     // Save the exception.
@@ -828,7 +731,7 @@
     while (i.hasNext()) {
       try {
         SubqueryAnswer s = (SubqueryAnswer) i.next();
-        deregisterAnswer(s);
+        operationContext.deregisterAnswer(s);
         //Do not close tuples - for Jena and JRDF.
         //s.close();
       } catch (Throwable th) {
@@ -862,31 +765,6 @@
     }
   }
 
-  public void registerAnswer(SubqueryAnswer answer) {
-    if (logger.isDebugEnabled()) {
-      logger.debug("registering Answer: " + System.identityHashCode(answer));
-    }
-    outstandingAnswers.add(answer);
-  }
-
-  public void deregisterAnswer(SubqueryAnswer answer) throws QueryException {
-    if (logger.isDebugEnabled()) {
-      logger.debug("deregistering Answer: " + System.identityHashCode(answer));
-    }
-
-    if (!outstandingAnswers.contains(answer)) {
-      logger.info("Stale answer being closed");
-    } else {
-      outstandingAnswers.remove(answer);
-      if (autoCommit && outstandingAnswers.isEmpty()) {
-        if (transaction != null) {
-          resumeTransactionalBlock();
-        }
-        endTransactionalBlock("Could not commit query");
-      }
-    }
-  }
-
   public List query(List queryList) throws QueryException {
 
     if (logger.isInfoEnabled()) {
@@ -1102,158 +980,6 @@
   }
 
   //
-  // Local query methods
-  //
-
-  /**
-   * Resolve a localized constraint into the tuples which satisfy it.
-   *
-   * This method must be called within a transactional context.
-   *
-   * @deprecated Will be made package-scope as soon as the View kludge is resolved.
-   * @param constraint  a localized constraint
-   * @return the tuples satisfying the <var>constraint</var>
-   * @throws IllegalArgumentException if <var>constraint</var> is
-   *   <code>null</code>
-   * @throws QueryException if the <var>constraint</var> can't be resolved
-   */
-  public Tuples resolve(Constraint constraint) throws QueryException {
-    if (logger.isDebugEnabled()) {
-      logger.debug("Resolving " + constraint);
-    }
-
-    // Validate "constraint" parameter
-    if (constraint == null) {
-      throw new IllegalArgumentException("Null \"constraint\" parameter");
-    }
-
-    ConstraintElement modelElem = constraint.getModel();
-    if (modelElem instanceof Variable) {
-      return resolveVariableModel(constraint);
-    } else if (modelElem instanceof LocalNode) {
-      long model = ((LocalNode) modelElem).getValue();
-      long realModel = operationContext.getCanonicalModel(model);
-
-      // Make sure security adapters are satisfied
-      for (Iterator i = securityAdapterList.iterator(); i.hasNext();) {
-        SecurityAdapter securityAdapter = (SecurityAdapter) i.next();
-
-        // Lie to the user
-        if (!securityAdapter.canSeeModel(realModel, systemResolver))
-        {
-          try {
-            throw new QueryException(
-              "No such model " + systemResolver.globalize(realModel)
-            );
-          }
-          catch (GlobalizeException e) {
-            logger.warn("Unable to globalize model " + realModel);
-            throw new QueryException("No such model");
-          }
-        }
-      }
-      for (Iterator i = securityAdapterList.iterator(); i.hasNext();) {
-        SecurityAdapter securityAdapter = (SecurityAdapter) i.next();
-
-        // Tell a different lie to the user
-        if (!securityAdapter.canResolve(realModel, systemResolver))
-        {
-          return TuplesOperations.empty();
-        }
-      }
-
-      // if the model was changed then update the constraint
-      if (model != realModel) {
-        constraint = ConstraintOperations.rewriteConstraintModel(new LocalNode(realModel), constraint);
-      }
-
-      // Evaluate the constraint
-      Tuples result = operationContext.obtainResolver(
-                        operationContext.findModelResolverFactory(realModel),
-                        systemResolver
-                      ).resolve(constraint);
-      assert result != null;
-
-      return result;
-    } else {
-      throw new QueryException("Non-localized model in resolve: " + modelElem);
-    }
-  }
-
-  /**
-  * Resolve a {@link Constraint} in the case where the model isn't fixed.
-  *
-  * This is mostly relevant in the case where the <code>in</code> clause takes
-  * a variable parameter.  It's tricky to resolve because external models may
-  * be accessible to the system, but aren't known to it unless they're named.
-  * The policy we take is to only consider internal models.
-  *
-  * @param constraint  a constraint with a {@link Variable}-valued model
-  *   element, never <code>null</code>
-  * @return the solutions to the <var>constraint</var> occurring in all
-  *   internal models, never <code>null</code>
-  * @throws QueryException if the solution can't be evaluated
-  */
-  private Tuples resolveVariableModel(Constraint constraint)
-    throws QueryException
-  {
-    assert constraint != null;
-    assert constraint.getElement(3) instanceof Variable;
-
-    Tuples tuples = TuplesOperations.empty();
-
-    // This is the alternate code we'd use if we were to consult external
-    // models as well as internal models during the resolution of variable IN
-    // clauses:
-    //
-    //Iterator i = resolverFactoryList.iterator();
-
-    Iterator i = internalResolverFactoryMap.values().iterator();
-    while (i.hasNext()) {
-      ResolverFactory resolverFactory = (ResolverFactory) i.next();
-      assert resolverFactory != null;
-
-      // Resolve the constraint
-      Resolver resolver = operationContext.obtainResolver(resolverFactory, systemResolver);
-      if (logger.isDebugEnabled()) {
-        logger.debug("Resolving " + constraint + " against " + resolver);
-      }
-      Resolution resolution = resolver.resolve(constraint);
-      assert resolution != null;
-
-      try {
-        // If this is a complete resolution of the constraint, we won't have to
-        // consider any of the other resolvers
-        if (resolution.isComplete()) {
-          if (logger.isDebugEnabled()) {
-            logger.debug("Returning complete resolution from " + resolver);
-          }
-          tuples.close();
-
-          return resolution;
-        } else {
-          // Append the resolution to the overall solutions
-          if (logger.isDebugEnabled()) {
-            logger.debug("Appending " + resolver);
-          }
-          Tuples oldTuples = tuples;
-          tuples = TuplesOperations.append(tuples, resolution);
-          oldTuples.close();
-        }
-      } catch (TuplesException e) {
-        throw new QueryException("Unable to resolve " + constraint, e);
-      }
-    }
-
-    if (logger.isDebugEnabled()) {
-      logger.debug("Resolved " + constraint + " to " +
-          TuplesOperations.formatTuplesTree(tuples));
-    }
-
-    return tuples;
-  }
-
-  //
   // Internal methods
   //
 
@@ -1408,7 +1134,7 @@
    * @throws QueryException if a transaction needed to be committed and
    *   couldn't be
    */
-  private void endTransactionalBlock(String failureMessage) throws QueryException {
+  void endTransactionalBlock(String failureMessage) throws QueryException {
     if (logger.isInfoEnabled()) {
       logger.info(
         "End Transactional Block autocommit=" + autoCommit +
@@ -1739,4 +1465,15 @@
   boolean isWriting() {
     return writing;
   }
+
+  boolean ensureTransactionResumed() throws QueryException {
+    if (this.transaction != null) {
+      resumeTransactionalBlock();
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+
 }

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java	2006-10-25 08:19:20 UTC (rev 111)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java	2006-10-25 22:35:58 UTC (rev 112)
@@ -78,7 +78,7 @@
   private final ResolverSession resolverSession;
 
   /** The session this query is local to.  */
-  private final DatabaseSession databaseSession;
+  private final DatabaseOperationContext context;
 
   /** The constraint expression. */
   private ConstraintExpression constraintExpression;
@@ -114,7 +114,7 @@
    *   <var>resolverSession</var> are <code>null</code>
    * @throws LocalizeException if the <var>query</var> can't be localized
    */
-  LocalQuery(Query query, ResolverSession resolverSession, DatabaseSession databaseSession)
+  LocalQuery(Query query, ResolverSession resolverSession, DatabaseOperationContext context)
     throws LocalizeException
   {
     if (logger.isDebugEnabled()) {
@@ -134,7 +134,7 @@
     // Initialize fields
     this.constraintExpression = query.getConstraintExpression();
     this.resolverSession = resolverSession;
-    this.databaseSession = databaseSession;
+    this.context = context;
     this.modelExpression = (ModelExpression)query.getModelExpression().clone();
     this.orderList = query.getOrderList();
     this.offset = query.getOffset();
@@ -152,7 +152,7 @@
   LocalQuery(LocalQuery localQuery, ConstraintExpression constraintExpression) {
     this.constraintExpression = constraintExpression;
     this.resolverSession = localQuery.resolverSession;
-    this.databaseSession = localQuery.databaseSession;
+    this.context = localQuery.context;
     this.modelExpression = localQuery.modelExpression;
     this.orderList = localQuery.orderList;
     this.offset = localQuery.offset;
@@ -190,7 +190,7 @@
   Tuples resolve(Map outerBindings) throws QueryException
   {
     try {
-      return databaseSession.innerCount(new LocalQuery(this,
+      return context.innerCount(new LocalQuery(this,
           new ConstraintConjunction(ConstraintOperations.bindVariables(outerBindings, constraintExpression),
                                     constrainBindings(outerBindings))));
     } catch (LocalizeException el) {
@@ -224,7 +224,7 @@
 
 
   Tuples resolve(Constraint constraint) throws QueryException {
-    return databaseSession.resolve(constraint);
+    return context.resolve(constraint);
   }
 
 
@@ -315,7 +315,7 @@
   {
     if (result.getRowCardinality() != Tuples.ZERO) {
       Tuples tmp = result;
-      result = new AppendAggregateTuples(resolverSession, databaseSession, result, filterSubqueries(select));
+      result = new AppendAggregateTuples(resolverSession, context, result, filterSubqueries(select));
       tmp.close();
     }
 




More information about the Mulgara-svn mailing list