[Mulgara-svn] r421 - 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 08:51:55 UTC 2007
Author: andrae
Date: 2007-09-11 03:51:54 -0500 (Tue, 11 Sep 2007)
New Revision: 421
Added:
branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/MutableLocalQueryImpl.java
Modified:
branches/mgr-69/src/jar/query/java/org/mulgara/query/Query.java
branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/Database.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:
Seperates MutableLocalQueryImpl from LocalQuery. Name is not a bit of a
misnomer, but as it implements the MutableLocalQuery interface it's appropriate.
Also fixes a bug in the Query::clone() method, was doing a shallow copy of
AggregateFunctions, which interacted badly with close().
The change to Database reduces the ServerInfo warning to an info-level message -
removes alot of noise from the debug output - and we should probably have info
on Database as the default anyway.
Modified: branches/mgr-69/src/jar/query/java/org/mulgara/query/Query.java
===================================================================
--- branches/mgr-69/src/jar/query/java/org/mulgara/query/Query.java 2007-09-11 06:37:22 UTC (rev 420)
+++ branches/mgr-69/src/jar/query/java/org/mulgara/query/Query.java 2007-09-11 08:51:54 UTC (rev 421)
@@ -213,6 +213,17 @@
* where-clause in the original query.
*/
public Query(Query query, ConstraintExpression where) {
+ logger.warn("Creating new query from: " + System.identityHashCode(query), new Throwable());
+ this.mutableVariableList = query.mutableVariableList;
+ this.variableList = query.variableList;
+ this.modelExpression = query.modelExpression;
+ this.constraintExpression = where;
+ this.havingConstraint = query.havingConstraint;
+ this.orderList = query.orderList;
+ this.limit = query.limit;
+ this.offset = query.offset;
+ this.answer = (Answer)query.answer.clone();
+ /*
this(query.getVariableList(),
query.getModelExpression(),
where,
@@ -220,7 +231,8 @@
query.getOrderList(),
query.getLimit(),
query.getOffset(),
- query.getGiven());
+ (Answer)query.getGiven().clone());
+ */
}
/**
@@ -237,11 +249,26 @@
}
// Copy mutable fields by value
- cloned.mutableVariableList =
- (variableList == null) ? null : new ArrayList(variableList);
- cloned.variableList =
- (variableList == null) ? null
- : Collections.unmodifiableList(cloned.mutableVariableList);
+ if (variableList == null) {
+ cloned.mutableVariableList = null;
+ cloned.variableList = null;
+ } else {
+ cloned.variableList = new ArrayList();
+ Iterator i = variableList.iterator();
+ while (i.hasNext()) {
+ Object o = i.next();
+ if (o instanceof Subquery) {
+ Subquery s = (Subquery)o;
+ cloned.variableList.add(new Subquery(s.getVariable(), (Query)s.getQuery().clone()));
+ } else if (o instanceof Count) {
+ Count a = (Count)o;
+ cloned.variableList.add(new Count(a.getVariable(), (Query)a.getQuery().clone()));
+ } else {
+ cloned.variableList.add(o);
+ }
+ }
+ cloned.mutableVariableList = Collections.unmodifiableList(cloned.variableList);
+ }
cloned.modelExpression = modelExpression; // FIXME: should be cloned
cloned.answer = (Answer) answer.clone();
@@ -433,6 +460,7 @@
* Close this {@link Query}, and the underlying {@link Answer} objects.
*/
public void close() throws TuplesException {
+ logger.warn("Query: " + System.identityHashCode(this) + " closed", new Throwable());
answer.close();
answer = null;
Modified: branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/Database.java
===================================================================
--- branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/Database.java 2007-09-11 06:37:22 UTC (rev 420)
+++ branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/Database.java 2007-09-11 08:51:54 UTC (rev 421)
@@ -1242,7 +1242,7 @@
setter.invoke(null, new Object[] { names });
} catch (Exception e) {
/* Not much that can be done here */
- logger.warn("Unable to set the host names for Server Info", e);
+ logger.info("Unable to set the host names for Server Info", e);
}
}
}
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 06:37:22 UTC (rev 420)
+++ branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/DatabaseOperationContext.java 2007-09-11 08:51:54 UTC (rev 421)
@@ -779,8 +779,8 @@
logger.info("Inner Count: " + query);
}
try {
+ query = transform(query);
LocalQuery lq = new LocalQuery(query, systemResolver, this);
- transform(lq);
Tuples result = lq.resolveE();
lq.close();
query.close();
@@ -831,10 +831,10 @@
{
TransactionalAnswer result;
+ query = transform(query);
+
LocalQuery localQuery = new LocalQuery(query, systemResolver, this);
- transform(localQuery);
-
// Complete the numerical phase of resolution
Tuples tuples = localQuery.resolveE();
result = new TransactionalAnswer(transaction, new SubqueryAnswer(this, systemResolver, tuples, query.getVariableList()));
@@ -846,36 +846,41 @@
}
/**
- *
- * Perform in-place transformation of localQuery.
- * Note: we really want to convert this to a functional form eventually.
+ * Apply the registered transformations to the query until we reach a
+ * fixed-point.
*/
- void transform(LocalQuery localQuery) throws Exception {
+ Query transform(Query query) throws Exception {
// Start with the symbolic phase of resolution
- LocalQuery.MutableLocalQueryImpl mutableLocalQueryImpl =
- localQuery.new MutableLocalQueryImpl();
if (symbolicLogger.isDebugEnabled()) {
- symbolicLogger.debug("Before transformation: " + mutableLocalQueryImpl);
+ symbolicLogger.debug("Before transformation: " + query);
}
+
+ MutableLocalQueryImpl mutable = new MutableLocalQueryImpl(query);
Iterator i = symbolicTransformationList.iterator();
while (i.hasNext()) {
- SymbolicTransformation symbolicTransformation =
- (SymbolicTransformation) i.next();
+ 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
+
+ symbolicTransformation.transform(this, mutable);
+
+ // When a transformation succeeds, we rewind and start from the
+ // beginning of the symbolicTransformationList again
+ if (mutable.isModified()) {
if (symbolicLogger.isDebugEnabled()) {
- symbolicLogger.debug("Symbolic transformation: " +
- mutableLocalQueryImpl);
+ symbolicLogger.debug("Symbolic transformation: " + mutable);
}
- mutableLocalQueryImpl.close();
- mutableLocalQueryImpl = localQuery.new MutableLocalQueryImpl();
+
+ Query tmp = query;
+ query = new Query(query, mutable.getConstraintExpression());
+ tmp.close();
+
+ mutable = new MutableLocalQueryImpl(query);
+
i = symbolicTransformationList.iterator();
}
}
- mutableLocalQueryImpl.close();
+
+ return query;
}
void clear() throws QueryException {
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 06:37:22 UTC (rev 420)
+++ branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/LocalQuery.java 2007-09-11 08:51:54 UTC (rev 421)
@@ -43,7 +43,6 @@
import org.mulgara.resolver.spi.GlobalizeException;
import org.mulgara.resolver.spi.LocalizeException;
import org.mulgara.resolver.spi.LocalizedTuples;
-import org.mulgara.resolver.spi.MutableLocalQuery;
import org.mulgara.resolver.spi.QueryEvaluationContext;
import org.mulgara.resolver.spi.ResolverSession;
import org.mulgara.resolver.spi.SymbolicTransformation;
@@ -77,9 +76,6 @@
/** The current localisation/globalisation session. */
private final ResolverSession resolverSession;
- /** The constraint expression. */
- private ConstraintExpression constraintExpression;
-
private LocalQueryResolver context;
private Query query;
@@ -120,22 +116,11 @@
// Initialize fields
this.context = new LocalQueryResolver(context, resolverSession);
this.resolverSession = resolverSession;
- this.constraintExpression = query.getConstraintExpression();
if (logger.isDebugEnabled()) {
logger.debug("Constructed local query");
}
}
- LocalQuery(LocalQuery localQuery, ConstraintExpression constraintExpression) {
- this.constraintExpression = constraintExpression;
- this.resolverSession = localQuery.resolverSession;
- this.context = localQuery.context;
- }
-
- //
- // API methods
- //
-
/**
* @return the solution to this query
* @throws QueryException if resolution can't be obtained
@@ -151,7 +136,8 @@
logger.debug("Stacktrace: ", new Throwable());
}
- Tuples result = ConstraintOperations.resolveConstraintExpression(context, query.getModelExpression(), constraintExpression);
+ Tuples result = ConstraintOperations.resolveConstraintExpression(context,
+ query.getModelExpression(), query.getConstraintExpression());
if (logger.isDebugEnabled()) {
logger.debug("Tuples result = " + TuplesOperations.formatTuplesTree(result));
@@ -296,65 +282,4 @@
throw new QueryException("Failed to close query", et);
}
}
-
- /**
- * Mutator for {@link LocalQuery}.
- */
- class MutableLocalQueryImpl implements MutableLocalQuery
- {
- private boolean closed = false;
- private boolean modified = false;
-
- /**
- * Once called, this instance can no longer be used for modifications.
- */
- void close()
- {
- closed = true;
- }
-
- /**
- * @return whether this instance has been used to mutate the value of the
- * outer class
- */
- boolean isModified()
- {
- return modified;
- }
-
- //
- // Methods implementing LocalQuery
- //
-
- public ConstraintExpression getConstraintExpression()
- {
- return constraintExpression;
- }
-
- public void setConstraintExpression(ConstraintExpression constraintExpression)
- {
- // Validate state
- if (closed) {
- throw new IllegalStateException();
- }
-
- // Validate "constraintExpression" parameter
- if (constraintExpression == null) {
- throw new IllegalArgumentException("Null \"constraintExpression\" parameter");
- }
-
- // Update fields
- LocalQuery.this.constraintExpression = constraintExpression;
- modified = true;
- }
-
- //
- // Methods overriding Object
- //
-
- public String toString()
- {
- return LocalQuery.this.toString();
- }
- }
}
Added: branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/MutableLocalQueryImpl.java
===================================================================
--- branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/MutableLocalQueryImpl.java 2007-09-11 06:37:22 UTC (rev 420)
+++ branches/mgr-69/src/jar/resolver/java/org/mulgara/resolver/MutableLocalQueryImpl.java 2007-09-11 08:51:54 UTC (rev 421)
@@ -0,0 +1,91 @@
+/*
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * 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.
+ *
+ * The Original Code is the Kowari Metadata Store.
+ *
+ * The Initial Developer of the Original Code is Plugged In Software Pty
+ * Ltd (http://www.pisoftware.com, mailto:info at pisoftware.com). Portions
+ * created by Plugged In Software Pty Ltd are Copyright (C) 2001,2002
+ * Plugged In Software Pty Ltd. All Rights Reserved.
+ *
+ * Contributor(s):
+ * This file copyright 2006 - Australian Department of Defense
+ * Developed by Netymon Pty Ltd under contract to the Australian
+ * Defense Science and Technology Organisation.
+ *
+ * Extracted and modified by Andrae Muys to reflect move to immutable
+ * mutation interface.
+ *
+ * [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
+ * should use the text of this Exhibit A rather than the text found in the
+ * Original Code Source Code for Your Modifications.]
+ *
+ */
+
+package org.mulgara.resolver;
+
+// Java 2 standard packages
+
+// Third party packages
+import org.apache.log4j.Logger;
+
+// Local packages
+import org.mulgara.query.*;
+import org.mulgara.resolver.spi.MutableLocalQuery;
+
+/**
+ * Allows symbolic transformers to notify the transformation logic that a
+ * transformation has been required.
+ *
+ * @created 2007-09-11
+ * @author <a href="http://www.pisoftware.com/raboczi">Simon Raboczi</a>
+ * @company <a href="mailto:info at netymon.com">Netymon Pty Ltd</a>
+ * @copyright ©2006 Australian Department of Defense</a>
+ * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
+ */
+class MutableLocalQueryImpl implements MutableLocalQuery
+{
+ private ConstraintExpression constraintExpression;
+
+ private boolean modified;
+
+ MutableLocalQueryImpl(Query query) {
+ this.constraintExpression = query.getConstraintExpression();
+ this.modified = false;
+ }
+
+ /**
+ * @return whether this instance has been used to mutate the value of the outer class
+ */
+ boolean isModified() {
+ return modified;
+ }
+
+ public ConstraintExpression getConstraintExpression() {
+ return constraintExpression;
+ }
+
+ public void setConstraintExpression(ConstraintExpression constraintExpression) {
+ if (constraintExpression == null) {
+ throw new IllegalArgumentException("Null \"constraintExpression\" parameter");
+ }
+
+ if (constraintExpression != this.constraintExpression) {
+ this.constraintExpression = constraintExpression;
+ modified = true;
+ }
+ }
+
+ public String toString() {
+ return getClass().toString() + ":=:" + constraintExpression.toString();
+ }
+}
More information about the Mulgara-svn
mailing list