[Mulgara-svn] r1392 - in branches/xa11/src/jar: query/java/org/mulgara/query querylang/java/org/mulgara/itql querylang/java/org/mulgara/sparql querylang/sablecc resolver-store/java/org/mulgara/resolver/store resolver-store/java/org/mulgara/store/statement/xa11
pag at mulgara.org
pag at mulgara.org
Wed Dec 3 00:00:57 UTC 2008
Author: pag
Date: 2008-12-02 16:00:56 -0800 (Tue, 02 Dec 2008)
New Revision: 1392
Removed:
branches/xa11/src/jar/query/java/org/mulgara/query/ConstraintNegation.java
branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolution.java
branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolutionUnitTest.java
branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreInverseResolution.java
Modified:
branches/xa11/src/jar/querylang/java/org/mulgara/itql/ConstraintExpressionBuilder.java
branches/xa11/src/jar/querylang/java/org/mulgara/sparql/IdentityTransformer.java
branches/xa11/src/jar/querylang/sablecc/itql.grammar
branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreResolver.java
branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java
Log:
Removed ConstraintNegation and related code
Deleted: branches/xa11/src/jar/query/java/org/mulgara/query/ConstraintNegation.java
===================================================================
--- branches/xa11/src/jar/query/java/org/mulgara/query/ConstraintNegation.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/query/java/org/mulgara/query/ConstraintNegation.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -1,185 +0,0 @@
-/*
- * 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):
- * getModel() contributed by Netymon Pty Ltd on behalf of
- * The Australian Commonwealth Government under contract 4500507038.
- *
- * [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.query;
-
-import java.util.*;
-
-// Third party packages
-// import org.apache.log4j.Logger;
-
-/**
- * A constraint expression composed of the negation (logical NOT) of one
- * subexpressions.
- *
- * @created 2001-10-29
- *
- * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
- *
- * @version $Revision: 1.9 $
- *
- * @modified $Date: 2005/05/29 08:32:39 $
- *
- * @maintenanceAuthor $Author: raboczi $
- *
- * @company <A href="mailto:info at PIsoftware.com">Plugged In Software</A>
- *
- * @copyright © 2001-2003 <A href="http://www.PIsoftware.com/">Plugged In
- * Software Pty Ltd</A>
- *
- * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
- */
-public class ConstraintNegation implements Constraint {
-
- // /** The logger */
- // private final static Logger logger = Logger.getLogger(ConstraintNegation.class.getName());
-
- /**
- * Allow newer compiled version of the stub to operate when changes
- * have not occurred with the class.
- * NOTE : update this serialVersionUID when a method or a public member is
- * deleted.
- */
- private static final long serialVersionUID = 9147228997817064907L;
-
- /**
- * The negated expression.
- */
- private Constraint constraint;
-
- //
- // Constructor
- //
-
- /**
- * Construct a constraint negation.
- *
- * @param constraint a non-<code>null</code> constraint
- * @throws IllegalArgumentException if <var>constraint</var> is
- * <code>null</code>
- */
- public ConstraintNegation(Constraint constraint) {
-
- // Validate "expression" parameter
- if (constraint == null) {
-
- throw new IllegalArgumentException("Null \"constraint\" parameter");
- }
-
- // Initialize fields
- this.constraint = constraint;
- }
-
- public boolean isRepeating() {
- return false;
- }
-
-
- /**
- * Get a constraint element by index.
- *
- * @param index The constraint element to retrieve, from 0 to 3.
- * @return The constraint element referred to by index.
- */
- public ConstraintElement getElement(int index) {
- return constraint.getElement(index);
- }
-
- public ConstraintElement getModel() {
- return constraint.getModel();
- }
-
-
- /**
- * Get all constraints which are variables. For back-compatibility, this
- * method currently ignores the fourth element of the triple.
- *
- * @return A set containing all variable constraints.
- */
- public Set<Variable> getVariables() {
- return constraint.getVariables();
- }
-
-
- /**
- * tests if the inner constraint is a ConstraintIs.
- *
- * @return <code>true</code> if the inner constraint is a ConstraintIs class.
- */
- public boolean isInnerConstraintIs() {
- return constraint instanceof ConstraintIs;
- }
-
- /**
- * Convert this object to a string.
- *
- * @return A string representation of this object.
- */
- public String toString() {
- return "not " + constraint;
- }
-
- /**
- * Creates a relatively unique value representing this constraint.
- *
- * @return A numerical combination of the elements and the anchor
- */
- public int hashCode() {
- return constraint.hashCode() * -1;
- }
-
- /**
- * Equality is by value.
- *
- * @param object PARAMETER TO DO
- * @return RETURNED VALUE TO DO
- */
- public boolean equals(Object object) {
-
- if (object == null) {
- return false;
- }
-
- if (object == this) {
- return true;
- }
-
- boolean returnValue = false;
-
- // Check that the given object is the correct class if so check each
- // element.
- if (object.getClass().equals(ConstraintNegation.class)) {
-
- ConstraintNegation tmpConstraint = (ConstraintNegation) object;
- returnValue = constraint.equals(tmpConstraint.constraint);
- }
-
- return returnValue;
- }
-}
Modified: branches/xa11/src/jar/querylang/java/org/mulgara/itql/ConstraintExpressionBuilder.java
===================================================================
--- branches/xa11/src/jar/querylang/java/org/mulgara/itql/ConstraintExpressionBuilder.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/querylang/java/org/mulgara/itql/ConstraintExpressionBuilder.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -133,99 +133,7 @@
}
- public void caseAConstraintConstraintFactor(AConstraintConstraintFactor rawConstraintFactor) {
-
- if (logger.isDebugEnabled()) logger.debug("Found constraint constraint factor " + rawConstraintFactor);
-
- // get the constraint
- PConstraint constraint = ((AConstraintConstraintFactor)rawConstraintFactor).getConstraint();
-
- if (logger.isDebugEnabled()) logger.debug("Found constraint " + constraint + ", resolving components");
-
- // get the constraint's components
- try {
- Constraint tmpConstraint;
-
- ConstraintElement subject = toConstraintElement(((AConstraint)constraint).getSubject());
- ConstraintElement predicate = toConstraintElement(((AConstraint)constraint).getPredicate());
- ConstraintElement object = toConstraintElement(((AConstraint)constraint).getObject());
-
- if (logger.isDebugEnabled()) {
- logger.debug("Found subject " + subject);
- logger.debug("Found predicate " + predicate);
- logger.debug("Found object " + object);
- }
-
- // check for an IN clause
- AInClause inClause = (AInClause)((AConstraint)constraint).getInClause();
-
- // bundle them into a constraint (order is probably important here...?)
- if (inClause != null) {
- if (logger.isDebugEnabled()) logger.debug("Found model " + inClause.getElement());
-
- ConstraintElement model = toConstraintElement(inClause.getElement());
- tmpConstraint = ConstraintFactory.newConstraint(subject, predicate, object, model);
- } else {
- tmpConstraint = ConstraintFactory.newConstraint(subject, predicate, object);
- }
-
- // handle negated constraints
- if (((AConstraintConstraintFactor) rawConstraintFactor).getExclude() != null) {
- tmpConstraint = new ConstraintNegation(tmpConstraint);
- }
-
- // Set new value.
- if (logger.isDebugEnabled()) logger.debug("Setting constraint: " + tmpConstraint);
-
- setConstraintExpression(tmpConstraint);
- } catch (URISyntaxException use) {
- uriException = use;
- } catch (QueryException qe) {
- queryException = qe;
- }
- }
-
-
/**
- * Handle a constraint expression. Will set URIException or QueryException if
- * an exception occurs.
- *
- * @param rawConstraintFactor the expression to create a constraint expression from.
- */
- public void caseAExpressionConstraintFactor(AExpressionConstraintFactor rawConstraintFactor) {
-
- try {
- ConstraintExpression tmpConstraintExpression;
-
- if (logger.isDebugEnabled()) logger.debug("Found factor expression constraint factor " + rawConstraintFactor);
-
- // get the constraint expression
- PConstraintExpression embeddedConstraintExpression =
- ((AExpressionConstraintFactor)rawConstraintFactor).getConstraintExpression();
-
- if (logger.isDebugEnabled()) logger.debug("Recursing with constraint factor " + embeddedConstraintExpression);
-
- // build the constraint expression
- ConstraintExpressionBuilder builder = new ConstraintExpressionBuilder(interpreter);
- embeddedConstraintExpression.apply((Switch) builder);
-
- tmpConstraintExpression = builder.getConstraintExpression();
-
- // handle negated expressions
- if (((AExpressionConstraintFactor) rawConstraintFactor).getExclude() != null) {
- tmpConstraintExpression = new ConstraintNegation((Constraint)tmpConstraintExpression);
- }
-
- setConstraintExpression(tmpConstraintExpression);
- } catch (URISyntaxException use) {
- uriException = use;
- } catch (QueryException qe) {
- queryException = qe;
- }
- }
-
-
- /**
* Handle a transitive constraint. Will set URIException or QueryException if
* an exception occurs.
*
Modified: branches/xa11/src/jar/querylang/java/org/mulgara/sparql/IdentityTransformer.java
===================================================================
--- branches/xa11/src/jar/querylang/java/org/mulgara/sparql/IdentityTransformer.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/querylang/java/org/mulgara/sparql/IdentityTransformer.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -32,7 +32,6 @@
import org.mulgara.query.ConstraintImpl;
import org.mulgara.query.ConstraintIn;
import org.mulgara.query.ConstraintIs;
-import org.mulgara.query.ConstraintNegation;
import org.mulgara.query.ConstraintNotOccurs;
import org.mulgara.query.ConstraintOccurs;
import org.mulgara.query.ConstraintOccursLessThan;
@@ -60,7 +59,7 @@
* Builds a transformer, with identity constructors.
*/
public IdentityTransformer() {
- initialize(new ConsImpl(), new ConsIs(), new ConsNegation(),
+ initialize(new ConsImpl(), new ConsIs(),
new ConsNotOccurs(), new ConsOccurs(), new ConsOccursLessThan(),
new ConsOccursMoreThan(), new ConsSingleTransitive(),
new ConsTransitive(), new ConsWalk());
@@ -267,11 +266,6 @@
public Class<ConstraintIs> getType() { return ConstraintIs.class; }
}
- protected class ConsNegation implements ConstraintTypeCons<ConstraintNegation> {
- public ConstraintNegation newConstraint(Constraint c) { throw new IllegalStateException("Negations are no longer supported"); }
- public Class<ConstraintNegation> getType() { return ConstraintNegation.class; }
- }
-
protected class ConsSingleTransitive implements ConstraintTypeCons<SingleTransitiveConstraint> {
public SingleTransitiveConstraint newConstraint(Constraint c) throws SymbolicTransformationException {
SingleTransitiveConstraint s = (SingleTransitiveConstraint)c;
Modified: branches/xa11/src/jar/querylang/sablecc/itql.grammar
===================================================================
--- branches/xa11/src/jar/querylang/sablecc/itql.grammar 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/querylang/sablecc/itql.grammar 2008-12-03 00:00:56 UTC (rev 1392)
@@ -47,7 +47,6 @@
{def} drop = 'drop';
{def} echo = 'echo';
{def} execute = 'execute';
- {def} exclude = 'exclude';
{def} export = 'export';
{def} from = 'from';
{def} help = 'help';
@@ -253,10 +252,8 @@
{minus} [minuend]:constraint_dterm minus [subtrahend]:constraint_factor ;
constraint_factor =
- {constraint} exclude? constraint |
{compound} lbrace [subject]:element exists_expression in_clause? rbrace |
{existential} lbracket exists_expression in_clause? rbracket |
- {expression} exclude? lpar constraint_expression rpar |
{transitive} transitive_clause |
{walk} walk_clause ;
Deleted: branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolution.java
===================================================================
--- branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolution.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolution.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -1,615 +0,0 @@
-/*
- * 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):
- * getModel() contributed by Netymon Pty Ltd on behalf of
- * The Australian Commonwealth Government under contract 4500507038.
- *
- * [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.store;
-
-// Third party packages
-import org.apache.log4j.Logger;
-
-// Standard Java packages
-import java.util.*;
-
-// Locally written packages
-import org.mulgara.query.*;
-import org.mulgara.resolver.spi.Resolution;
-import org.mulgara.resolver.spi.Resolver;
-import org.mulgara.store.nodepool.NodePool;
-import org.mulgara.store.statement.StatementStore;
-import org.mulgara.store.statement.StatementStoreException;
-import org.mulgara.store.tuples.AbstractTuples;
-import org.mulgara.store.tuples.StoreTuples;
-import org.mulgara.store.tuples.Tuples;
-import org.mulgara.store.tuples.TuplesOperations;
-
-/**
- * Tuples backed by the graph, corresponding to a particular constraint.
- *
- * It differs from {@link StatementStoreResolution} in that it handles
- * constraints with duplicate variable bindings. That is,
- * <code>$x $x $x</code> which will return all the statements that have the
- * same value in all three places. The class retains the original constraint
- * so that the graph index it's resolved against can be resolved anew as its
- * variables are bound.
- *
- * TO DO: Support <code>mulgara:is</code> re-binding.
- *
- * @created 2004-08-26
- *
- * @author Andrew Newman
- *
- * @version $Revision: 1.10 $
- *
- * @modified $Date: 2005/05/02 20:07:58 $ by $Author: raboczi $
- *
- * @maintenanceAuthor $Author: raboczi $
- *
- * @company <a href="mailto:info at PIsoftware.com">Plugged In Software</a>
- *
- * @copyright © 2003 <A href="http://www.PIsoftware.com/">Plugged In
- * Software Pty Ltd</A>
- *
- * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
- */
-class StatementStoreDuplicateResolution extends AbstractTuples implements Resolution {
-
- protected static Logger logger = Logger.getLogger(StatementStoreDuplicateResolution.class);
-
- /** Indicates ordering by subject */
- private final static int MASK0 = 1;
-
- /** Indicates ordering by predicate */
- private final static int MASK1 = 2;
-
- /** Indicates ordering by object */
- private final static int MASK2 = 4;
-
- /** Indicates ordering by graph */
- private final static int MASK3 = 8;
-
- /**
- * The constraint these tuples were generated to satisfy.
- */
- protected Constraint constraint;
-
- /**
- * The graph from which these tuples were generated.
- */
- protected StatementStore store;
-
- /**
- * The tuples.
- */
- private Tuples baseTuples, uniqueTuples;
-
- /**
- * Which columns s, p, o are the same.
- */
- private boolean[] sameColumns;
-
- /**
- * Whether we've calculated the rows.
- */
- private boolean calculatedRowCount;
-
- /**
- * An array that contains the position in the tuples. Elements 0, 1, 2, 3
- * map to subject, predicate, object and meta and the value in the array is
- * the column position.
- */
- private int[] columnOrder;
-
- /** A mapping between the virtual column numbers and the internal column numbers. */
- private int[] columnMap;
-
- private boolean hasNext = false;
-
- private List variableList;
-
- private TuplesEvaluator tuplesEvaluator;
-
- /**
- * Construct a tuples with node numbers and local tuples objects.
- *
- * @param newTuples a local tuples representing a graph.
- */
- StatementStoreDuplicateResolution(boolean[] newSameColumns, Tuples newTuples,
- int[] newColumnOrder) {
-
- baseTuples = newTuples;
- sameColumns = newSameColumns;
- columnOrder = newColumnOrder;
-
- // Get variable list.
- variableList = new LinkedList();
- Variable[] baseVars = baseTuples.getVariables();
- for (int index = 0; index < sameColumns.length; index++) {
- if (sameColumns[index]) variableList.add(baseVars[index]);
- }
- // do 1:1 mapping as this is expected in the tests - variable names are not duplicated
- columnMap = new int[baseVars.length];
- for (int i = 0; i < columnMap.length; i++) columnMap[i] = i;
-
- // Project for unique variables.
- try {
- uniqueTuples = TuplesOperations.project(baseTuples, variableList);
- }
- catch (TuplesException te) {
- logger.error("Failed to get unique tuples", te);
- }
-
- columnOrder = newColumnOrder;
- setVariables(newTuples.getVariables());
- setTuplesEvaluator();
- }
-
- /**
- * Find a graph index that satisfies a constraint.
- *
- * @param newConstraint the constraint to satisfy
- * @param newStore the store to resolve against
- * @throws IllegalArgumentException if <var>constraint</var> or <var>graph
- * </var> is <code>null</code>
- * @throws TuplesException EXCEPTION TO DO
- */
- StatementStoreDuplicateResolution(Constraint newConstraint, StatementStore newStore)
- throws TuplesException {
-
- try {
- constraint = newConstraint;
- store = newStore;
-
- // Setup which columns are duplicates.
- boolean equalSubject = constraint.getElement(0).equals(constraint.getElement(1)) ||
- constraint.getElement(0).equals(constraint.getElement(2));
- boolean equalPredicate = constraint.getElement(1).equals(constraint.getElement(0)) ||
- constraint.getElement(1).equals(constraint.getElement(2));
- boolean equalObject = constraint.getElement(2).equals(constraint.getElement(0)) ||
- constraint.getElement(2).equals(constraint.getElement(1));
- sameColumns = new boolean[] { equalSubject, equalPredicate,
- equalObject };
-
- // Setup which are the constants and which are the variables.
- long subject = toGraphTuplesIndex(constraint.getElement(0));
- long predicate = toGraphTuplesIndex(constraint.getElement(1));
- long object = toGraphTuplesIndex(constraint.getElement(2));
- long meta = toGraphTuplesIndex(constraint.getModel());
-
- final long VAR = NodePool.NONE;
- if (meta != VAR && subject == VAR && predicate == VAR && object == VAR) {
- // all variables except the graph. Select explicit ordering.
- int mask = MASK3;
- if (equalSubject) mask |= MASK0;
- if (equalPredicate) mask |= MASK1;
- if (equalObject) mask |= MASK2;
- baseTuples = store.findTuples(mask, subject, predicate, object, meta);
- } else {
- // Return the tuples using the s, p, o hints.
- baseTuples = store.findTuples(subject, predicate, object, meta);
- }
-
- // Get the unique values for the multiply constrained column.
- variableList = new LinkedList();
- for (int index = 0; index < sameColumns.length; index++) {
- if (sameColumns[index]) {
- variableList.add(StatementStore.VARIABLES[index]);
- }
- }
- uniqueTuples = TuplesOperations.project(baseTuples, variableList);
-
- // Create column map.
- columnOrder = new int[4];
- int[] inverseColumnOrder = ((StoreTuples)baseTuples).getColumnOrder();
- for (int index = 0; index < inverseColumnOrder.length; index++) {
- columnOrder[inverseColumnOrder[index]] = index;
- }
-
- // Set the variables. Using an ordered set.
- Set uniqueVariables = new LinkedHashSet();
- columnMap = new int[2];
- for (int index = 0; index < baseTuples.getVariables().length; index++) {
- Object obj = constraint.getElement(index);
- if (obj instanceof Variable) {
- if (!((Variable) obj).equals(Variable.FROM)) {
- if (!uniqueVariables.contains(obj)) columnMap[uniqueVariables.size()] = columnOrder[index];
- uniqueVariables.add(obj);
- }
- }
- }
- setVariables((Variable[]) uniqueVariables.toArray(new Variable[uniqueVariables.size()]));
-
- // Set up the tuples evaluator.
- setTuplesEvaluator();
- }
- catch (StatementStoreException se) {
- throw new TuplesException("Failed to set-up tuples", se);
- }
- }
-
- /**
- * Create a new tuples evaluator depending on how many columns to bind.
- */
- public void setTuplesEvaluator() {
- if (variableList.size() == 2) {
- tuplesEvaluator = new TwoConstrainedTuplesEvaluator();
- }
- else {
- tuplesEvaluator = new ThreeConstrainedTuplesEvaluator();
- }
- }
-
- public long getRowCount() throws TuplesException {
- return tuplesEvaluator.getRowCount();
- }
-
- public boolean hasNoDuplicates() throws TuplesException {
- return baseTuples.hasNoDuplicates();
- }
-
- public List getOperands() {
- return new ArrayList();
- }
-
- public void beforeFirst(long[] prefix, int suffixTruncation) throws TuplesException {
- if (prefix.length > 4) {
- throw new TuplesException("Prefix too long");
- }
- tuplesEvaluator.beforeFirst(prefix, suffixTruncation);
- }
-
- public void close() throws TuplesException {
- try {
- if (baseTuples != null) {
- baseTuples.close();
- }
- }
- finally {
- if (uniqueTuples != null) {
- uniqueTuples.close();
- }
- }
- }
-
- /**
- * METHOD TO DO
- *
- * @return RETURNED VALUE TO DO
- */
- public Object clone() {
- StatementStoreDuplicateResolution cloned = (StatementStoreDuplicateResolution) super.clone();
- cloned.baseTuples = (Tuples) baseTuples.clone();
- cloned.uniqueTuples = (Tuples) uniqueTuples.clone();
- cloned.setVariables(getVariables());
- cloned.setTuplesEvaluator();
-// cloned.constraint = constraint;
- return cloned;
- }
-
-
- public long getRowUpperBound() throws TuplesException {
- return getRowCount();
- }
-
- public int getRowCardinality() throws TuplesException {
- long count = getRowCount();
- if (count > 1) {
- return Cursor.MANY;
- }
- switch ((int) count) {
- case 0:
- return Cursor.ZERO;
- case 1:
- return Cursor.ONE;
- default:
- throw new TuplesException("Illegal row count: " + count);
- }
- }
-
- public Constraint getConstraint() {
- return constraint;
- }
-
- public long getColumnValue(int column) throws TuplesException {
- return baseTuples.getColumnValue(columnMap[column]);
- }
-
- public boolean isColumnEverUnbound(int column) throws TuplesException {
- return baseTuples.isColumnEverUnbound(columnMap[column]);
- }
-
- public boolean isUnconstrained() throws TuplesException {
- return baseTuples.isUnconstrained();
- }
-
- public boolean isMaterialized() {
- return baseTuples.isMaterialized();
- }
-
- public boolean next() throws TuplesException {
- return tuplesEvaluator.next();
- }
-
- public boolean isComplete() {
- return true;
- }
-
-
- /**
- * A decorator around the getRowCount(), next() and beforeFirst() methods on
- * a tuples correctly sets the searching tuples and performs the correct next
- * operation.
- */
- private interface TuplesEvaluator {
-
- /**
- * Returns the row count.
- *
- * @return the row count.
- * @throws TuplesException if there was an error accessing the tuples.
- */
- public long getRowCount() throws TuplesException;
-
- /**
- * Calls before first using a given prefix.
- *
- * @param prefix long[] the prefix to jump to.
- * @param suffixTruncation the suffixes to truncate.
- * @throws TuplesException if there was a problem accessing the tuples.
- */
- public void beforeFirst(long[] prefix, int suffixTruncation)
- throws TuplesException;
-
- /**
- * Returns true if there is another tuples.
- *
- * @throws TuplesException if there was a problem accessing the tuples.
- * @return true if there is another tuples.
- */
- public boolean next() throws TuplesException;
- }
-
- /**
- * Operates on a tuples where two of the constraints are equal.
- */
- private class TwoConstrainedTuplesEvaluator implements TuplesEvaluator {
-
- public long getRowCount() throws TuplesException {
-
- // Only calculate rows once.
- if (!calculatedRowCount) {
-
- // Start with total number of tuples.
- Tuples tmpUniqueTuples = (Tuples) uniqueTuples.clone();
- Tuples tmpTuples = (Tuples) baseTuples.clone();
- tmpUniqueTuples.beforeFirst();
- tmpTuples.beforeFirst();
-
- rowCount = 0;
-
- while (tmpUniqueTuples.next()) {
- if (tmpUniqueTuples.getColumnValue(0) == tmpUniqueTuples.getColumnValue(1)) {
- tmpTuples.beforeFirst(new long[] {
- tmpUniqueTuples.getColumnValue(0),
- tmpUniqueTuples.getColumnValue(1) }, 0);
- while (tmpTuples.next()) {
- rowCount++;
- }
- }
- }
-
- // Ensure we don't calculate the rows again.
- calculatedRowCount = true;
- }
- return rowCount;
- }
-
- public void beforeFirst(long[] prefix, int suffixTruncation)
- throws TuplesException {
-
- // create a new prefix for uniqueTuples
- // this only includes columns from the initial prefix that represented duplicate variables
- // takes advantage of the fact that variables came out in the same order as the initial constraint
- // also, sameColumns offsets are same as baseTuples offsets
- long[] duplicatesPrefix = new long[] {};
- for (int i = 0; i < prefix.length; i++) {
- // i is an index into the virtual tuples. Map it to the original columns
- if (sameColumns[columnMap[i]]) {
- // only the first of the duplicated columns was mapped
- duplicatesPrefix = new long[] { prefix[i], prefix[i] };
- break;
- }
- }
-
- // Get the subject/predicate before first.
- uniqueTuples.beforeFirst(duplicatesPrefix, suffixTruncation);
-
- hasNext = uniqueTuples.next();
- while (hasNext && (uniqueTuples.getColumnValue(0) != uniqueTuples.getColumnValue(1))) {
- hasNext = uniqueTuples.next();
- }
-
- // Go to the first tuples. Ignoring suffix truncation.
- if (hasNext) {
- if (prefix.length <= 1) {
- baseTuples.beforeFirst(new long[] { uniqueTuples.getColumnValue(0), uniqueTuples.getColumnValue(1) }, 0);
- } else {
- assert prefix.length == 2;
- baseTuples.beforeFirst(new long[] { uniqueTuples.getColumnValue(0), uniqueTuples.getColumnValue(1), prefix[1] }, 0);
- }
- }
- }
-
- public boolean next() throws TuplesException {
-
- // Check that there are more tuples - assume tuples are in order.
- if (hasNext) {
-
- boolean hasNextBase = baseTuples.next();
-
- // Check if we still have a match, if not get the next match.
- if (!hasNextBase ||
- !((uniqueTuples.getColumnValue(0) == baseTuples.getColumnValue(0)) &&
- (uniqueTuples.getColumnValue(1) == baseTuples.getColumnValue(1)))) {
-
- // Get the next item to search.
- while (uniqueTuples.next()) {
-
- // Check to see that there is a next value. There will be at least
- // one value as the items to search are based on the original tuples.
- if (uniqueTuples.getColumnValue(0) == uniqueTuples.getColumnValue(1)) {
- baseTuples.beforeFirst(new long[] { uniqueTuples.getColumnValue(0),
- uniqueTuples.getColumnValue(1) }, 0);
- hasNextBase = baseTuples.next();
- if (hasNextBase) {
- break;
- }
- }
- }
- }
- hasNext = hasNextBase;
- }
- return hasNext;
- }
- }
-
- /**
- * Operates on a tuples where all three of the constraints are equal.
- */
- private class ThreeConstrainedTuplesEvaluator implements TuplesEvaluator {
-
- public long getRowCount() throws TuplesException {
-
- // Only calculate rows once.
- if (!calculatedRowCount) {
-
- // Start with total number of tuples.
- Tuples tmpSubjPredTuples = (Tuples) uniqueTuples.clone();
- Tuples tmpTuples = (Tuples) baseTuples.clone();
- tmpSubjPredTuples.beforeFirst();
- tmpTuples.beforeFirst();
-
- rowCount = 0;
-
- while (tmpSubjPredTuples.next()) {
- if ((tmpSubjPredTuples.getColumnValue(0) == tmpSubjPredTuples.getColumnValue(1)) &&
- (tmpSubjPredTuples.getColumnValue(1) == tmpSubjPredTuples.getColumnValue(2))) {
- tmpTuples.beforeFirst(new long[] {
- tmpSubjPredTuples.getColumnValue(0),
- tmpSubjPredTuples.getColumnValue(1),
- tmpSubjPredTuples.getColumnValue(2) }, 0);
- while (tmpTuples.next()) {
- rowCount++;
- }
- }
- }
-
- // Ensure we don't calculate the rows again.
- calculatedRowCount = true;
- }
- return rowCount;
- }
-
- public void beforeFirst(long[] prefix, int suffixTruncation)
- throws TuplesException {
-
- // Get the subject/predicate before first.
- uniqueTuples.beforeFirst(prefix, suffixTruncation);
- baseTuples.beforeFirst(prefix, suffixTruncation);
- hasNext = uniqueTuples.next();
-
- while (hasNext &&
- ((uniqueTuples.getColumnValue(0) != uniqueTuples.getColumnValue(1)) ||
- (uniqueTuples.getColumnValue(1) != uniqueTuples.getColumnValue(2)))) {
- hasNext = uniqueTuples.next();
- }
-
- // Go to the first tuples.
- if (hasNext) {
- baseTuples.beforeFirst(new long[] { uniqueTuples.getColumnValue(0),
- uniqueTuples.getColumnValue(1), uniqueTuples.getColumnValue(2) },
- 0);
- }
- }
-
- public boolean next() throws TuplesException {
-
- // Check that there are more tuples - assume tuples are in order.
- if (hasNext) {
-
- boolean hasNextBase = baseTuples.next();
-
- // Check if we still have a match, if not get the next match.
- if (!hasNextBase ||
- !((uniqueTuples.getColumnValue(0) == baseTuples.getColumnValue(0)) &&
- (uniqueTuples.getColumnValue(1) == baseTuples.getColumnValue(1)) &&
- (uniqueTuples.getColumnValue(2) == baseTuples.getColumnValue(2)))) {
-
- // Get the next item to search.
- while (uniqueTuples.next()) {
-
- // Check to see that there is a next value. There will be at least
- // one value as the items to search are based on the original tuples.
- if ((uniqueTuples.getColumnValue(0) == uniqueTuples.getColumnValue(1)) &&
- (uniqueTuples.getColumnValue(1) == uniqueTuples.getColumnValue(2))) {
- baseTuples.beforeFirst(new long[] { uniqueTuples.getColumnValue(0),
- uniqueTuples.getColumnValue(1),
- uniqueTuples.getColumnValue(2) }, 0);
- hasNextBase = baseTuples.next();
- if (hasNextBase) {
- break;
- }
- }
- }
- }
- hasNext = hasNextBase;
- }
- return hasNext;
- }
- }
-
- /**
- * Returns the long representation of the constraint element or
- * NodePool.NONE if a variable.
- *
- * @param constraintElement the constraint element to resolve.
- * @throws TuplesException if the constraint element is not supported.
- * @return long the long representation of the constraint element.
- */
- protected static long toGraphTuplesIndex(ConstraintElement constraintElement)
- throws TuplesException {
- if (constraintElement instanceof Variable) {
- return NodePool.NONE;
- }
- if (constraintElement instanceof LocalNode) {
- return ((LocalNode) constraintElement).getValue();
- }
-
- throw new TuplesException("Unsupported constraint element: " +
- constraintElement + " (" + constraintElement.getClass() + ")");
- }
-}
Deleted: branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolutionUnitTest.java
===================================================================
--- branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolutionUnitTest.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreDuplicateResolutionUnitTest.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -1,405 +0,0 @@
-/*
- * 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): N/A.
- *
- * [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.store;
-
-import java.util.*;
-
-// JUnit
-import junit.framework.*;
-
-// Log4J
-import org.apache.log4j.Logger;
-
-// Local packages
-import org.mulgara.store.statement.*;
-import org.mulgara.store.tuples.LiteralTuples;
-import org.mulgara.store.tuples.Tuples;
-
-/**
- * Test case for {@link StatementStoreDuplicateResolution}.
- *
- * @created 2004-06-15
- *
- * @author Andrew Newman
- *
- * @version $Revision: 1.3 $
- *
- * @modified $Date: 2005/01/05 04:58:55 $
- *
- * @maintenanceAuthor $Author: newmana $
- *
- * @company <A href="mailto:info at PIsoftware.com">Plugged In Software</A>
- *
- * @copyright © 2003 <A href="http://www.PIsoftware.com/">Plugged In
- * Software Pty Ltd</A>
- *
- * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
- */
-public class StatementStoreDuplicateResolutionUnitTest extends TestCase {
-
- /**
- * Logger.
- */
- private Logger logger =
- Logger.getLogger(StatementStoreDuplicateResolutionUnitTest.class.getName());
-
- /**
- * Tuples for testing with.
- */
- private LiteralTuples t1, t2, t3, t4;
-
- /**
- * Constrained negation test tuples.
- */
- private StatementStoreDuplicateResolution tuples;
-
- /**
- * Constructs a new test with the given name.
- *
- * @param name the name of the test
- */
- public StatementStoreDuplicateResolutionUnitTest(String name) {
- super(name);
- }
-
- /**
- * Hook for test runner to obtain a test suite from.
- *
- * @return The test suite
- */
- public static Test suite() {
-
- TestSuite suite = new TestSuite();
-
- suite.addTest(new StatementStoreDuplicateResolutionUnitTest("testSubjectPredicate"));
- suite.addTest(new StatementStoreDuplicateResolutionUnitTest("testSubjectObject"));
- suite.addTest(new StatementStoreDuplicateResolutionUnitTest("testPredicateObject"));
- suite.addTest(new StatementStoreDuplicateResolutionUnitTest("testSubjectPredicateObject"));
-
- return suite;
- }
-
- /**
- * Create test instance.
- *
- * @throws Exception EXCEPTION TO DO
- */
- public void setUp() throws Exception {
-
- String[] var1 = new String[] { "x", "y", "z" };
- t1 = new LiteralTuples(var1);
- long[][] subjectTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 1, 3, 1 },
- new long[] { 1, 3, 4 },
- new long[] { 1, 4, 1 },
- new long[] { 2, 1, 4 },
- new long[] { 2, 2, 2 },
- new long[] { 2, 2, 3 },
- new long[] { 2, 2, 4 },
- new long[] { 2, 2, 5 },
- new long[] { 2, 3, 1 },
- new long[] { 3, 1, 1 },
- new long[] { 3, 1, 3 },
- new long[] { 3, 3, 3 },
- new long[] { 3, 2, 4 },
- new long[] { 4, 1, 1 },
- new long[] { 4, 4, 1 },
- new long[] { 4, 5, 4 },
- new long[] { 4, 5, 6 },
- new long[] { 4, 5, 7 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 7, 7 },
- new long[] { 7, 8, 1 },
- };
-
- for (int i = 0; i < subjectTuples.length; i++) {
- ((LiteralTuples) t1).appendTuple(subjectTuples[i]);
- }
-
- String[] var2 = new String[] { "y", "z", "x" };
- t2 = new LiteralTuples(var2);
- long[][] predicateTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 1, 1, 3 },
- new long[] { 1, 1, 4 },
- new long[] { 1, 3, 3 },
- new long[] { 1, 4, 2 },
- new long[] { 2, 2, 2 },
- new long[] { 2, 3, 2 },
- new long[] { 2, 4, 2 },
- new long[] { 2, 4, 3 },
- new long[] { 2, 5, 2 },
- new long[] { 3, 1, 1 },
- new long[] { 3, 1, 2 },
- new long[] { 3, 3, 3 },
- new long[] { 3, 4, 1 },
- new long[] { 4, 1, 1 },
- new long[] { 4, 1, 4 },
- new long[] { 5, 4, 4 },
- new long[] { 5, 6, 4 },
- new long[] { 5, 7, 4 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 7, 7 },
- new long[] { 8, 1, 7 },
- };
-
- for (int i = 0; i < predicateTuples.length; i++) {
- ((LiteralTuples) t2).appendTuple(predicateTuples[i]);
- }
-
- String[] var4 = new String[] { "x", "z", "y" };
- t4 = new LiteralTuples(var4);
- long[][] subjectObjectTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 1, 1, 3 },
- new long[] { 1, 1, 4 },
- new long[] { 1, 4, 3 },
- new long[] { 2, 1, 3 },
- new long[] { 2, 2, 2 },
- new long[] { 2, 3, 2 },
- new long[] { 2, 4, 1 },
- new long[] { 2, 4, 2 },
- new long[] { 2, 5, 2 },
- new long[] { 3, 1, 1 },
- new long[] { 3, 3, 1 },
- new long[] { 3, 3, 3 },
- new long[] { 3, 4, 2 },
- new long[] { 4, 1, 1 },
- new long[] { 4, 1, 4 },
- new long[] { 4, 4, 5 },
- new long[] { 4, 6, 5 },
- new long[] { 4, 7, 5 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 1, 8 },
- new long[] { 7, 7, 7 },
- };
-
- for (int i = 0; i < subjectObjectTuples.length; i++) {
- ((LiteralTuples) t4).appendTuple(subjectObjectTuples[i]);
- }
- }
-
- /**
- * Default text runner.
- *
- * @param args The command line arguments
- */
- public static void main(String[] args) {
-
- junit.textui.TestRunner.run(suite());
- }
-
- //
- // Test cases
- //
-
- /**
- * Test a constraint where the subject and predicate are the same.
- *
- * @throws Exception if query fails when it should have succeeded
- */
- public void testSubjectPredicate() throws Exception {
-
- // Not subject = 1.
- tuples = new StatementStoreDuplicateResolution(
- new boolean[] { true, true, false }, t1, new int[] { 0, 1, 2, 3});
-
- // Expected results
- long[][] expectedTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 2, 2, 2 },
- new long[] { 2, 2, 3 },
- new long[] { 2, 2, 4 },
- new long[] { 2, 2, 5 },
- new long[] { 3, 3, 3 },
- new long[] { 4, 4, 1 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 7, 7 },
- };
-
- testTuples(expectedTuples, tuples);
- }
-
- /**
- * Test a constraint where the predicate and object are the same.
- *
- * @throws Exception if query fails when it should have succeeded
- */
- public void testPredicateObject() throws Exception {
-
- // Not subject = 1.
- tuples = new StatementStoreDuplicateResolution(
- new boolean[] { false, true, true }, t2, new int[] { 1, 2, 0, 3});
-
- // Expected results
- long[][] expectedTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 1, 1, 3 },
- new long[] { 1, 1, 4 },
- new long[] { 2, 2, 2 },
- new long[] { 3, 3, 3 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 7, 7 },
- };
-
- testTuples(expectedTuples, tuples);
- }
-
- /**
- * Test a constraint where the subject and object are the same.
- *
- * @throws Exception if query fails when it should have succeeded
- */
- public void testSubjectObject() throws Exception {
-
- // Not subject = 1.
- tuples = new StatementStoreDuplicateResolution(
- new boolean[] { true, false, true }, t4, new int[] { 0, 2, 1, 3});
-
- // Expected results
- long[][] expectedTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 1, 1, 3 },
- new long[] { 1, 1, 4 },
- new long[] { 2, 2, 2 },
- new long[] { 3, 3, 1 },
- new long[] { 3, 3, 3 },
- new long[] { 4, 4, 5 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 7, 7 },
- };
-
- testTuples(expectedTuples, tuples);
- }
-
- /**
- * Test a constraint where the subject, predicate and object are the same.
- *
- * @throws Exception if query fails when it should have succeeded
- */
- public void testSubjectPredicateObject() throws Exception {
-
- // Not subject = 1.
- tuples = new StatementStoreDuplicateResolution(
- new boolean[] { true, true, true }, t1, new int[] { 0, 1, 2, 3});
-
- // Expected results
- long[][] expectedTuples = new long[][] {
- new long[] { 1, 1, 1 },
- new long[] { 2, 2, 2 },
- new long[] { 3, 3, 3 },
- new long[] { 5, 5, 5 },
- new long[] { 6, 6, 6 },
- new long[] { 7, 7, 7 },
- };
-
- testTuples(expectedTuples, tuples);
-
- String[] vars1a = new String[] { "x", "y", "z" };
- Tuples t1a = new LiteralTuples(vars1a);
- long[][] t1aTuples = new long[][] {
- new long[] { 3897, 3906, 3906 },
- new long[] { 3897, 3908, 3908 },
- new long[] { 3899, 3892, 3900 },
- new long[] { 3900, 3892, 3894 },
- new long[] { 3906, 3892, 3894 },
- new long[] { 3906, 3892, 3907 },
- new long[] { 3906, 3906, 3906 },
- new long[] { 3908, 3892, 3896 },
- new long[] { 3908, 3892, 3908 },
- new long[] { 3908, 3908, 3894 },
- new long[] { 3908, 3908, 3908 },
- new long[] { 3910, 3892, 3902 },
- new long[] { 3910, 3910, 3910 },
- new long[] { 3911, 3892, 3904 },
- new long[] { 3911, 3892, 3911 },
- };
-
- for (int i = 0; i < t1aTuples.length; i++) {
- ((LiteralTuples) t1a).appendTuple(t1aTuples[i]);
- }
-
- tuples = new StatementStoreDuplicateResolution(new boolean[] { true, true, true},
- t1a, new int[] { 0, 1, 2, 3});
-
- expectedTuples = new long[][] {
- new long[] { 3906, 3906, 3906 },
- new long[] { 3908, 3908, 3908 },
- new long[] { 3910, 3910, 3910 },
- };
-
- testTuples(expectedTuples, tuples);
- }
-
- /**
- * Test that we have the expected number and values of Tuples.
- *
- * @throws Exception if query fails when it should have succeeded
- */
- public void testTuples(long[][] expectedTuples, Tuples result)
- throws Exception {
-
- assertTrue("Expected: " + expectedTuples.length + ", " +
- result.getRowCount(), expectedTuples.length == result.getRowCount());
-
- if (result.getRowCount() > 0) {
- result.beforeFirst();
- result.next();
-
- int index = 0;
- do {
-
- long tuple[] = new long[] {
- result.getColumnValue(0),
- result.getColumnValue(1),
- result.getColumnValue(2)
- };
-
- assertTrue("Expected tuple result: " + expectedTuples[index][0] + "," +
- expectedTuples[index][1] + "," +
- expectedTuples[index][2] + " but was: " + tuple[0] + "," + tuple[1] +
- "," + tuple[2],
- expectedTuples[index][0] == tuple[0] &&
- expectedTuples[index][1] == tuple[1] &&
- expectedTuples[index][2] == tuple[2]);
- index++;
- tuples.next();
- }
- while (index < expectedTuples.length);
-
- assertFalse("Should be no more result tuples", tuples.next());
- }
- }
-}
Deleted: branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreInverseResolution.java
===================================================================
--- branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreInverseResolution.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreInverseResolution.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -1,670 +0,0 @@
-/*
- * 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):
- * getModel() contributed by Netymon Pty Ltd on behalf of
- * The Australian Commonwealth Government under contract 4500507038.
- *
- * [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.store;
-
-// Third party packages
-import org.apache.log4j.Logger;
-
-// Standard Java packages
-import java.util.*;
-
-// Locally written packages
-import org.mulgara.query.*;
-import org.mulgara.resolver.spi.Resolution;
-import org.mulgara.resolver.spi.Resolver;
-import org.mulgara.store.nodepool.NodePool;
-import org.mulgara.store.statement.StatementStore;
-import org.mulgara.store.statement.StatementStoreException;
-import org.mulgara.store.tuples.AbstractTuples;
-import org.mulgara.store.tuples.StoreTuples;
-import org.mulgara.store.tuples.Tuples;
-
-/**
- * Tuples backed by the graph, corresponding the tuples that don't match
- * a particular constraint. This class retains the original constraint so that
- * the graph index it's resolved against can be resolved anew as its variables
- * are bound.
- *
- * @created 2004-08-04
- *
- * @author Andrew Newman
- *
- * @version $Revision: 1.10 $
- *
- * @modified $Date: 2005/05/02 20:07:58 $ by $Author: raboczi $
- *
- * @maintenanceAuthor $Author: raboczi $
- *
- * @company <a href="mailto:info at PIsoftware.com">Plugged In Software</a>
- *
- * @copyright © 2003 <A href="http://www.PIsoftware.com/">Plugged In
- * Software Pty Ltd</A>
- *
- * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
- */
-class StatementStoreInverseResolution extends AbstractTuples implements Resolution {
-
- protected static final Logger logger = Logger.getLogger(StatementStoreInverseResolution.class);
-
- /**
- * The constraint these tuples were generated to satisfy.
- */
- protected Constraint constraint;
-
- /**
- * The graph from which these tuples were generated.
- */
- protected StatementStore store;
-
- /**
- * The tuples.
- */
- private Tuples tuples;
-
- /**
- * The long representation of the subject node or NodePool.NONE
- */
- private long subject;
-
- /**
- * The long representation of the predicate node or NodePool.NONE
- */
- private long predicate;
-
- /**
- * The long representation of the object node or NodePool.NONE
- */
- private long object;
-
- /**
- * The long representation of the meta node or NodePool.NONE
- */
- private long metanode;
-
- /**
- * Prefix. The prefix into the tuples to the section to exclude.
- */
- private long[] excludePrefix;
-
- /**
- * The not evaluator for a given tuples.
- */
- private TuplesEvaluator tuplesEvaluator;
-
- /**
- * Whether we've calculated the rows.
- */
- private boolean calculatedRowCount;
-
- /**
- * An array that contains the position in the tuples. Elements 0, 1, 2, 3
- * map to subject, predicate, object and meta and the value in the array is
- * the column position.
- */
- private int[] columnOrder;
-
- /**
- * True when we have skipped over the block in the store.
- */
- private boolean skipped = false;
-
- /**
- * True if all constraints are fixed.
- */
- private boolean allFixedConstraints;
-
- /**
- * True if a single statement given by the constraints exists.
- */
- private boolean singleStatementExists;
-
- /**
- * Used to force the tuples to act empty, used if beforeFirst is used with a bad prefix.
- */
- private boolean forceEmpty;
-
- /**
- * Find a graph index that satisfies a constraint.
- *
- * @param newConstraint the constraint to satisfy
- * @param newStore the store to resolve against
- * @throws IllegalArgumentException if <var>constraint</var> or <var>graph
- * </var> is <code>null</code>
- * @throws TuplesException EXCEPTION TO DO
- */
- StatementStoreInverseResolution(Constraint newConstraint, StatementStore newStore)
- throws TuplesException {
-
- if (newStore == null) {
- throw new IllegalArgumentException("Cannot give null statementstore");
- }
-
- constraint = newConstraint;
- store = newStore;
-
- subject = toGraphTuplesIndex(constraint.getElement(0));
- predicate = toGraphTuplesIndex(constraint.getElement(1));
- object = toGraphTuplesIndex(constraint.getElement(2));
- metanode = toGraphTuplesIndex(constraint.getModel());
-
- allFixedConstraints = (subject != NodePool.NONE) &&
- (predicate != NodePool.NONE) && (object != NodePool.NONE);
-
- forceEmpty = false;
-
- try {
-
- if (allFixedConstraints) {
- singleStatementExists = store.existsTriples(subject, predicate, object, metanode);
-
- // Return the tuples for a single model
- tuples = store.findTuples(false, false, false, true);
- tuples.beforeFirst(new long[] {metanode}, 0);
-
- } else {
-
- // Return the tuples using the s, p, o hints.
- tuples = store.findTuples(subject != NodePool.NONE,
- predicate != NodePool.NONE,
- object != NodePool.NONE,
- metanode != NodePool.NONE);
-
- if (metanode != NodePool.NONE) {
- // go to the beginning of the fixed model
- tuples.beforeFirst(new long[] {metanode}, 0);
- } else {
- // go to the beginning of all models
- tuples.beforeFirst();
- }
- }
-
- // Get the column order - this is column index -> tuples index we want
- // tuple index -> column index
- int[] inverseColumnOrder = ((StoreTuples) tuples).getColumnOrder();
-
- columnOrder = new int[4];
-
- // Create column map.
- for (int index = 0; index < inverseColumnOrder.length; index++) {
- columnOrder[inverseColumnOrder[index]] = index;
- }
-
- // Prepopulate variable list.
- List variableList = new ArrayList(Arrays.asList(StatementStore.VARIABLES));
- boolean changedList = false;
-
- // Create correct variable bindings in order.
- for (int index = 0; index < 4; index++) {
- if (constraint.getElement(index) instanceof Variable) {
- Variable var = (Variable) constraint.getElement(index);
- if (!var.equals(Variable.FROM)) {
-
- // Remove it from it's position in the list and re-add it with the
- // correct value.
- changedList = true;
- variableList.remove(columnOrder[index]);
- variableList.add(columnOrder[index], var);
- }
- }
- }
-
- setTuplesEvaluator();
- setVariables(variableList);
- }
- catch (StatementStoreException se) {
- throw new TuplesException("Failed to set-up tuples", se);
- }
-
- }
-
- /**
- * Create the appropriate tuples evaluator.
- */
- private void setTuplesEvaluator() {
-
- if (((subject != NodePool.NONE) && (predicate == NodePool.NONE) && (object == NodePool.NONE)) ||
- ((subject != NodePool.NONE) && (predicate != NodePool.NONE) && (object == NodePool.NONE)) ||
- ((subject != NodePool.NONE) && (predicate != NodePool.NONE) && (object != NodePool.NONE))) {
- tuplesEvaluator = new SPOTuplesEvaluator();
-
- if ((subject != NodePool.NONE) && (predicate == NodePool.NONE) && (object == NodePool.NONE)) {
- excludePrefix = new long[] { subject };
- }
- else if ((subject != NodePool.NONE) && (predicate != NodePool.NONE) && (object == NodePool.NONE)) {
- excludePrefix = new long[] { subject, predicate };
- }
- else if ((subject != NodePool.NONE) && (predicate != NodePool.NONE) && (object != NodePool.NONE)) {
- excludePrefix = new long[] { subject, predicate, object };
- }
- }
- else if (((subject == NodePool.NONE) && (predicate != NodePool.NONE) && (object == NodePool.NONE)) ||
- ((subject == NodePool.NONE) && (predicate != NodePool.NONE) && (object != NodePool.NONE))) {
- tuplesEvaluator = new POSTuplesEvaluator();
- if ((subject == NodePool.NONE) && (predicate != NodePool.NONE) && (object == NodePool.NONE)) {
- excludePrefix = new long[] { predicate };
- }
- else if ((subject == NodePool.NONE) && (predicate != NodePool.NONE) && (object != NodePool.NONE)) {
- excludePrefix = new long[] { predicate, object };
- }
- }
- else if ((subject == NodePool.NONE) && (predicate == NodePool.NONE) && (object != NodePool.NONE)) {
- tuplesEvaluator = new OSPTuplesEvaluator();
- excludePrefix = new long[] { object };
- }
- else if ((subject != NodePool.NONE) && (predicate == NodePool.NONE) && (object != NodePool.NONE)) {
- tuplesEvaluator = new SOPTuplesEvaluator();
- excludePrefix = new long[] { subject, object };
- }
- else if ((subject == NodePool.NONE) && (predicate == NodePool.NONE) && (object == NodePool.NONE)) {
- tuplesEvaluator = new UnconstrainedTuplesEvaluator();
- excludePrefix = new long[] {};
- }
-
- // prepend the metanode if it is set
- if (metanode != NodePool.NONE) {
- long[] newPrefix = new long[excludePrefix.length + 1];
- newPrefix[0] = metanode;
- for (int i = 0; i < excludePrefix.length; i++) {
- newPrefix[i + 1] = excludePrefix[i];
- }
- excludePrefix = newPrefix;
- }
- }
-
- public long getRowCount() throws TuplesException {
-
- // Only calculate rows once.
- if (!calculatedRowCount) {
-
- // If the exclude prefix is more than just the model then calculate otherwise we've asked
- // for a NOT ($s $p $o) which is 0.
- if (excludePrefix.length > 1) {
-
- Tuples modelTuples = null;
- Tuples excludedTuples = null;
-
- try {
- // get all tuples in the model
- modelTuples = store.findTuples(NodePool.NONE, NodePool.NONE, NodePool.NONE, metanode);
-
- // get excluded tuples in the model
- excludedTuples = store.findTuples(subject, predicate, object, metanode);
-
- // Calculated the excluded set from the model.
- rowCount = modelTuples.getRowCount() - excludedTuples.getRowCount();
-
- } catch (StatementStoreException e) {
- throw new TuplesException("Unable to count data", e);
- } finally {
- try {
- if (modelTuples != null) {
- modelTuples.close();
- }
- } finally {
- if (excludedTuples != null) {
- excludedTuples.close();
- }
- }
- }
-
- } else {
- rowCount = 0;
- }
-
- // Ensure we don't calculate the rows again.
- calculatedRowCount = true;
- }
- return rowCount;
- }
-
- public boolean hasNoDuplicates() throws TuplesException {
- return tuples.hasNoDuplicates();
- }
-
- public List getOperands() {
- return new ArrayList();
- }
-
- public void beforeFirst(long[] prefix, int suffixTruncation) throws TuplesException {
- if (prefix.length > 4) {
- throw new TuplesException("Prefix too long");
- }
-
- // Reset skipped.
- skipped = false;
- // Reset the forceEmpty flag
- forceEmpty = false;
-
- if (metanode != NodePool.NONE) {
- if (prefix.length > 0) {
- if (prefix[0] != metanode) {
- // no matching tuples
- forceEmpty = true;
- }
- } else {
- prefix = new long[] {metanode};
- }
- }
-
- // Move to the
- tuples.beforeFirst(prefix, suffixTruncation);
- }
-
- public void close() throws TuplesException {
- if (tuples != null) {
- tuples.close();
- }
- }
-
- /**
- * METHOD TO DO
- *
- * @return RETURNED VALUE TO DO
- */
- public Object clone() {
- StatementStoreInverseResolution cloned = (StatementStoreInverseResolution) super.clone();
- cloned.tuples = (Tuples) tuples.clone();
- cloned.setVariables(getVariables());
-
- // Create a new tuples evaluator.
- cloned.setTuplesEvaluator();
- return cloned;
- }
-
-
- public long getRowUpperBound() throws TuplesException {
- return getRowCount();
- }
-
- public int getRowCardinality() throws TuplesException {
- long count = getRowCount();
- if (count > 1) {
- return Cursor.MANY;
- }
- switch ((int) count) {
- case 0:
- return Cursor.ZERO;
- case 1:
- return Cursor.ONE;
- default:
- throw new TuplesException("Illegal row count: " + count);
- }
- }
-
- public long getColumnValue(int column) throws TuplesException {
- return tuples.getColumnValue(column);
- }
-
- public boolean isColumnEverUnbound(int column) throws TuplesException {
- return tuples.isColumnEverUnbound(column);
- }
-
- public boolean isUnconstrained() throws TuplesException {
-
- // If we have a least one variable return the tuples isUnconstrainedValue.
- if (!allFixedConstraints) {
- return tuples.isUnconstrained();
- }
- else {
-
- // If the statement exists we are constrained.
- if (singleStatementExists) {
- return false;
- }
- else {
- return true;
- }
- }
- }
-
- public boolean isMaterialized() {
- return tuples.isMaterialized();
- }
-
- public boolean next() throws TuplesException {
- boolean hasNext = false;
- if (!forceEmpty) {
- hasNext = tuplesEvaluator.next();
- }
- return hasNext;
- }
-
- /**
- * @return the original {@link Constraint} passed to the
- * {@link Resolver#resolve} method to generate this {@link Resolution}
- */
- public Constraint getConstraint() {
- return constraint;
- }
-
-
- /**
- * If a {@link Resolver} represents a closed world, it may assert that the
- * {@link Resolution} contains every possible solution.
- *
- * @return whether this {@link Resolution} includes every solution to the constraint
- */
- public boolean isComplete() {
- return true;
- }
-
-
- public String toString() {
- return "not " + tuples.toString() + " from constraint " + constraint;
- }
-
- /**
- * Returns the long representation of the constraint element or
- * NodePool.NONE if a variable.
- *
- * @param constraintElement the constraint element to resolve.
- * @throws TuplesException if the constraint element is not supported.
- * @return long the long representation of the constraint element.
- */
- protected static long toGraphTuplesIndex(ConstraintElement constraintElement)
- throws TuplesException {
- if (constraintElement instanceof Variable) {
- return NodePool.NONE;
- }
- if (constraintElement instanceof LocalNode) {
- return ((LocalNode) constraintElement).getValue();
- }
-
- throw new TuplesException("Unsupported constraint element: " +
- constraintElement + " (" + constraintElement.getClass() + ")");
- }
-
- /**
- * A decorator around the next() method on a tuples that skips a set of
- * statements if they are given in the constraint.
- */
- private interface TuplesEvaluator {
-
- /**
- * Returns true if there is another tuples. Calling next may skip a set
- * of tuples based on the constraint.
- *
- * @throws TuplesException if there was a problem accessing the tuples.
- * @return true if there is another tuples.
- */
- public boolean next() throws TuplesException;
- }
-
- /**
- * The evaluator for the S, P, O constrained tuples.
- */
- private class SPOTuplesEvaluator implements TuplesEvaluator {
-
- public boolean next() throws TuplesException {
-
- // Iterate forward one.
- boolean moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
-
- // If we've skipped over the tuples then just call the normal tuples.next.
- if (!skipped) {
-
- // Assume that the subject is always bound - otherwise wouldn't be used.
- // If the predicate is also constrained iterate through these.
- if (predicate != NodePool.NONE) {
-
- // If the predicate is also constrained iterate through these.
- if (object != NodePool.NONE) {
-
- // If we match then skip over the totally constrained tuple.
- if ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[0]) == subject) &&
- (tuples.getColumnValue(columnOrder[1]) == predicate) &&
- (tuples.getColumnValue(columnOrder[2]) == object)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- else {
-
- // Skip over all the objects for the given subject, predicate.
- while ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[0]) == subject) &&
- (tuples.getColumnValue(columnOrder[1]) == predicate)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- }
- else {
-
- // Skip over all the predicate, objects for the given subject.
- while ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[0]) == subject)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- }
- return moreTuples;
- }
- }
-
- /**
- * The evaluator for the P, O, S constrained tuples.
- */
- private class POSTuplesEvaluator implements TuplesEvaluator {
-
- public boolean next() throws TuplesException {
-
- // Iterate forward one.
- boolean moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
-
- // If we've skipped over the tuples then just call the normal tuples.next.
- if (!skipped) {
-
- // If the object is also constrained iterate through these.
- if (object != NodePool.NONE) {
-
- // Skip over all the subjects for the given predicate, objects.
- while ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[1]) == predicate) &&
- (tuples.getColumnValue(columnOrder[2]) == object)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- else {
-
- // Skip over all the object, subjects for the given predicate.
- while ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[1]) == predicate)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- }
- return moreTuples;
- }
- }
-
- /**
- * The evaluator for the O, S, P constrained tuples.
- */
- private class OSPTuplesEvaluator implements TuplesEvaluator {
-
- public boolean next() throws TuplesException {
-
- // Iterate forward one.
- boolean moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
-
- // If we've skipped over the tuples then just call the normal tuples.next.
- if (!skipped) {
-
- // Skip over all the subject, predicates for the given object.
- while ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[2]) == object)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- return moreTuples;
- }
- }
-
- /**
- * The evaluator for the S, O, P constrained tuples.
- */
- private class SOPTuplesEvaluator implements TuplesEvaluator {
-
- public boolean next() throws TuplesException {
-
- // Iterate forward one.
- boolean moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
-
- // If we've skipped over the tuples then just call the normal tuples.next.
- if (!skipped) {
-
- // Skip over all the subject, predicates for the given object.
- while ((moreTuples) &&
- (tuples.getColumnValue(columnOrder[0]) == subject) &&
- (tuples.getColumnValue(columnOrder[2]) == object)) {
- moreTuples = tuples.next() && tuples.getColumnValue(columnOrder[3]) == metanode;
- skipped = true;
- }
- }
- return moreTuples;
- }
- }
-
- /**
- * The evaluator when none of the tuples are constrained.
- */
- private class UnconstrainedTuplesEvaluator implements TuplesEvaluator {
-
- public boolean next() throws TuplesException {
- return false;
- }
- }
-}
Modified: branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreResolver.java
===================================================================
--- branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreResolver.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/resolver-store/java/org/mulgara/resolver/store/StatementStoreResolver.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -391,8 +391,6 @@
if (!constraint.isRepeating()) {
if (constraint instanceof ConstraintImpl) {
return new StatementStoreResolution(constraint, statementStore);
- } else if (constraint instanceof ConstraintNegation) {
- return new StatementStoreInverseResolution(constraint, statementStore);
} else {
throw new QueryException("Unable to resolve constraint " + constraint + " unknown type");
}
Modified: branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java
===================================================================
--- branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java 2008-12-03 00:00:16 UTC (rev 1391)
+++ branches/xa11/src/jar/resolver-store/java/org/mulgara/store/statement/xa11/XA11StatementStoreImpl.java 2008-12-03 00:00:56 UTC (rev 1392)
@@ -1357,7 +1357,7 @@
return TuplesOperations.empty();
}
- if (0 == (variableMask & MASK3)) throw new StatementStoreException("This version of find is for re-ordering graphs, base on a given mask.");
+ if (0 == (variableMask & MASK3)) throw new StatementStoreException("This version of find is for re-ordering graphs, based on a given mask.");
try {
switch (variableMask) {
case MASK3:
More information about the Mulgara-svn
mailing list