[Mulgara-svn] r918 - in trunk/src/jar: . resolver-null resolver-null/java resolver-null/java/org resolver-null/java/org/mulgara resolver-null/java/org/mulgara/resolver resolver-null/java/org/mulgara/resolver/nullres
pag at mulgara.org
pag at mulgara.org
Wed May 14 03:06:37 UTC 2008
Author: pag
Date: 2008-05-13 20:06:37 -0700 (Tue, 13 May 2008)
New Revision: 918
Added:
trunk/src/jar/resolver-null/
trunk/src/jar/resolver-null/build.xml
trunk/src/jar/resolver-null/java/
trunk/src/jar/resolver-null/java/org/
trunk/src/jar/resolver-null/java/org/mulgara/
trunk/src/jar/resolver-null/java/org/mulgara/resolver/
trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/
trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolution.java
trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolver.java
trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolverFactory.java
trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/package.html
trunk/src/jar/resolver-null/resolver-null-build.properties
Log:
New NULL resolver for appearing as an always empty graph
Added: trunk/src/jar/resolver-null/build.xml
===================================================================
--- trunk/src/jar/resolver-null/build.xml (rev 0)
+++ trunk/src/jar/resolver-null/build.xml 2008-05-14 03:06:37 UTC (rev 918)
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE project>
+
+<project name="resolver-null" default="resolver-null-jar" basedir="../../..">
+
+ <path id="resolver-null-classpath">
+
+ <path refid="common-classpath"/>
+ <fileset file="${query.dist.dir}/${query.jar}"/>
+ <fileset file="${resolver-spi.dist.dir}/${resolver-spi.jar}"/>
+ <fileset file="${tuples.dist.dir}/${tuples.jar}"/>
+ <fileset file="${util.dist.dir}/${util.jar}"/>
+ </path>
+
+ <path id="resolver-null-test-classpath">
+ <path refid="resolver-null-classpath"/>
+ <fileset file="${resolver-null.dist.dir}/${resolver-null.jar}"/>
+ </path>
+
+ <target name="resolver-null-clean" description="Removes all compile generated files for the resolver-null">
+ <tstamp/>
+ <delete dir="${resolver-null.obj.dir}"/>
+ <delete dir="${resolver-null.test.dir}"/>
+ <delete dir="${resolver-null.dist.dir}"/>
+ </target>
+
+ <target name="-resolver-null-prepare" description="Creates all directories associated with the resolver-null's compilation"
+ depends="-prepare-build">
+ <mkdir dir="${resolver-null.obj.dir}"/>
+ <mkdir dir="${resolver-null.test.dir}"/>
+ <mkdir dir="${resolver-null.dist.dir}"/>
+ <mkdir dir="${resolver-null.obj.dir}/classes"/>
+ </target>
+
+ <target name="resolver-null-compile" depends="-resolver-null-prepare, resolver-spi-jar, util-jar"
+ description="Compiles all resolver-null related files included generated source code">
+ <javac destdir="${resolver-null.obj.dir}/classes" debug="on" deprecation="on" source="1.5">
+ <classpath refid="resolver-null-classpath"/>
+ <src path="${resolver-null.src.dir}/java"/>
+ </javac>
+ </target>
+
+ <target name="resolver-null-jar" depends="resolver-null-compile, -resolver-null-jar-uptodate"
+ unless="resolver-null.jar.uptodate" description="Builds the File Resolver JAR">
+ <jar jarfile="${resolver-null.dist.dir}/${resolver-null.jar}">
+ <fileset dir="${resolver-null.obj.dir}/classes"/>
+ </jar>
+ </target>
+
+ <target name="-resolver-null-jar-uptodate">
+ <uptodate property="resolver-null.jar.uptodate" targetfile="${resolver-null.dist.dir}/${resolver-null.jar}">
+ <srcfiles dir="${resolver-null.obj.dir}/classes" includes="**/*"/>
+ </uptodate>
+ </target>
+
+ <target name="resolver-null-dist" depends="resolver-null-jar" unless="resolver-null.uptodate"
+ description="Performs all tasks related to finalising this resolver-null and readying it for distribution">
+ </target>
+
+ <target name="resolver-null-test" depends="resolver-null-jar">
+ <antcall target="component-test">
+ <param name="classpath.id" value="resolver-null-classpath"/>
+ <param name="dir" value="${resolver-null.src.dir}"/>
+ <param name="jar" value="${resolver-null.jar}"/>
+ </antcall>
+ </target>
+
+ <target name="resolver-null-javadoc" depends="resolver-null-jar" description="Creates the javadoc for this resolver-null">
+ <antcall target="javadoc">
+ <param name="javadoc.package" value="org.mulgara.resolver.file.*"/>
+ <param name="javadoc.classpath" value="resolver-null-classpath"/>
+ <param name="javadoc.sourcepath" value="${resolver-null.src.dir}/java"/>
+ </antcall>
+ </target>
+
+ <target name="resolver-null-help" description="Displays the help information for this resolver-null">
+ <echo message="Welcome to the build script for ${resolver-null.name}."/>
+ <echo message=""/>
+ <echo message="These targets can be invoked as follows:"/>
+ <echo message=" ./build.sh <target>"/>
+ <echo message=""/>
+ <java fork="false" classname="org.apache.tools.ant.Main" newenvironment="false">
+ <jvmarg value="${arch.bits}"/>
+ <arg line="-buildfile ${resolver-null.src.dir}/build.xml -projecthelp"/>
+ </java>
+ </target>
+
+</project>
Added: trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolution.java
===================================================================
--- trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolution.java (rev 0)
+++ trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolution.java 2008-05-14 03:06:37 UTC (rev 918)
@@ -0,0 +1,207 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (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.opensource.org/licenses/osl-3.0.txt
+ *
+ * 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.
+ */
+
+package org.mulgara.resolver.nullres;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.mulgara.query.Constraint;
+import org.mulgara.query.TuplesException;
+import org.mulgara.query.Variable;
+import org.mulgara.resolver.spi.Resolution;
+import org.mulgara.store.tuples.Annotation;
+import org.mulgara.store.tuples.RowComparator;
+import org.mulgara.store.tuples.Tuples;
+
+/**
+ * An empty set of results, equivalent to {@link org.mulgara.store.tuples.EmptyTuples}.
+ *
+ * @created May 8, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class NullResolution implements Resolution {
+
+ /** Logger. */
+ private static Logger logger = Logger.getLogger(NullResolver.class.getName());
+
+ /** The constraint. */
+ private final Constraint constraint;
+
+ /**
+ * Constructs this resolution around a constraint.
+ * @param constraint The constraint that resulted in this empty resolution.
+ */
+ NullResolution(Constraint constraint) {
+ this.constraint = constraint;
+ }
+
+ /** @see org.mulgara.resolver.spi.Resolution#getConstraint() */
+ public Constraint getConstraint() {
+ return constraint;
+ }
+
+ /** @see org.mulgara.resolver.spi.Resolution#isComplete() */
+ public boolean isComplete() {
+ return true;
+ }
+
+ /** @see org.mulgara.store.tuples.Tuples#beforeFirst(long[], int) */
+ public void beforeFirst(long[] prefix, int suffixTruncation) throws TuplesException {
+ // no-op
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getAnnotation(java.lang.Class)
+ * @return Always <code>null</code>.
+ */
+ public Annotation getAnnotation(Class<?> annotationClass) throws TuplesException {
+ return null;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getColumnIndex(org.mulgara.query.Variable)
+ * @throws TuplesException Always thrown, as this result has no variables.
+ */
+ public int getColumnIndex(Variable variable) throws TuplesException {
+ throw new TuplesException("variable doesn't match any column");
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getColumnValue(int)
+ * @throws TuplesException Always thrown, as this result has no columns.
+ */
+ public long getColumnValue(int column) throws TuplesException {
+ throw new TuplesException("Column index out of range: " + column);
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getComparator()
+ * @return Always <code>null</code>.
+ */
+ public RowComparator getComparator() {
+ return null;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getOperands()
+ * @return An empty list.
+ */
+ public List<Tuples> getOperands() {
+ return Collections.emptyList();
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getRawColumnValue(int)
+ * @throws TuplesException Always thrown, as this result has no columns.
+ */
+ public long getRawColumnValue(int column) throws TuplesException {
+ throw new TuplesException("Column index out of range: " + column);
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getRowCount()
+ * @return Always 0 rows.
+ */
+ public long getRowCount() throws TuplesException {
+ return 0;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#getVariables()
+ * @return an empty {@link Variable} array.
+ */
+ public Variable[] getVariables() {
+ return new Variable[0];
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#hasNoDuplicates()
+ * @return Always <code>true</code> as there are no duplicates when there is no data.
+ */
+ public boolean hasNoDuplicates() throws TuplesException {
+ return true;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#isColumnEverUnbound(int)
+ * @return Always <code>false</code> as there are no variables.
+ */
+ public boolean isColumnEverUnbound(int column) throws TuplesException {
+ return false;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#isMaterialized()
+ * @return Always <code>true</code> as this is no need to materialize.
+ */
+ public boolean isMaterialized() {
+ return true;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#isUnconstrained()
+ * @return Always <code>false</code> as there are no variables.
+ */
+ public boolean isUnconstrained() throws TuplesException {
+ return false;
+ }
+
+ /**
+ * @see org.mulgara.store.tuples.Tuples#next()
+ * @return Always <code>false</code> to indicate no data.
+ */
+ public boolean next() throws TuplesException {
+ return false;
+ }
+
+ /** @see org.mulgara.store.tuples.Tuples#renameVariables(org.mulgara.query.Constraint) */
+ public void renameVariables(Constraint constraint) { /* no-op */ }
+
+ /** @see org.mulgara.query.Cursor#beforeFirst() */
+ public void beforeFirst() throws TuplesException { /* no-op */ }
+
+ /** @see org.mulgara.query.Cursor#close() */
+ public void close() throws TuplesException { /* no-op */ }
+
+ /** @see org.mulgara.query.Cursor#getNumberOfVariables() */
+ public int getNumberOfVariables() {
+ return 0;
+ }
+
+ /** @see org.mulgara.query.Cursor#getRowCardinality() */
+ public int getRowCardinality() throws TuplesException {
+ return 0;
+ }
+
+ /** @see org.mulgara.query.Cursor#getRowUpperBound() */
+ public long getRowUpperBound() throws TuplesException {
+ return 0;
+ }
+
+ /**
+ * All implementations must support cloning.
+ * @return the cloned instance
+ */
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ logger.error("Unexpected cloning error", e);
+ return new NullResolution(constraint);
+ }
+ }
+
+}
Added: trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolver.java
===================================================================
--- trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolver.java (rev 0)
+++ trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolver.java 2008-05-14 03:06:37 UTC (rev 918)
@@ -0,0 +1,103 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (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.opensource.org/licenses/osl-3.0.txt
+ *
+ * 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.
+ */
+
+package org.mulgara.resolver.nullres;
+
+// Java 2 standard packages
+import java.net.URI;
+
+import javax.transaction.xa.XAResource;
+
+// Third party packages
+import org.apache.log4j.Logger;
+
+// Locally written packages
+import org.mulgara.query.Constraint;
+import org.mulgara.query.QueryException;
+import org.mulgara.query.TuplesException;
+import org.mulgara.resolver.spi.*;
+
+/**
+ * A resolver for accepting and discarding any data and returning valid empty results.
+ *
+ * @created May 8, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class NullResolver implements Resolver {
+ /** Logger. */
+ private static Logger logger = Logger.getLogger(NullResolver.class.getName());
+
+ /** The URI of the type describing null type graphs. */
+ private URI graphTypeUri;
+
+ /**
+ * Construct a null resolver.
+ * @param graphTypeUri The URI representing the NULL graph type.
+ * @throws IllegalArgumentException if <var>graphTypeUri</var> is <code>null</code>
+ */
+ NullResolver(URI graphTypeUri) {
+ if (graphTypeUri == null) throw new IllegalArgumentException("Null graph type provided.");
+ this.graphTypeUri = graphTypeUri;
+ }
+
+ /**
+ * @see org.mulgara.resolver.spi.Resolver#createModel(long, java.net.URI)
+ * Do nothing.
+ */
+ public void createModel(long graph, URI graphType) throws ResolverException, LocalizeException {
+ if (logger.isDebugEnabled()) logger.debug("createGraph called on Null resolver: graph gNode=" + graph);
+ if (!graphTypeUri.equals(graphType)) {
+ throw new ResolverException("Wrong graph type provided as a Null graph");
+ }
+ }
+
+ /**
+ * @see org.mulgara.resolver.spi.Resolver#modifyModel(long, org.mulgara.resolver.spi.Statements, boolean)
+ * Do nothing. If the statements that are being ignored cannot be accessed, then report the problem.
+ */
+ public void modifyModel(long graph, Statements statements, boolean occurs) throws ResolverException {
+ if (logger.isDebugEnabled()) {
+ try {
+ logger.debug((occurs ? "adding" : "removing") + " up to "+ statements.getRowUpperBound() + " statements");
+ } catch (TuplesException e) {
+ logger.warn("Called modifyGraph on Null graph with bad statements", e);
+ }
+ }
+ }
+
+ /**
+ * @see org.mulgara.resolver.spi.Resolver#removeModel(long)
+ * Do nothing.
+ */
+ public void removeModel(long graph) throws ResolverException {
+ if (logger.isDebugEnabled()) logger.debug("calling removeGraph from Null resolver: graph gNode=" + graph);
+ }
+
+ /**
+ * @see org.mulgara.resolver.spi.Resolver#resolve(org.mulgara.query.Constraint)
+ * Return empty results.
+ */
+ public Resolution resolve(Constraint constraint) throws QueryException {
+ return new NullResolution(constraint);
+ }
+
+ /** @see org.mulgara.resolver.spi.EnlistableResource#abort() */
+ public void abort() { /* no-op */ }
+
+ /** @see org.mulgara.resolver.spi.EnlistableResource#getXAResource() */
+ public XAResource getXAResource() {
+ return new DummyXAResource(10);
+ }
+
+}
Added: trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolverFactory.java
===================================================================
--- trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolverFactory.java (rev 0)
+++ trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/NullResolverFactory.java 2008-05-14 03:06:37 UTC (rev 918)
@@ -0,0 +1,90 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (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.opensource.org/licenses/osl-3.0.txt
+ *
+ * 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.
+ */
+
+package org.mulgara.resolver.nullres;
+
+// Third party packages
+import java.net.URI;
+
+import org.apache.log4j.Logger;
+
+// Locally written packages
+import org.mulgara.query.rdf.Mulgara;
+import org.mulgara.resolver.spi.*;
+
+/**
+ * The registered factory for creating a Null resolver.
+ *
+ * @created May 8, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class NullResolverFactory implements ResolverFactory {
+ /** Logger. */
+ @SuppressWarnings("unused")
+ private static Logger logger = Logger.getLogger(NullResolverFactory.class.getName());
+
+ /** The URI to be used for a null graph */
+ public final static URI DEFAULT_GRAPH = URI.create(Mulgara.NULL_GRAPH);
+
+ /** The URI for the graphType. */
+ private static final URI nullTypeURI = URI.create(Mulgara.NAMESPACE + "Null");
+
+ /**
+ * Instantiate a {@link NullResolverFactory}.
+ */
+ private NullResolverFactory(ResolverFactoryInitializer resolverFactoryInitializer) throws InitializerException {
+ // Validate "resolverFactoryInitializer" parameter
+ if (resolverFactoryInitializer == null) throw new IllegalArgumentException("Null \"resolverFactoryInitializer\" parameter");
+
+ // No need to claim the type supported by the resolver as this is detected in the default graph
+ }
+
+ /** {@inheritDoc ResolverFactory} */
+ public void close() {
+ // null implementation
+ }
+
+ /** {@inheritDoc ResolverFactory} */
+ public void delete() {
+ // null implementation
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return <code>null</code> - no default graphs for this resolver
+ */
+ public Graph[] getDefaultGraphs() {
+ return new Graph[] { new Graph(DEFAULT_GRAPH, nullTypeURI) };
+ }
+
+ /**
+ * Register this resolver upon database startup.
+ * @param resolverFactoryInitializer The database within which to find or create the various XML Schema resources
+ * @throws InitializerException If the XML Schema resources can't be found or created
+ */
+ public static ResolverFactory newInstance(ResolverFactoryInitializer resolverFactoryInitializer) throws InitializerException {
+ return new NullResolverFactory(resolverFactoryInitializer);
+ }
+
+ /**
+ * Obtain a file resolver.
+ * @param resolverSession the session which this query is local to
+ * @param canWrite {@inheritDoc}; ignored in this implementation
+ * @throws IllegalArgumentException if <var>resolverSession</var> is <code>null</code>
+ * @throws ResolverFactoryException {@inheritDoc}
+ */
+ public Resolver newResolver(boolean canWrite, ResolverSession resolverSession, Resolver systemResolver) throws ResolverFactoryException {
+ return new NullResolver(nullTypeURI);
+ }
+}
Added: trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/package.html
===================================================================
--- trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/package.html (rev 0)
+++ trunk/src/jar/resolver-null/java/org/mulgara/resolver/nullres/package.html 2008-05-14 03:06:37 UTC (rev 918)
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>Null Resolver</title>
+</head>
+<body>
+<abstract>
+Null Resolver.
+</abstract>
+<p>
+This package is a basic resolver that discards written data, and always resolves to an empty set.
+</p>
+</body>
+</html>
Added: trunk/src/jar/resolver-null/resolver-null-build.properties
===================================================================
--- trunk/src/jar/resolver-null/resolver-null-build.properties (rev 0)
+++ trunk/src/jar/resolver-null/resolver-null-build.properties 2008-05-14 03:06:37 UTC (rev 918)
@@ -0,0 +1,11 @@
+# Module Name
+resolver-null.name = Null Resolver
+
+# General module properties
+resolver-null.conf.dir = ${resolver.conf.dir}/null
+resolver-null.src.dir = ${jar.src.dir}/resolver-null
+resolver-null.obj.dir = ${jar.obj.dir}/resolver-null
+resolver-null.dist.dir = ${bin.dir}
+resolver-null.test.dir = ${test.dir}/resolver-null
+resolver-null.jxtest.dir = ${jxtest.dir}/resolver-null
+resolver-null.jar = resolver-null-base-${mulgara-version}.jar
More information about the Mulgara-svn
mailing list