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

andrae at mulgara.org andrae at mulgara.org
Mon Oct 16 07:27:31 UTC 2006


Author: andrae
Date: 2006-10-16 02:27:31 -0500 (Mon, 16 Oct 2006)
New Revision: 104

Modified:
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/QueryOperation.java
   branches/xafix/src/jar/resolver/java/org/mulgara/resolver/SubqueryAnswer.java
Log:
Moved all the operation related context into OperationContext.  This includes doQuery, doModify, and resolve.

These methods depend on the specific *phase* attached to a given operation.  As we wish this to be independent of the phase being used by the Session, it needed to move.

Better yet: DatabaseSession is > 1kloc!!! - AbstractDatabaseSession is finally no more!



Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java	2006-10-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/AppendAggregateTuples.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -109,7 +109,7 @@
    * @throws TuplesException  if there's trouble reading <var>tuples</var>
    */
   AppendAggregateTuples(ResolverSession session,
-      DatabaseSession databaseSession, Tuples tuples,
+      OperationContext operationContext, 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, operationContext));
         }
         catch (LocalizeException e) {
           throw new TuplesException(

Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2006-10-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -68,6 +68,9 @@
 import org.mulgara.resolver.view.ViewMarker;
 import org.mulgara.store.nodepool.NodePool;
 
+// !!FIXME: We need to consider how we partition OperationContext to seperate out the functions required
+//          by the various clients of this class.
+
 /**
  * Services provided by {@link DatabaseSession} to invocations of the
  * {@link Operation#execute} method.
@@ -598,4 +601,255 @@
     }
   }
 
+  //
+  // Local query methods
+  //
+
+  protected void doModify(// The SystemResolver should be in the context already - it isn't, but it should be.  SystemResolver systemResolver, URI modelURI,
+      Statements statements, boolean insert) throws Throwable {
+    long model = systemResolver.localize(new URIReferenceImpl(modelURI));
+    model = 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(model, systemResolver)) {
+        throw new QueryException("No such model " + modelURI);
+      }
+
+      // Tell the truth to the user
+      if (!securityAdapter.canModifyModel(model, systemResolver)) {
+        throw new QueryException("You aren't allowed to modify " + modelURI);
+      }
+    }
+
+    // Obtain a resolver for the destination model type
+    Resolver resolver = obtainResolver(findModelResolverFactory(model), systemResolver);
+    assert resolver != null;
+
+    if (logger.isDebugEnabled()) {
+      logger.debug("Modifying " + modelURI + " using " + resolver);
+    }
+
+    resolver.modifyModel(model, statements, insert);
+
+    if (logger.isDebugEnabled()) {
+      logger.debug("Modified " + modelURI);
+    }
+  }
+
+  public Answer innerQuery(Query query) throws QueryException {
+    return doQuery(systemResolver, query);
+  }
+
+  Tuples innerCount(LocalQuery localQuery) throws QueryException {
+    LocalQuery lq = (LocalQuery)localQuery.clone();
+    transform(this, lq);
+    Tuples result = lq.resolve();
+    lq.close();
+
+    return result;
+  }
+
+  Answer doQuery(SystemResolver  systemResolver, Query query) throws Exception
+  {
+    LocalQuery localQuery = new LocalQuery(query, systemResolver, this);
+
+    transform(localQuery);
+
+    Tuples tuples = localQuery.resolve();
+    Answer result = new TransactionalAnswer(
+        new SubqueryAnswer(this, systemResolver, tuples, query.getVariableList()));
+    tuples.close();
+    localQuery.close();
+
+    return result;
+  }
+
+
+  /**
+   *
+   * Perform in-place transformation of localQuery.
+   * Note: we really want to convert this to a functional form eventually.
+   */
+  private static void transform(LocalQuery localQuery) throws Exception {
+    // Start with the symbolic phase of resolution
+    LocalQuery.MutableLocalQueryImpl mutableLocalQueryImpl =
+      localQuery.new MutableLocalQueryImpl();
+    if (symbolicLogger.isDebugEnabled()) {
+      symbolicLogger.debug("Before transformation: " + mutableLocalQueryImpl);
+    }
+
+    Iterator i = symbolicTransformationList.iterator();
+    while (i.hasNext()) {
+      SymbolicTransformation symbolicTransformation =
+        (SymbolicTransformation) i.next();
+      assert symbolicTransformation != null;
+      symbolicTransformation.transform(this, mutableLocalQueryImpl);
+      if (mutableLocalQueryImpl.isModified()) {
+        // When a transformation succeeds, we rewind and start from the
+        // beginning of the symbolicTransformationList again
+        if (symbolicLogger.isDebugEnabled()) {
+          symbolicLogger.debug("Symbolic transformation: " +
+                               mutableLocalQueryImpl);
+        }
+        mutableLocalQueryImpl.close();
+        mutableLocalQueryImpl = localQuery.new MutableLocalQueryImpl();
+        i = symbolicTransformationList.iterator();
+      }
+    }
+    mutableLocalQueryImpl.close();
+  }
+
+  /**
+   * 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 = 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 = 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;
+  }
+
+
 }

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-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -135,8 +135,6 @@
 
   private final DatabaseMetadata metadata;
 
-  private final DatabaseOperationContext operationContext;
-
   /** Security adapters this instance should enforce. */
   private final List securityAdapterList;
 
@@ -285,19 +283,6 @@
 
     this.outstandingAnswers         = new HashSet();
     this.transaction                = null;
-    this.operationContext           = new DatabaseOperationContext(
-                                        cachedModelSet,
-                                        cachedResolverFactorySet,
-                                        changedCachedModelSet,
-                                        this,
-                                        externalResolverFactoryMap,
-                                        internalResolverFactoryMap,
-                                        metadata,
-                                        securityAdapterList,
-                                        temporaryModelTypeURI,
-                                        temporaryResolverFactory,
-                                        transactionManager
-                                      );
 
     if (logger.isDebugEnabled()) {
       logger.debug("Constructed DatabaseSession");
@@ -528,48 +513,10 @@
       logger.info("INSERT QUERY: " + query + " into " + modelURI);
     }
 
-    execute(new ModifyModelOperation(modelURI, query, insert, this),
+    execute(new ModifyModelOperation(modelURI, query, insert),
             "Unable to modify " + modelURI);
   }
 
-  protected void doModify(SystemResolver systemResolver, URI modelURI,
-      Statements statements, boolean insert) throws Throwable {
-    long model = systemResolver.localize(new URIReferenceImpl(modelURI));
-    model = 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(model, systemResolver)) {
-        throw new QueryException("No such model " + modelURI);
-      }
-
-      // Tell the truth to the user
-      if (!securityAdapter.canModifyModel(model, systemResolver)) {
-        throw new QueryException("You aren't allowed to modify " + modelURI);
-      }
-    }
-
-    // Obtain a resolver for the destination model type
-    Resolver resolver = operationContext.obtainResolver(
-                          operationContext.findModelResolverFactory(model),
-                          systemResolver
-                        );
-    assert resolver != null;
-
-    if (logger.isDebugEnabled()) {
-      logger.debug("Modifying " + modelURI + " using " + resolver);
-    }
-
-    resolver.modifyModel(model, statements, insert);
-
-    if (logger.isDebugEnabled()) {
-      logger.debug("Modified " + modelURI);
-    }
-  }
-
   public void login(URI securityDomain, String user, char[] password) {
     if (logger.isDebugEnabled()) {
       logger.debug("Login of " + user + " to " + securityDomain);
@@ -588,81 +535,16 @@
       logger.info("QUERY: " + query);
     }
 
-    return execute(new QueryOperation(query, this)).getAnswer();
+    return execute(new QueryOperation(query)).getAnswer();
   }
 
-  public Answer innerQuery(Query query) throws QueryException {
-    return doQuery(this, systemResolver, query);
-  }
-
-  Tuples innerCount(LocalQuery localQuery) throws QueryException {
-    LocalQuery lq = (LocalQuery)localQuery.clone();
-    transform(this, lq);
-    Tuples result = lq.resolve();
-    lq.close();
-
-    return result;
-  }
-
-  static Answer doQuery(DatabaseSession databaseSession,
-                        SystemResolver  systemResolver,
-                        Query           query) throws Exception
-  {
-    LocalQuery localQuery = new LocalQuery(query, systemResolver, databaseSession);
-
-    transform(databaseSession, localQuery);
-
-    Tuples tuples = localQuery.resolve();
-    Answer result = new TransactionalAnswer(
-        new SubqueryAnswer(databaseSession, systemResolver, tuples, query.getVariableList()));
-    tuples.close();
-    localQuery.close();
-
-    return result;
-  }
-
-
-  /**
-   *
-   * 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 {
-    // Start with the symbolic phase of resolution
-    LocalQuery.MutableLocalQueryImpl mutableLocalQueryImpl =
-      localQuery.new MutableLocalQueryImpl();
-    if (symbolicLogger.isDebugEnabled()) {
-      symbolicLogger.debug("Before transformation: " + mutableLocalQueryImpl);
-    }
-    Iterator i = databaseSession.symbolicTransformationList.iterator();
-    while (i.hasNext()) {
-      SymbolicTransformation symbolicTransformation =
-        (SymbolicTransformation) i.next();
-      assert symbolicTransformation != null;
-      symbolicTransformation.transform(databaseSession.operationContext, mutableLocalQueryImpl);
-      if (mutableLocalQueryImpl.isModified()) {
-        // When a transformation succeeds, we rewind and start from the
-        // beginning of the symbolicTransformationList again
-        if (symbolicLogger.isDebugEnabled()) {
-          symbolicLogger.debug("Symbolic transformation: " +
-                               mutableLocalQueryImpl);
-        }
-        mutableLocalQueryImpl.close();
-        mutableLocalQueryImpl = localQuery.new MutableLocalQueryImpl();
-        i = databaseSession.symbolicTransformationList.iterator();
-      }
-    }
-    mutableLocalQueryImpl.close();
-  }
-
-
   public List query(List queryList) throws QueryException {
 
     if (logger.isInfoEnabled()) {
       logger.info("QUERYING LIST: " + queryList);
     }
 
-    QueryOperation queryOperation = new QueryOperation(queryList, this);
+    QueryOperation queryOperation = new QueryOperation(queryList);
     executeQuery(queryOperation);
     return queryOperation.getAnswerList();
   }
@@ -860,158 +742,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
   //
 
@@ -1027,11 +757,25 @@
     throws QueryException
   {
     try {
+      OperationContext operationContext = new DatabaseOperationContext(
+          cachedModelSet,
+          cachedResolverFactorySet,
+          changedCachedModelSet,
+          this,
+          externalResolverFactoryMap,
+          internalResolverFactoryMap,
+          metadata,
+          securityAdapterList,
+          temporaryModelTypeURI,
+          temporaryResolverFactory,
+          transactionManager,
+          symbolicTransformationList);
       MulgaraTransaction transaction = transactionManager.getTransaction(this, operation.isWriteOperation());
       transaction.execute(operation, operationContext, systemResolver, resolverSessionFactory, metadata);
     } catch (MulgaraTransactionException em) {
       throw new QueryException(failureMessage, em);
     }
+
   }
 
   /**

Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java	2006-10-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -77,8 +77,8 @@
   /** The current localisation/globalisation session.  */
   private final ResolverSession resolverSession;
 
-  /** The session this query is local to.  */
-  private final DatabaseSession databaseSession;
+  /** The operation context this query is local to.  */
+  private final OperationContext operationContext;
 
   /** 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, OperationContext operationContext)
     throws LocalizeException
   {
     if (logger.isDebugEnabled()) {
@@ -134,7 +134,7 @@
     // Initialize fields
     this.constraintExpression = query.getConstraintExpression();
     this.resolverSession = resolverSession;
-    this.databaseSession = databaseSession;
+    this.operationContext = operationContext;
     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.operationContext = localQuery.operationContext;
     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 operationContext.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 operationContext.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, operationContext, result, filterSubqueries(select));
       tmp.close();
     }
 

Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java	2006-10-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/ModifyModelOperation.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -98,8 +98,6 @@
    */
   private final boolean insert;
 
-  private final DatabaseSession databaseSession;
-
   //
   // Constructor
   //
@@ -132,7 +130,6 @@
     this.tripleSet = tripleSet;
     this.query     = null;
     this.insert    = insert;
-    this.databaseSession = null;
   }
 
   /**
@@ -148,8 +145,7 @@
    * @throws QueryException if <var>query</var> doesn't have exactly three
    *   variables in its <code>SELECT</code> clause
    */
-  ModifyModelOperation(URI modelURI, Query query, boolean insert,
-                       DatabaseSession databaseSession)
+  ModifyModelOperation(URI modelURI, Query query, boolean insert)
     throws QueryException
   {
     // Validate "modelURI" parameter
@@ -166,17 +162,11 @@
           "Invalid select clause in insert/select.  Exactly 3 terms required");
     }
 
-    // Validate "databaseSession" parameter
-    if (databaseSession == null) {
-      throw new IllegalArgumentException("Null \"databaseSession\" parameter");
-    }
-
     // Initialize fields
     this.modelURI  = modelURI;
     this.tripleSet = null;
     this.query     = query;
     this.insert    = insert;
-    this.databaseSession = databaseSession;
   }
 
   //
@@ -199,8 +189,7 @@
     else {
       assert query != null;
 
-      Answer answer =
-        DatabaseSession.doQuery(databaseSession, systemResolver, query);
+      Answer answer = operationContext.doQuery(systemResolver, query);
       Variable[] vars = answer.getVariables();
       assert vars.length == 3;
       statements = new TuplesWrapperStatements(
@@ -209,9 +198,10 @@
     }
     assert statements != null;
 
-    doModify(operationContext, systemResolver, modelURI, statements, insert);
+    operationContext.doModify(systemResolver, modelURI, statements, insert);
   }
 
+/* Check this is a copy of OperationContext::doModify
   protected void doModify(OperationContext operationContext,
                           SystemResolver   systemResolver,
                           URI              modelURI,
@@ -255,7 +245,7 @@
       logger.debug("Modified " + modelURI);
     }
   }
-
+*/
   /**
    * @return <code>true</code>
    */

Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/QueryOperation.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/QueryOperation.java	2006-10-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/QueryOperation.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -70,7 +70,6 @@
 
   private final Query query;
   private final List queryList;
-  private final DatabaseSession databaseSession;
 
   /**
    * Answer to the query, or <code>null</code> if the {@link #execute} method
@@ -96,7 +95,7 @@
    * @throws IllegalArgumentException if <var>query</var> or
    *   <var>databaseSession</var> are <code>null</code>
    */
-  QueryOperation(Query query, DatabaseSession databaseSession)
+  QueryOperation(Query query)
   {
     // Validate "query" parameter
     if (query == null) {
@@ -111,7 +110,6 @@
     // Initialize fields
     this.query           = query;
     this.queryList       = null;
-    this.databaseSession = databaseSession;
   }
 
   /**
@@ -123,22 +121,16 @@
    * @throws IllegalArgumentException if <var>queryList</var> or
    *   <var>databaseSession</var> are <code>null</code>
    */
-  QueryOperation(List queryList, DatabaseSession databaseSession)
+  QueryOperation(List queryList)
   {
     // Validate "query" parameter
     if (queryList == null) {
       throw new IllegalArgumentException("Null \"query\" parameter");
     }
 
-    // Validate "databaseSession" parameter
-    if (databaseSession == null) {
-      throw new IllegalArgumentException("Null \"databaseSession\" parameter");
-    }
-
     // Initialize fields
     this.query           = null;
     this.queryList       = queryList;
-    this.databaseSession = databaseSession;
   }
 
   //
@@ -153,16 +145,14 @@
     if (query != null) {
       assert queryList == null;
 
-      answer = DatabaseSession.doQuery(databaseSession, systemResolver, query);
+      answer = operationContext.doQuery(systemResolver, query);
     }
     else {
       assert queryList != null;
 
       answerList = new ArrayList(queryList.size());
       for (Iterator i = queryList.iterator(); i.hasNext();) {
-        answerList.add(DatabaseSession.doQuery(databaseSession,
-                                               systemResolver,
-                                               (Query) i.next()));
+        answerList.add(operationContext.doQuery(systemResolver, (Query)i.next()));
       }
     }
   }

Modified: branches/xafix/src/jar/resolver/java/org/mulgara/resolver/SubqueryAnswer.java
===================================================================
--- branches/xafix/src/jar/resolver/java/org/mulgara/resolver/SubqueryAnswer.java	2006-10-16 06:00:42 UTC (rev 103)
+++ branches/xafix/src/jar/resolver/java/org/mulgara/resolver/SubqueryAnswer.java	2006-10-16 07:27:31 UTC (rev 104)
@@ -76,7 +76,7 @@
   private Variable[] variables;
 
   /** The current database session for this query. */
-  protected AnswerDatabaseSession databaseSession;
+  protected OperationContext operationContext;
 
   /**
    * Assignment property.
@@ -115,11 +115,11 @@
    * @throws TuplesException if it fails to get the row cardinality of the
    *   given tuples.
    */
-  SubqueryAnswer(AnswerDatabaseSession session, ResolverSession resolverSession,
+  SubqueryAnswer(OperationContext operationContext, ResolverSession resolverSession,
       Tuples tuples, List variableList) throws TuplesException {
     super(tuples, resolverSession);
 
-    this.databaseSession = session;
+    this.operationContext = session;
     assignVariables(tuples, variableList);
   }
 
@@ -305,7 +305,7 @@
         logger.debug("Generated subquery: " + query);
       }
 
-      return databaseSession.innerQuery(query);
+      return operationContext.innerQuery(query);
     }
     catch (Exception e) {
       throw new QueryException("Failed to resolve subquery", e);




More information about the Mulgara-svn mailing list