[Mulgara-svn] r422 - in branches/mgr-69/src/jar: query/java/org/mulgara/query resolver/java/org/mulgara/resolver

andrae at mulgara.org andrae at mulgara.org
Tue Sep 11 09:11:34 UTC 2007


Author: andrae
Date: 2007-09-11 04:11:33 -0500 (Tue, 11 Sep 2007)
New Revision: 422

Modified:
   branches/mgr-69/src/jar/query/java/org/mulgara/query/ModelExpression.java
   branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
   branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java
Log:
Almost completes the isolation of the final resolve method from LocalQuery.

Also fixes ModelExpression, which ceased to be Serializable when I removed
Transformable; made this explicit.



Modified: branches/mgr-69/src/jar/query/java/org/mulgara/query/ModelExpression.java
===================================================================
--- branches/mgr-69/src/jar/query/java/org/mulgara/query/ModelExpression.java	2007-09-11 08:51:54 UTC (rev 421)
+++ branches/mgr-69/src/jar/query/java/org/mulgara/query/ModelExpression.java	2007-09-11 09:11:33 UTC (rev 422)
@@ -27,9 +27,9 @@
 
 package org.mulgara.query;
 
-// used only in doc comments
 import java.net.*;
 import java.util.*;
+import java.io.Serializable;
 
 /**
  * An expression whose leaves are the {@link URL}s of RDF models.
@@ -49,7 +49,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public interface ModelExpression extends Cloneable {
+public interface ModelExpression extends Cloneable, Serializable {
 
   /**
    * Allow newer compiled version of the stub to operate when changes

Modified: branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java
===================================================================
--- branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2007-09-11 08:51:54 UTC (rev 421)
+++ branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java	2007-09-11 09:11:33 UTC (rev 422)
@@ -780,9 +780,8 @@
     }
     try {
       query = transform(query);
-      LocalQuery lq = new LocalQuery(query, systemResolver, this);
-      Tuples result = lq.resolveE();
-      lq.close();
+      LocalQuery lq = new LocalQuery(systemResolver, this);
+      Tuples result = lq.resolveE(query);
       query.close();
 
       return result;
@@ -833,14 +832,13 @@
 
     query = transform(query);
 
-    LocalQuery localQuery = new LocalQuery(query, systemResolver, this);
+    LocalQuery localQuery = new LocalQuery(systemResolver, this);
 
     // Complete the numerical phase of resolution
-    Tuples tuples = localQuery.resolveE();
+    Tuples tuples = localQuery.resolveE(query);
     result = new TransactionalAnswer(transaction, new SubqueryAnswer(this, systemResolver, tuples, query.getVariableList()));
     answers.put(result, null);
     tuples.close();
-    localQuery.close();
 
     return result;
   }

Modified: branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java
===================================================================
--- branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java	2007-09-11 08:51:54 UTC (rev 421)
+++ branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java	2007-09-11 09:11:33 UTC (rev 422)
@@ -78,12 +78,6 @@
 
   private LocalQueryResolver context;
 
-  private Query query;
-
-  //
-  // Constructor
-  //
-
   /**
    * Construct a database.
    *
@@ -94,25 +88,14 @@
    *   <var>resolverSession</var> are <code>null</code>
    * @throws LocalizeException if the <var>query</var> can't be localized
    */
-  LocalQuery(Query query, ResolverSession resolverSession, DatabaseOperationContext context)
+  LocalQuery(ResolverSession resolverSession, DatabaseOperationContext context)
     throws LocalizeException, TuplesException
   {
-    if (logger.isDebugEnabled()) {
-      logger.debug("Constructing local query for " + query);
-    }
-
-    // Validate "query" parameter
-    if (query == null) {
-      throw new IllegalArgumentException("Null \"query\" parameter");
-    }
-
     // Validate "resolverSession" parameter
     if (resolverSession == null) {
       throw new IllegalArgumentException("Null \"resolverSession\" parameter");
     }
 
-    this.query = (Query)query.clone();
-
     // Initialize fields
     this.context = new LocalQueryResolver(context, resolverSession);
     this.resolverSession = resolverSession;
@@ -125,8 +108,12 @@
    * @return the solution to this query
    * @throws QueryException if resolution can't be obtained
    */
-  Tuples resolveE() throws QueryException
+  Tuples resolveE(Query query) throws QueryException
   {
+    if (query == null) {
+      throw new IllegalArgumentException("Query null in LocalQuery::resolveE");
+    }
+
     try {
       if (logger.isDebugEnabled()) {
         logger.debug("Resolving query " + query);
@@ -143,12 +130,12 @@
         logger.debug("Tuples result = " + TuplesOperations.formatTuplesTree(result));
       }
 
-      result = projectSelectClause(result);
-      result = appendAggregates(result);
-      result = applyHaving(result);
-      result = orderResult(result);
-      result = offsetResult(result);
-      result = limitResult(result);
+      result = projectSelectClause(query, result);
+      result = appendAggregates(query, result);
+      result = applyHaving(query, result);
+      result = orderResult(query, result);
+      result = offsetResult(query, result);
+      result = limitResult(query, result);
 
       return result;
     } catch (TuplesException et) {
@@ -157,7 +144,7 @@
   }
 
 
-  private Tuples projectSelectClause(Tuples result) throws TuplesException
+  private Tuples projectSelectClause(Query query, Tuples result) throws TuplesException
   {
     if (result.getRowCardinality() > Cursor.ZERO) {
       Tuples tmp = result;
@@ -187,7 +174,7 @@
   }
 
 
-  private Tuples appendAggregates(Tuples result) throws TuplesException
+  private Tuples appendAggregates(Query query, Tuples result) throws TuplesException
   {
     if (result.getRowCardinality() != Tuples.ZERO) {
       Tuples tmp = result;
@@ -211,7 +198,7 @@
   }
 
 
-  private Tuples applyHaving(Tuples result) throws TuplesException {
+  private Tuples applyHaving(Query query, Tuples result) throws TuplesException {
     ConstraintHaving having = query.getHavingExpression();
     Tuples tmp = result;
     if (having != null) {
@@ -224,7 +211,7 @@
   }
 
 
-  private Tuples orderResult(Tuples result) throws TuplesException, QueryException {
+  private Tuples orderResult(Query query, Tuples result) throws TuplesException, QueryException {
     List orderList = query.getOrderList();
     if (orderList.size() > 0 && result.getRowCardinality() > Cursor.ONE) {
       Tuples tmp = result;
@@ -236,7 +223,7 @@
     return result;
   }
 
-  private Tuples offsetResult(Tuples result) throws TuplesException
+  private Tuples offsetResult(Query query, Tuples result) throws TuplesException
   {
     int offset = query.getOffset();
     if (offset > 0) {
@@ -249,7 +236,7 @@
   }
 
 
-  private Tuples limitResult(Tuples result)  throws TuplesException
+  private Tuples limitResult(Query query, Tuples result)  throws TuplesException
   {
     Integer limit = query.getLimit();
     if (limit != null) {
@@ -260,26 +247,4 @@
 
     return result;
   }
-
-
-  public Object clone()
-  {
-    try {
-      LocalQuery query = (LocalQuery)super.clone();
-
-      return query;
-    } catch (CloneNotSupportedException ec) {
-      throw new Error("Object threw CloneNotSupportedException", ec);
-    }
-  }
-
-
-  public void close() throws QueryException
-  {
-    try {
-      query.close();
-    } catch (TuplesException et) {
-      throw new QueryException("Failed to close query", et);
-    }
-  }
 }




More information about the Mulgara-svn mailing list