You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/04/23 21:56:54 UTC
[38/51] [partial] jena git commit: Rename com.hp.hpl.jena.* as
org.apache.jena.*
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphAltDefaultGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphAltDefaultGraph.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphAltDefaultGraph.java
deleted file mode 100644
index 0e1ea81..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphAltDefaultGraph.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-
-/** DatasetGraph that switches the default graph to another graph.
- * This different graph can be one of the underlying dataset or a completely
- * unconnected graph.
- * This wrapper should used with care at scale because it masks the
- * query execution from storage, so generic query execution happens,
- * not, for example, TDB quad execution.
- */
-
-public class DatasetGraphAltDefaultGraph extends DatasetGraphCollection {
- private Graph defaultGraph ;
- private final DatasetGraph dsg ;
-
- public DatasetGraphAltDefaultGraph(DatasetGraph dsg, Graph defaultGraph) {
- this.defaultGraph = defaultGraph ;
- this.dsg = dsg ;
- }
-
- @Override
- public Iterator<Node> listGraphNodes() {
- return dsg.listGraphNodes() ;
- }
-
- @Override
- public Graph getDefaultGraph() {
- return defaultGraph ;
- }
-
- @Override
- public Graph getGraph(Node graphNode) {
- return dsg.getGraph(graphNode) ;
- }
-
- @Override
- public void addGraph(Node graphName, Graph graph) { dsg.addGraph(graphName, graph); }
-
- @Override
- public void removeGraph(Node graphName) { dsg.removeGraph(graphName); }
-}
-
-
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBase.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBase.java
deleted file mode 100644
index 10d93d1..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBase.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.io.IndentedLineBuffer ;
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.Transform ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.shared.Lock ;
-import com.hp.hpl.jena.shared.LockMRSW ;
-import com.hp.hpl.jena.sparql.sse.writers.WriterGraph ;
-import com.hp.hpl.jena.sparql.util.Context ;
-
-/**
- * <p>DatasetGraph framework : readonly dataset need only provide find(g,s,p,o), getGraph() and getDefaultGraph()
- * although it may wish to override other operations and do better.</p>
- *
- * <p>Other implementations include:</p>
- * <ul>
- * <li>{@link DatasetGraphBase} that adds an implementation of find based on default / named graphs.</li>
- * <li>{@link DatasetGraphCollection} that adds mutating quad operations mapped to a collection of graphs.</li>
- * <li>{@link DatasetGraphQuad} that maps graph operations to a quad view.
- * </ul>
- */
-abstract public class DatasetGraphBase implements DatasetGraph
-{
- private final Lock lock = new LockMRSW() ;
- private Context context = new Context() ;
-
- protected DatasetGraphBase() {}
-
- @Override
- public boolean containsGraph(Node graphNode)
- { return contains(graphNode, Node.ANY, Node.ANY, Node.ANY) ; }
-
- // Explicit record of what's not provided here.
-
- @Override
- public abstract Graph getDefaultGraph() ;
-
- @Override
- public abstract Graph getGraph(Node graphNode) ;
-
- @Override
- public abstract void addGraph(Node graphName, Graph graph) ;
-
- @Override
- public abstract void removeGraph(Node graphName) ;
-
- @Override
- public void setDefaultGraph(Graph g)
- { throw new UnsupportedOperationException("DatasetGraph.setDefaultGraph") ; }
-
- @Override
- public void add(Quad quad) { throw new UnsupportedOperationException("DatasetGraph.add(Quad)") ; }
-
- @Override
- public void delete(Quad quad) { throw new UnsupportedOperationException("DatasetGraph.delete(Quad)") ; }
-
- @Override
- public void add(Node g, Node s, Node p, Node o) { add(new Quad(g,s,p,o)) ; }
- @Override
- public void delete(Node g, Node s, Node p, Node o) { delete(new Quad(g,s,p,o)) ; }
-
- private static final int DeleteBufferSize = 1000 ;
- @Override
- /** Simple implementation but done without assuming iterator.remove() */
- public void deleteAny(Node g, Node s, Node p, Node o)
- {
- // Delete in slices rather than assume .remove() on the iterator is implemented.
- // We keep executing find(g, s, p, o) until we don't get a full slice.
- Quad[] buffer = new Quad[DeleteBufferSize] ;
- while(true) {
- Iterator<Quad> iter = find(g, s, p, o) ;
- // Get a slice
- int len = 0 ;
- for (; len < DeleteBufferSize; len++) {
- if ( !iter.hasNext() )
- break ;
- buffer[len] = iter.next() ;
- }
- // Delete them.
- for (int i = 0; i < len; i++) {
- delete(buffer[i]) ;
- buffer[i] = null ;
- }
- // Finished?
- if ( len < DeleteBufferSize )
- break ;
- }
- }
-
- @Override
- public Iterator<Quad> find()
- { return find(Node.ANY, Node.ANY, Node.ANY, Node.ANY) ; }
-
- @Override
- public Iterator<Quad> find(Quad quad)
- {
- if ( quad == null )
- return find() ;
- return find(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; }
-
- @Override
- public boolean contains(Quad quad) { return contains(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; }
-
- @Override
- public boolean contains(Node g, Node s, Node p , Node o)
- {
- Iterator<Quad> iter = find(g, s, p, o) ;
- boolean b = iter.hasNext() ;
- Iter.close(iter) ;
- return b ;
- }
-
- protected static boolean isWildcard(Node g)
- {
- return g == null || g == Node.ANY ;
- }
-
- @Override
- public void clear()
- {
- deleteAny(Node.ANY, Node.ANY, Node.ANY, Node.ANY) ;
- }
-
- @Override
- public boolean isEmpty()
- {
- return ! contains(Node.ANY, Node.ANY, Node.ANY, Node.ANY) ;
- }
-
- @Override
- public long size() { return -1 ; }
-
- @Override
- public Lock getLock()
- {
- return lock ;
- }
-
- @Override
- public Context getContext()
- {
- return context ;
- }
-
- @Override
- public void close()
- { }
-
- @Override
- public String toString()
- {
- // Using the size of the graphs would be better.
- IndentedLineBuffer out = new IndentedLineBuffer() ;
- WriterGraph.output(out, this, null) ;
- return out.asString() ;
- }
-
- // Helpers
-
- protected static Iterator<Quad> triples2quadsDftGraph(Iterator<Triple> iter)
- {
- //return triples2quads(Quad.defaultGraphIRI, iter) ;
- return triples2quads(Quad.defaultGraphNodeGenerated, iter) ;
- //return triples2quads(Quad.tripleInQuad, iter) ;
- }
-
- protected static Iter<Quad> triples2quads(final Node graphNode, Iterator<Triple> iter)
- {
- Transform<Triple, Quad> transformNamedGraph = new Transform<Triple, Quad> () {
- @Override
- public Quad convert(Triple triple)
- {
- return new Quad(graphNode, triple) ;
- }
- } ;
-
- return Iter.iter(iter).map(transformNamedGraph) ;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBaseFind.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBaseFind.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBaseFind.java
deleted file mode 100644
index e83f0c1..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphBaseFind.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-
-import com.hp.hpl.jena.graph.Node ;
-
-/**
- * DatasetGraph framework.
- * This class contains a convenience implementation of find that maps to a split between
- * defaultGraph/named graphs.
- * @see DatasetGraphTriplesQuads
- * @see DatasetGraphCollection
- * @see DatasetGraphOne
- *
- */
-abstract public class DatasetGraphBaseFind extends DatasetGraphBase
-{
- protected DatasetGraphBaseFind() {}
-
- /** Implementation of find based on splitting into triples (default graph) and quads (named graph) */
- @Override
- public Iterator<Quad> find(Node g, Node s, Node p , Node o)
- {
- if ( Quad.isDefaultGraph(g))
- return findInDftGraph(s, p, o) ;
- if ( ! isWildcard(g) )
- return findNG(g, s, p, o) ;
- return findAny(s, p, o) ;
- }
-
- @Override
- public Iterator<Quad> findNG(Node g, Node s, Node p , Node o)
- {
- Iterator<Quad> qIter ;
- if ( Quad.isUnionGraph(g))
- qIter = findInAnyNamedGraphs(s, p, o) ;
- else if ( ! isWildcard(g) )
- qIter = findInSpecificNamedGraph(g, s, p, o) ;
- else
- qIter = findInAnyNamedGraphs(s, p, o) ;
- if ( qIter == null )
- return Iter.nullIterator() ;
- return qIter ;
- }
-
- protected Iterator<Quad> findAny(Node s, Node p , Node o)
- {
- // Default graph
- Iterator<Quad> iter1 = findInDftGraph(s, p, o) ;
- Iterator<Quad> iter2 = findInAnyNamedGraphs(s, p, o) ;
-
- if ( iter1 == null && iter2 == null )
- return Iter.nullIterator() ;
- // Copes with null in either position.
- return Iter.append(iter1, iter2) ;
- }
-
- protected abstract Iterator<Quad> findInDftGraph(Node s, Node p , Node o) ;
- protected abstract Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p , Node o) ;
- protected abstract Iterator<Quad> findInAnyNamedGraphs(Node s, Node p , Node o) ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCaching.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCaching.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCaching.java
deleted file mode 100644
index f9b2692..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCaching.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-
-import java.util.Iterator ;
-import java.util.concurrent.Callable ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.Cache ;
-import org.apache.jena.atlas.lib.CacheFactory ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.GraphUtil ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-
-/**
- * DatasetGraph that <em>caches</em> calls to make graph implementations.
- * Useful for storage layers that use triples+quads storage and the
- * graphs are wrappers to the actual storage layer.
- *
- * The cache is finite and graphs will be dropped as needed.
- *
- * {@link DatasetGraphMap} provides an implementation which is an extensable collection of graphs.
- */
-abstract public class DatasetGraphCaching extends DatasetGraphTriplesQuads
-{
- private final boolean caching = true ;
- private boolean closed = false ;
-
- // read synchronised in this class, not needed for a sync wrapper.
- protected Graph defaultGraph = null ;
- protected Cache<Node, Graph> namedGraphs = CacheFactory.createCache(100) ;
-
- abstract protected void _close() ;
- abstract protected Graph _createNamedGraph(Node graphNode) ;
- abstract protected Graph _createDefaultGraph() ;
- abstract protected boolean _containsGraph(Node graphNode) ;
-
- protected DatasetGraphCaching() { this(100) ; }
-
- protected DatasetGraphCaching(int cacheSize) {
- if ( cacheSize <= 0 )
- throw new IllegalArgumentException("Cache size is less that 1: " + cacheSize) ;
- namedGraphs = CacheFactory.createCache(cacheSize) ;
- }
-
- @Override
- public boolean containsGraph(Node graphNode) {
- if ( namedGraphs.containsKey(graphNode) )
- // Empty graph may or may not count.
- // If they don't, need to override this method.
- return true ;
- return _containsGraph(graphNode) ;
- }
-
- @Override
- public final Graph getDefaultGraph() {
- if ( !caching )
- return _createDefaultGraph() ;
-
- synchronized (this) {
- if ( defaultGraph == null )
- defaultGraph = _createDefaultGraph() ;
- }
- return defaultGraph ;
- }
-
- @Override
- public final Graph getGraph(final Node graphNode) {
- if ( !caching )
- return _createNamedGraph(graphNode) ;
-
- synchronized (this) {
- Callable<Graph> filler = new Callable<Graph>() {
- @Override
- public Graph call() {
- return _createNamedGraph(graphNode) ;
- }} ;
- // MRSW - need to create and update the cache atomically.
- Graph graph = namedGraphs.getOrFill(graphNode, filler) ;
- return graph ;
- }
- }
-
- @Override
- public void addGraph(Node graphName, Graph graph) {
- removeGraph(graphName) ;
- GraphUtil.addInto(getGraph(graphName), graph) ;
- }
-
- @Override
- public final void removeGraph(Node graphName) {
- deleteAny(graphName, Node.ANY, Node.ANY, Node.ANY) ;
- synchronized (this) {
- namedGraphs.remove(graphName) ;
- }
- }
-
- @Override
- public void clear() {
- synchronized (this) {
- super.clear() ;
- namedGraphs.clear() ;
- }
- }
-
- @Override
- public void close() {
- synchronized (this) {
- if ( closed )
- return ;
- closed = true ;
-
- defaultGraph = null ;
- namedGraphs.clear() ;
- _close() ;
- super.close() ;
- }
- }
-
- // Helper implementations of operations.
- // Not necessarily efficient.
- protected static class Helper {
- public static void addToDftGraph(DatasetGraphCaching dsg, Node s, Node p, Node o) {
- dsg.getDefaultGraph().add(new Triple(s, p, o)) ;
- }
-
- public static void addToNamedGraph(DatasetGraphCaching dsg, Node g, Node s, Node p, Node o) {
- dsg.getGraph(g).add(new Triple(s, p, o)) ;
- }
-
- public static void deleteFromDftGraph(DatasetGraphCaching dsg, Node s, Node p, Node o) {
- dsg.getDefaultGraph().delete(new Triple(s, p, o)) ;
- }
-
- public static void deleteFromNamedGraph(DatasetGraphCaching dsg, Node g, Node s, Node p, Node o) {
- dsg.getGraph(g).delete(new Triple(s, p, o)) ;
- }
-
- public static Iterator<Quad> findInAnyNamedGraphs(DatasetGraphCaching dsg, Node s, Node p, Node o) {
- Iterator<Node> iter = dsg.listGraphNodes() ;
- Iterator<Quad> quads = null ;
- for ( ; iter.hasNext() ; ) {
- Node gn = iter.next() ;
- quads = Iter.append(quads, findInSpecificNamedGraph(dsg, gn, s, p, o)) ;
- }
- return quads ;
- }
-
- public static Iterator<Quad> findInDftGraph(DatasetGraphCaching dsg, Node s, Node p, Node o) {
- return triples2quadsDftGraph(dsg.getDefaultGraph().find(s, p, o)) ;
- }
-
- public static Iterator<Quad> findInSpecificNamedGraph(DatasetGraphCaching dsg, Node g, Node s, Node p, Node o) {
- return triples2quadsDftGraph(dsg.getGraph(g).find(s, p, o)) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCollection.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCollection.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCollection.java
deleted file mode 100644
index 3986e30..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphCollection.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.IteratorConcat;
-import org.apache.jena.atlas.lib.Lib ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.shared.JenaException ;
-
-/** Base class for implementations of a DatasetGraph as a set of graphs.
- * This can be a fixed collection or a changeable collection depending
- * on the implementation of getDefaultGraph()/getGraph(Node)
- */
-public abstract class DatasetGraphCollection extends DatasetGraphBaseFind
-{
- @Override
- public void add(Quad quad)
- {
- Graph g = fetchGraph(quad.getGraph()) ;
- if ( g == null )
- throw new JenaException("No such graph: "+quad.getGraph()) ;
- g.add(quad.asTriple()) ;
- }
-
- @Override
- public void delete(Quad quad)
- {
- Graph g = fetchGraph(quad.getGraph()) ;
- if ( g == null )
- throw new JenaException("No such graph: "+quad.getGraph()) ;
- g.delete(quad.asTriple()) ;
- }
-
- @Override
- protected Iterator<Quad> findInDftGraph(Node s, Node p , Node o)
- {
- return triples2quadsDftGraph(getDefaultGraph().find(s, p, o)) ;
- }
-
- @Override
- protected Iter<Quad> findInSpecificNamedGraph(Node g, Node s, Node p , Node o)
- {
- Graph graph = fetchGraph(g) ;
- if ( graph == null )
- return Iter.nullIter() ;
- return triples2quads(g, graph.find(s, p, o)) ;
- }
-
- @Override
- protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o)
- {
- Iterator<Node> gnames = listGraphNodes() ;
- IteratorConcat<Quad> iter = new IteratorConcat<>() ;
-
- // Named graphs
- for ( ; gnames.hasNext() ; )
- {
- Node gn = gnames.next();
- Iterator<Quad> qIter = findInSpecificNamedGraph(gn, s, p, o) ;
- if ( qIter != null )
- iter.add(qIter) ;
- }
- return iter ;
- }
-
- @Override
- public abstract Iterator<Node> listGraphNodes() ;
-
- @Override
- public void clear() {
- // Delete all triples in the default graph
- getDefaultGraph().clear() ;
- // Now remove the named graphs (but don't clear them - they may be shared).
- Iterator<Node> gnIter = listGraphNodes() ;
- for ( ; gnIter.hasNext(); ) {
- Node gn = gnIter.next() ;
- removeGraph(gn) ;
- }
- }
-
- protected Graph fetchGraph(Node gn)
- {
- if ( Quad.isDefaultGraph(gn) || Lib.equal(gn,Quad.tripleInQuad)) // Not preferred style
- return getDefaultGraph() ;
- else
- return getGraph(gn) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphFactory.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphFactory.java
deleted file mode 100644
index 2de4b44..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphFactory.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.sparql.graph.GraphFactory ;
-
-public class DatasetGraphFactory
-{
- /** Create a DatasetGraph based on an existing one;
- * this is a structure copy of the dataset struture
- * but graphs are shared
- */
- public static DatasetGraph create(DatasetGraph dsg)
- {
- // Fixed - requires explicit "add graph"
- return new DatasetGraphMap(dsg) ;
-// DatasetGraph dsg2 = createMem() ;
-// copyOver(dsg2, dsg2) ;
-// return dsg2 ;
- }
-
- private static void copyOver(DatasetGraph dsgDest, DatasetGraph dsgSrc)
- {
- dsgDest.setDefaultGraph(dsgSrc.getDefaultGraph()) ;
- for ( Iterator<Node> names = dsgSrc.listGraphNodes() ; names.hasNext() ; )
- {
- Node gn = names.next() ;
- dsgDest.addGraph(gn, dsgSrc.getGraph(gn)) ;
- }
- }
-
- /**
- * Create a DatasetGraph starting with a single graph.
- * New graphs must be explicitly added.
- */
- public static DatasetGraph create(Graph graph)
- {
- DatasetGraph dsg2 = createMemFixed() ;
- dsg2.setDefaultGraph(graph) ;
- return dsg2 ;
- }
-
- /**
- * Create a DatasetGraph which only ever has a single default graph.
- */
- public static DatasetGraph createOneGraph(Graph graph) { return new DatasetGraphOne(graph) ; }
-
- /** Interface for makign graphs when a dataset needs to add a new graph.
- * Return null for no graph created.
- */
- public interface GraphMaker { public Graph create() ; }
-
- /** A graph maker that doesn't make graphs */
- public static GraphMaker graphMakerNull = new GraphMaker() {
- @Override
- public Graph create()
- {
- return null ;
- } } ;
-
- private static GraphMaker memGraphMaker = new GraphMaker()
- {
- @Override
- public Graph create()
- {
- return GraphFactory.createDefaultGraph() ;
- }
- } ;
-
- /**
- * Create a DatasetGraph which has all graphs in memory.
- */
-
- public static DatasetGraph createMem() { return new DatasetGraphMaker(memGraphMaker) ; }
-
- public static DatasetGraph createMemFixed() { return new DatasetGraphMap(GraphFactory.createDefaultGraph()) ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMaker.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMaker.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMaker.java
deleted file mode 100644
index 744ab76..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMaker.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.sparql.core.DatasetGraphFactory.GraphMaker ;
-
-/** Implementation of a DatasetGraph as an open set of graphs where all graphs "exist".
- * New graphs are created (via the policy of a GraphMaker) when a getGraph call is
- * made to a graph that has not been allocated.
- */
-public class DatasetGraphMaker extends DatasetGraphMap
-{
- private GraphMaker graphMaker ;
-
- public DatasetGraphMaker(GraphMaker graphMaker)
- {
- super(graphMaker.create()) ;
- this.graphMaker = graphMaker ;
- }
-
- public DatasetGraphMaker(Graph graph)
- {
- super(graph) ;
- this.graphMaker = DatasetGraphFactory.graphMakerNull ;
- }
-
- @Override
- protected Graph getGraphCreate()
- {
- return graphMaker.create() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMap.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMap.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMap.java
deleted file mode 100644
index 2abeeb6..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMap.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.HashMap ;
-import java.util.Iterator ;
-import java.util.Map ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-
-/** Implementation of a DatasetGraph as an extensible set of graphs.
- * Subclasses need to manage any implicit graph creation.
- */
-public class DatasetGraphMap extends DatasetGraphCollection
-{
- private Map<Node, Graph> graphs = new HashMap<>() ;
-
- private Graph defaultGraph ;
-
- public DatasetGraphMap(Graph defaultGraph)
- { this.defaultGraph = defaultGraph ; }
-
- /** Create a new DatasetGraph that initially shares the graphs of the
- * givem DatasetGraph. Adding/removing graphs will only affect this
- * object, not the argument DatasetGraph but changed to shared
- * graphs are seenby both objects.
- */
-
- public DatasetGraphMap(DatasetGraph dsg)
- {
- this(dsg.getDefaultGraph()) ;
- for ( Iterator<Node> names = dsg.listGraphNodes() ; names.hasNext() ; )
- {
- Node gn = names.next() ;
- addGraph(gn, dsg.getGraph(gn)) ;
- }
- }
-
- @Override
- public boolean containsGraph(Node graphNode)
- {
- return graphs.containsKey(graphNode) ;
- }
-
- @Override
- public Graph getDefaultGraph()
- {
- return defaultGraph ;
- }
-
- @Override
- public Graph getGraph(Node graphNode)
- {
- Graph g = graphs.get(graphNode) ;
- if ( g == null )
- {
- g = getGraphCreate() ;
- if ( g != null )
- addGraph(graphNode, g) ;
- }
- return g ;
- }
-
- /** Called from getGraph when a nonexistent graph is asked for.
- * Return null for "nothing created as a graph"
- */
- protected Graph getGraphCreate() { return null ; }
-
-
- @Override
- public void addGraph(Node graphName, Graph graph)
- {
- graphs.put(graphName, graph) ;
- }
-
- @Override
- public void removeGraph(Node graphName)
- {
- graphs.remove(graphName) ;
- }
-
- @Override
- public void setDefaultGraph(Graph g)
- {
- defaultGraph = g ;
- }
-
- @Override
- public Iterator<Node> listGraphNodes()
- {
- return graphs.keySet().iterator() ;
- }
-
- @Override
- public long size()
- {
- return graphs.size() ;
- }
-
- @Override
- public void close()
- {
- defaultGraph.close();
- for ( Graph graph : graphs.values() )
- graph.close();
- super.close() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMonitor.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMonitor.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMonitor.java
deleted file mode 100644
index 8980891..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphMonitor.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core ;
-
-import static org.apache.jena.atlas.iterator.Iter.take ;
-
-import java.util.Iterator ;
-import java.util.List ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.sparql.SystemARQ ;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
-
-/** Connect a DatasetGraph to a DatasetChanges monitor.
- * Any add or delete to the DatasetGraph is notified to the
- * monitoring object with a {@link QuadAction} to indicate
- * the change made.
- */
-
-public class DatasetGraphMonitor extends DatasetGraphWrapper
-{
- /** Whether to see if a quad action will change the dataset - test before add for existence, test before delete for absence */
- private boolean CheckFirst = true ;
- /** Whether to record a no-op (maybe as a comment) */
- private boolean RecordNoAction = true ;
- /** Where to send the notifications */
- private final DatasetChanges monitor ;
-
- /**
- * Create a DatasetGraph wrapper that monitors the dataset for changes (add or delete quads).
- * Use this DatasetGraph for all operations in order to record changes.
- * Note whether additions of deletions cause an actual change to the dataset or not.
- * @param dsg The DatasetGraph to monitor
- * @param monitor The handler for a change
- *
- * @see DatasetChanges
- * @see QuadAction
- */
- public DatasetGraphMonitor(DatasetGraph dsg, DatasetChanges monitor)
- {
- super(dsg) ;
- this.monitor = monitor ;
- }
-
- /**
- * Create a DatasetGraph wrapper that monitors the dataset for changes (add or delete quads).
- * Use this DatasetGraph for all operations in order to record changes.
- * @param dsg The DatasetGraph to monitor
- * @param monitor The handler for a change
- * @param recordOnlyIfRealChange
- * If true, check to see if the change would have an effect (e.g. add is a new quad).
- * If false, log changes as ADD/DELETE regardless of whether the dataset actually changes.
- *
- * @see DatasetChanges
- * @see QuadAction
- */
- public DatasetGraphMonitor(DatasetGraph dsg, DatasetChanges monitor, boolean recordOnlyIfRealChange)
- {
- super(dsg) ;
- CheckFirst = recordOnlyIfRealChange ;
- this.monitor = monitor ;
- }
-
- /** Return the monitor */
- public DatasetChanges getMonitor() { return monitor ; }
-
- /** Return the monitored DatasetGraph */
- public DatasetGraph monitored() { return getWrapped() ; }
-
- @Override public void add(Quad quad)
- {
- if ( CheckFirst && contains(quad) )
- {
- if ( RecordNoAction )
- record(QuadAction.NO_ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- return ;
- }
- add$(quad) ;
- }
-
- @Override public void add(Node g, Node s, Node p, Node o)
- {
- if ( CheckFirst && contains(g,s,p,o) )
- {
- if ( RecordNoAction )
- record(QuadAction.NO_ADD,g,s,p,o) ;
- return ;
- }
-
- add$(g,s,p,o) ;
- }
-
- private void add$(Node g, Node s, Node p, Node o)
- {
- super.add(g,s,p,o) ;
- record(QuadAction.ADD,g,s,p,o) ;
- }
-
- private void add$(Quad quad)
- {
- super.add(quad) ;
- record(QuadAction.ADD, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- }
-
- @Override public void delete(Quad quad)
- {
- if ( CheckFirst && ! contains(quad) )
- {
- if ( RecordNoAction )
- record(QuadAction.NO_DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- return ;
- }
- delete$(quad) ;
- }
-
- @Override public void delete(Node g, Node s, Node p, Node o)
- {
- if ( CheckFirst && ! contains(g,s,p,o) )
- {
- if ( RecordNoAction )
- record(QuadAction.NO_DELETE, g,s,p,o) ;
- return ;
- }
- delete$(g,s,p,o) ;
- }
-
- private void delete$(Quad quad)
- {
- super.delete(quad) ;
- record(QuadAction.DELETE, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
- }
-
- private void delete$(Node g, Node s, Node p, Node o)
- {
- super.delete(g,s,p,o) ;
- record(QuadAction.DELETE,g,s,p,o) ;
- }
-
-
- private static int SLICE = 1000 ;
-
- @Override
- public void deleteAny(Node g, Node s, Node p, Node o)
- {
- while (true)
- {
- Iterator<Quad> iter = find(g, s, p, o) ;
- // Materialize - stops possible ConcurrentModificationExceptions
- List<Quad> some = take(iter, SLICE) ;
- for (Quad q : some)
- delete$(q) ;
- if (some.size() < SLICE) break ;
- }
- }
-
- @Override public void addGraph(Node gn, Graph g)
- {
- // Convert to quads.
- //super.addGraph(gn, g) ;
- ExtendedIterator<Triple> iter = g.find(Node.ANY, Node.ANY, Node.ANY) ;
- for ( ; iter.hasNext(); )
- {
- Triple t = iter.next() ;
- add(gn, t.getSubject(), t.getPredicate(), t.getObject()) ;
- }
- }
-
- @Override public void removeGraph(Node gn)
- {
- //super.removeGraph(gn) ;
- deleteAny(gn, Node.ANY, Node.ANY, Node.ANY) ;
- }
-
- private void record(QuadAction action, Node g, Node s, Node p, Node o)
- {
- monitor.change(action, g, s, p, o) ;
- }
-
- @Override
- public void sync() {
- SystemARQ.syncObject(monitor) ;
- super.sync() ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphOne.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphOne.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphOne.java
deleted file mode 100644
index 5285c41..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphOne.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.NullIterator ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-
-/**
- * DatasetGraph of a single graph as default graph.
- * Fixed as one graph (the default) - can not add named graphs.
- */
-public class DatasetGraphOne extends DatasetGraphBaseFind
-{
- private final Graph graph ;
-
- public DatasetGraphOne(Graph graph) { this.graph = graph ; }
-
- @Override
- public boolean containsGraph(Node graphNode)
- {
- if ( isDefaultGraph(graphNode) )
- return true ;
- return false ;
- }
-
- @Override
- public Graph getDefaultGraph() { return graph ; }
-
- @Override
- public Graph getGraph(Node graphNode)
- {
- if ( isDefaultGraph(graphNode) )
- return graph ;
- return null ;
- }
-
- @Override
- public Iterator<Node> listGraphNodes()
- {
- return new NullIterator<>() ;
- }
-
- @Override
- public long size()
- {
- return 0 ;
- }
-
- @Override
- public void add(Node g , Node s, Node p, Node o)
- {
- if ( Quad.isDefaultGraph(g) )
- graph.add(new Triple(s, p, o)) ;
- else
- throw new UnsupportedOperationException("DatasetGraphOne.add/named graph") ;
- }
-
- @Override
- public void add(Quad quad)
- {
- if ( isDefaultGraph(quad) )
- graph.add(quad.asTriple()) ;
- else
- throw new UnsupportedOperationException("DatasetGraphOne.add/named graph") ;
- }
-
- @Override
- public void delete(Node g, Node s, Node p, Node o)
- {
- if ( Quad.isDefaultGraph(g) )
- graph.delete(new Triple(s, p, o)) ;
- else
- throw new UnsupportedOperationException("DatasetGraphOne.delete/named graph") ;
- }
-
- @Override
- public void delete(Quad quad)
- {
- if ( isDefaultGraph(quad) )
- graph.delete(quad.asTriple()) ;
- else
- throw new UnsupportedOperationException("DatasetGraphOne.delete/named graph") ;
- }
-
- @Override
- public void setDefaultGraph(Graph g)
- { throw new UnsupportedOperationException("DatasetGraphOne.setDefaultGraph") ; }
-
- @Override
- public void addGraph(Node graphName, Graph graph)
- { throw new UnsupportedOperationException("DatasetGraphOne.addGraph") ; }
-
- @Override
- public void removeGraph(Node graphName)
- { throw new UnsupportedOperationException("DatasetGraphOne.removeGraph") ; }
-
- // -- Not needed -- implement find(g,s,p,o) directly.
- @Override
- protected Iterator<Quad> findInDftGraph(Node s, Node p, Node o)
- {
- return triples2quadsDftGraph(graph.find(s, p ,o)) ;
- }
-
- @Override
- protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o)
- {
- // There are no named graphs
- return Iter.nullIterator() ;
- }
-
- @Override
- protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o)
- {
- // There are no named graphs
- return Iter.nullIterator() ;
- }
-
- protected static boolean isDefaultGraph(Quad quad)
- {
- return isDefaultGraph(quad.getGraph()) ;
- }
-
- protected static boolean isDefaultGraph(Node quadGraphNode)
- {
- return ( quadGraphNode == null || Quad.isDefaultGraph(quadGraphNode) ) ;
- }
-
- // It's just easier and more direct ...
- @Override
- public Iterator<Quad> find(Node g, Node s, Node p , Node o)
- {
- if ( isWildcard(g) || isDefaultGraph(g) )
- return triples2quadsDftGraph(graph.find(s, p, o)) ;
- else
- return new NullIterator<>() ;
- }
-
-
- @Override
- public void close()
- {
- graph.close();
- super.close() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphQuad.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphQuad.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphQuad.java
deleted file mode 100644
index da6b5d4..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphQuad.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.Transform ;
-
-import com.hp.hpl.jena.graph.Node ;
-
-
-/** A DatasetGraph base class for pure quad-centric storage.
- */
-public abstract class DatasetGraphQuad extends DatasetGraphBase
-{
- static Transform<Quad, Node> projectGraphName = new Transform<Quad, Node>() {
- @Override
- public Node convert(Quad quad)
- {
- return quad.getGraph() ;
- }} ;
-
- @Override
- public Iterator<Node> listGraphNodes()
- {
- Iter<Quad> iter = Iter.iter(find(Node.ANY, Node.ANY, Node.ANY, Node.ANY)) ;
- return iter.map(projectGraphName).distinct() ;
- }
-
- @Override
- public void removeGraph(Node graphName)
- {
- deleteAny(graphName, Node.ANY, Node.ANY, Node.ANY) ;
- }
-
- @Override
- public abstract Iterator<Quad> find(Node g, Node s, Node p, Node o) ;
-
- @Override
- public abstract Iterator<Quad> findNG(Node g, Node s, Node p, Node o) ;
-
- @Override
- public abstract void add(Quad quad) ;
-
- @Override
- public abstract void delete(Quad quad) ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphReadOnly.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphReadOnly.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphReadOnly.java
deleted file mode 100644
index d61ca9b..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphReadOnly.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.HashMap ;
-import java.util.Map ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.sparql.graph.GraphReadOnly ;
-
-/** Read-only view of a DatasetGraph. Assumes the dataset underneath isn't changing.
- */
-public class DatasetGraphReadOnly extends DatasetGraphWrapper
-{
- public DatasetGraphReadOnly(DatasetGraph dsg) { super(dsg) ; }
-
- private Graph dftGraph = null ;
-
- @Override
- public Graph getDefaultGraph()
- {
- if ( dftGraph == null )
- dftGraph = new GraphReadOnly(super.getDefaultGraph()) ;
- return dftGraph ;
- }
-
- private Map<Node, Graph> namedGraphs = new HashMap<>() ;
-
- @Override
- public Graph getGraph(Node graphNode)
- {
- if ( namedGraphs.containsKey(graphNode) )
- {
- if ( ! super.containsGraph(graphNode) )
- {
- namedGraphs.remove(graphNode) ;
- return null ;
- }
- return namedGraphs.get(graphNode) ;
- }
-
- Graph g = super.getGraph(graphNode) ;
- if ( g == null ) return null ;
- g = new GraphReadOnly(g) ;
- namedGraphs.put(graphNode, g) ;
- return g ;
- }
-
- @Override
- public void setDefaultGraph(Graph g)
- { throw new UnsupportedOperationException("read-only dataset") ; }
-
- @Override
- public void addGraph(Node graphName, Graph graph)
- { throw new UnsupportedOperationException("read-only dataset") ; }
-
- @Override
- public void removeGraph(Node graphName)
- { throw new UnsupportedOperationException("read-only dataset") ; }
-
- @Override
- public void add(Quad quad)
- { throw new UnsupportedOperationException("read-only dataset") ; }
-
- @Override
- public void delete(Quad quad)
- { throw new UnsupportedOperationException("read-only dataset") ; }
-
- @Override
- public void deleteAny(Node g, Node s, Node p, Node o)
- { throw new UnsupportedOperationException("read-only dataset") ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphSimpleMem.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphSimpleMem.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphSimpleMem.java
deleted file mode 100644
index f5a4bf1..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphSimpleMem.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.ArrayList ;
-import java.util.Collection ;
-import java.util.HashSet ;
-import java.util.Iterator ;
-import java.util.List ;
-import java.util.Set ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.graph.impl.GraphBase ;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
-import com.hp.hpl.jena.util.iterator.WrappedIterator ;
-
-/** Very simple, non-scalable DatasetGraph implementation
- * of a triples+quads style for testing.
- */
-public class DatasetGraphSimpleMem extends DatasetGraphCaching
-{
- private MiniSet<Triple> triples = new MiniSet<>() ;
- private MiniSet<Quad> quads = new MiniSet<>() ;
-
- /** Simple abstraction of a Set */
- private static class MiniSet<T> implements Iterable<T>
- {
- final Collection<T> store ;
- MiniSet(Collection<T> store) { this.store = store ; }
-
- MiniSet() { this.store = new ArrayList<>() ; }
-
- void add(T t)
- {
- if ( !store.contains(t) )
- store.add(t) ;
- }
-
- void remove(T t)
- {
- store.remove(t) ;
- }
-
- @Override
- public Iterator<T> iterator()
- {
- return store.iterator() ;
- }
-
- boolean isEmpty() { return store.isEmpty() ; }
-
- int size() { return store.size() ; }
- }
-
- public DatasetGraphSimpleMem() {}
-
-
- @Override
- public Iterator<Quad> findInDftGraph(Node s, Node p , Node o)
- {
- List<Quad> results = new ArrayList<>() ;
- for ( Triple t : triples )
- if ( matches(t, s, p, o) )
- // ?? Quad.defaultGraphNodeGenerated
- //Quad.defaultGraphIRI
- results.add(new Quad(Quad.defaultGraphIRI, t)) ;
- return results.iterator() ;
- }
-
- @Override
- public Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p , Node o)
- {
- List<Quad> results = new ArrayList<>() ;
- for ( Quad q : quads )
- if ( matches(q, g, s, p, o) )
- results.add(q) ;
- return results.iterator() ;
- }
-
- @Override
- public Iterator<Quad> findInAnyNamedGraphs(Node s, Node p , Node o)
- {
- List<Quad> results = new ArrayList<>() ;
- for ( Quad q : quads )
- if ( matches(q, Node.ANY, s, p, o) )
- results.add(q) ;
- return results.iterator() ;
- }
-
- /** Convert null to Node.ANY */
- public static Node nullAsAny(Node x) { return nullAsDft(x, Node.ANY) ; }
-
- /** Convert null to some default Node */
- public static Node nullAsDft(Node x, Node dft) { return x==null ? dft : x ; }
-
- private boolean matches(Triple t, Node s, Node p, Node o)
- {
- s = nullAsAny(s) ;
- p = nullAsAny(p) ;
- o = nullAsAny(o) ;
- return t.matches(s,p,o) ;
- }
-
- private boolean matches(Quad q, Node g, Node s, Node p, Node o)
- {
- g = nullAsAny(g) ;
- s = nullAsAny(s) ;
- p = nullAsAny(p) ;
- o = nullAsAny(o) ;
- return q.matches(g,s,p,o) ;
- }
-
- @Override
- protected void addToDftGraph(Node s, Node p, Node o)
- {
- Triple t = new Triple(s, p, o) ;
- triples.add(t) ;
- }
-
- @Override
- protected void addToNamedGraph(Node g, Node s, Node p, Node o)
- {
- Quad q = new Quad(g, s, p, o) ;
- quads.add(q) ;
- }
-
- @Override
- protected void deleteFromDftGraph(Node s, Node p, Node o)
- {
- triples.remove(new Triple(s, p, o)) ;
- }
-
- @Override
- protected void deleteFromNamedGraph(Node g, Node s, Node p, Node o)
- {
- quads.remove(new Quad(g, s, p, o)) ;
- }
-
- class GraphDft extends GraphBase
- {
- @Override
- public void performAdd(Triple t)
- {
- triples.add(t) ;
- }
-
- @Override
- public void performDelete(Triple t) { triples.remove(t) ; }
-
- @Override
- protected ExtendedIterator<Triple> graphBaseFind(Triple m)
- {
- List<Triple> results = new ArrayList<>() ;
- for ( Triple t : triples )
- if ( t.matches(m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) )
- results.add(t) ;
- return WrappedIterator.create(results.iterator()) ;
- }
- }
-
- class GraphNamed extends GraphBase
- {
- private final Node graphName ;
-
- GraphNamed(Node gname) { this.graphName = gname ; }
-
- @Override
- public void performAdd(Triple t)
- {
- Quad q = new Quad(graphName, t) ;
- quads.add(q) ;
- }
-
- @Override
- public void performDelete(Triple t) { Quad q = new Quad(graphName, t) ; quads.remove(q) ; }
-
- @Override
- protected ExtendedIterator<Triple> graphBaseFind(Triple m)
- {
- List<Triple> results = new ArrayList<>() ;
-
- Iterator<Quad> iter = findNG(graphName, m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) ;
- for ( ; iter.hasNext() ; )
- results.add(iter.next().asTriple()) ;
- return WrappedIterator.create(results.iterator()) ;
- }
- }
-
- @Override
- protected Graph _createDefaultGraph()
- {
- return new GraphDft() ;
- }
-
- @Override
- protected Graph _createNamedGraph(Node graphNode)
- {
- return new GraphNamed(graphNode) ;
- }
-
- @Override
- protected boolean _containsGraph(Node graphNode)
- {
- return graphNodes().contains(graphNode) ;
- }
-
- @Override
- public Iterator<Node> listGraphNodes()
- {
- return graphNodes().iterator() ;
- }
-
- private Set<Node> graphNodes()
- {
- Set<Node> x = new HashSet<>() ;
- for ( Quad q : quads )
- x.add(q.getGraph()) ;
- return x ;
- }
-
- @Override
- protected void _close()
- {}
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
deleted file mode 100644
index 3b84dd9..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.query.ReadWrite ;
-import com.hp.hpl.jena.shared.Lock ;
-
-/** Track the transactional state of a DatasetGraph */
-public abstract class DatasetGraphTrackActive implements DatasetGraph, Transactional
-{
- protected abstract DatasetGraph get() ;
-
- protected DatasetGraphTrackActive() { }
-
- protected abstract void checkActive() ;
- protected abstract void checkNotActive() ;
-
- @Override
- public final void begin(ReadWrite readWrite)
- {
- checkNotActive() ;
- _begin(readWrite) ;
- }
-
- @Override
- public final void commit()
- {
- checkActive() ;
- _commit() ;
- }
-
- @Override
- public final void abort()
- {
- checkActive() ;
- // Set before calling _abort, which might throw an exception.
- _abort() ;
- }
-
- @Override
- public final void end()
- {
- // Don't check if active. We may have committed or aborted already.
- _end() ;
- }
-
- @Override
- public abstract boolean isInTransaction() ;
- protected abstract void _begin(ReadWrite readWrite) ;
- protected abstract void _commit() ;
- protected abstract void _abort() ;
- protected abstract void _end() ;
-
- @Override
- public void close()
- {
- if ( isInTransaction() )
- abort() ;
- // Don't close really - let the implementation decide.
- _close() ;
- }
-
- protected abstract void _close() ;
-
- @Override
- public boolean containsGraph(Node graphNode)
- { return get().containsGraph(graphNode) ; }
-
- @Override
- public Graph getDefaultGraph()
- { return get().getDefaultGraph(); }
-
- @Override
- public Graph getGraph(Node graphNode)
- { return get().getGraph(graphNode) ; }
-
- @Override
- public void addGraph(Node graphName, Graph graph)
- { get().addGraph(graphName, graph) ; }
-
- @Override
- public void removeGraph(Node graphName)
- { get().removeGraph(graphName) ; }
-
- @Override
- public void setDefaultGraph(Graph g)
- { get().setDefaultGraph(g) ; }
-
- @Override
- public Lock getLock()
- { return get().getLock() ; }
-
- @Override
- public Iterator<Node> listGraphNodes()
- { return get().listGraphNodes() ; }
-
- @Override
- public void add(Quad quad)
- { get().add(quad) ; }
-
- @Override
- public void delete(Quad quad)
- { get().delete(quad) ; }
-
- @Override
- public void add(Node g, Node s, Node p, Node o)
- { get().add(g, s, p, o) ; }
-
- @Override
- public void delete(Node g, Node s, Node p, Node o)
- { get().delete(g, s, p, o) ; }
-
- @Override
- public void deleteAny(Node g, Node s, Node p, Node o)
- { get().deleteAny(g, s, p, o) ; }
-
- @Override
- public void clear()
- { get().clear() ; }
-
- @Override
- public boolean isEmpty()
- { return get().isEmpty() ; }
-
- @Override
- public Iterator<Quad> find()
- { return get().find() ; }
-
- @Override
- public Iterator<Quad> find(Quad quad)
- { return get().find(quad) ; }
-
- @Override
- public Iterator<Quad> find(Node g, Node s, Node p, Node o)
- { return get().find(g, s, p, o) ; }
-
- @Override
- public Iterator<Quad> findNG(Node g, Node s, Node p, Node o)
- { return get().findNG(g, s, p, o) ; }
-
- @Override
- public boolean contains(Quad quad)
- { return get().contains(quad) ; }
-
- @Override
- public boolean contains(Node g, Node s, Node p, Node o)
- { return get().contains(g, s, p, o) ; }
-
- // This mixes get() (which may do checking such as in/out transaction)
- // with configuration, which is not transaction related.
-
-// @Override
-// public Context getContext()
-// { return get().getContext() ; }
-
- @Override
- public long size()
- { return get().size() ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTriplesQuads.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTriplesQuads.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTriplesQuads.java
deleted file mode 100644
index 2f1a1d2..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTriplesQuads.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import com.hp.hpl.jena.graph.Node ;
-
-
-
-/** A DatasetGraph base class for triples+quads storage.
- */
-public abstract class DatasetGraphTriplesQuads extends DatasetGraphBaseFind
-{
- @Override
- final
- public void add(Quad quad)
- {
- add(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
- }
-
- @Override
- final
- public void delete(Quad quad)
- {
- delete(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
- }
-
- @Override
- public void add(Node g, Node s, Node p, Node o)
- {
- if ( Quad.isDefaultGraphGenerated(g) || Quad.isDefaultGraphExplicit(g) )
- addToDftGraph(s, p, o) ;
- else
- addToNamedGraph(g, s, p, o) ;
- }
-
- @Override
- public void delete(Node g, Node s, Node p, Node o)
- {
- if ( Quad.isDefaultGraphGenerated(g) || Quad.isDefaultGraphExplicit(g) )
- deleteFromDftGraph(s, p, o) ;
- else
- deleteFromNamedGraph(g, s, p, o) ;
- }
-
- protected abstract void addToDftGraph(Node s, Node p, Node o) ;
- protected abstract void addToNamedGraph(Node g, Node s, Node p, Node o) ;
- protected abstract void deleteFromDftGraph(Node s, Node p, Node o) ;
- protected abstract void deleteFromNamedGraph(Node g, Node s, Node p, Node o) ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphViewGraphs.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphViewGraphs.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphViewGraphs.java
deleted file mode 100644
index 58fecab..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphViewGraphs.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-
-/** Wrap a DatasetGraph with implementations of
- * {@link DatasetGraph#getDefaultGraph} and
- * {@link DatasetGraph#getGraph}
- * that use the view graph mechanism.
- *
- * @see GraphView
- */
-
-public class DatasetGraphViewGraphs extends DatasetGraphWrapper
-{
- // May integrate into DatasetGraph hierarchy into DatasetGraphBase.
-
- public DatasetGraphViewGraphs(DatasetGraph dsg) {
- super(dsg) ;
- }
-
- @Override
- public Graph getDefaultGraph()
- { return GraphView.createDefaultGraph(getWrapped()) ; }
-
- @Override
- public Graph getGraph(Node graphNode)
- { return GraphView.createNamedGraph(getWrapped(), graphNode) ; }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java
deleted file mode 100644
index 4e94a72..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWithLock.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core ;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.Sync ;
-
-import com.hp.hpl.jena.query.ReadWrite ;
-import com.hp.hpl.jena.sparql.JenaTransactionException ;
-import com.hp.hpl.jena.sparql.SystemARQ ;
-import com.hp.hpl.jena.sparql.util.Context ;
-
-/**
- * A DatasetGraph that uses the dataset lock to give weak transactional
- * behaviour, that is the application see transaction but they are not durable.
- * Only provides multiple-reader OR single-writer, and no write-transction
- * abort.
- */
-public class DatasetGraphWithLock extends DatasetGraphTrackActive implements Sync {
- static class ThreadLocalBoolean extends ThreadLocal<Boolean> {
- @Override
- protected Boolean initialValue() {
- return false ;
- }
- }
-
- static class ThreadLocalReadWrite extends ThreadLocal<ReadWrite> {
- @Override
- protected ReadWrite initialValue() {
- return null ;
- }
- }
-
- private final ThreadLocalReadWrite readWrite = new ThreadLocalReadWrite() ;
- private final ThreadLocalBoolean inTransaction = new ThreadLocalBoolean() ;
- private final DatasetGraph dsg ;
- // Associated DatasetChanges (if any, may be null)
- private final DatasetChanges dsChanges ;
-
- public DatasetGraphWithLock(DatasetGraph dsg) {
- this.dsg = dsg ;
- this.dsChanges = findDatasetChanges(dsg) ;
- }
-
- /** Find a DatasetChanges handler.
- * Unwrap layers of DatasetGraphWrapper to
- * look for a DatasetGraphMonitor.
- */
- private static DatasetChanges findDatasetChanges(DatasetGraph dataset) {
- for(;;) {
- // DatasetGraphMonitor extends DatasetGraphWrapper
- if ( dataset instanceof DatasetGraphMonitor )
- return ((DatasetGraphMonitor)dataset).getMonitor() ;
- if ( ! ( dataset instanceof DatasetGraphWrapper ) )
- return null ;
- dataset = ((DatasetGraphWrapper)dataset).getWrapped() ;
- }
- }
-
- @Override
- protected DatasetGraph get() {
- return dsg ;
- }
-
- @Override
- protected void checkActive() {
- if ( !isInTransaction() )
- throw new JenaTransactionException("Not in a transaction") ;
- }
-
- @Override
- protected void checkNotActive() {
- if ( isInTransaction() )
- throw new JenaTransactionException("Currently in a transaction") ;
- }
-
- @Override
- public boolean isInTransaction() {
- return inTransaction.get() ;
- }
-
- protected boolean isTransactionType(ReadWrite readWriteType) {
- return readWrite.get() == readWriteType ;
- }
-
- @Override
- protected void _begin(ReadWrite readWrite) {
- this.readWrite.set(readWrite) ;
- boolean b = isTransactionType(ReadWrite.READ) ;
- get().getLock().enterCriticalSection(b) ;
- inTransaction.set(true) ;
- if ( dsChanges != null )
- dsChanges.start() ;
- }
-
- @Override
- protected void _commit() {
- if ( isTransactionType(ReadWrite.WRITE) )
- sync() ;
- _end() ;
- }
-
- @Override
- protected void _abort() {
- if ( isTransactionType(ReadWrite.WRITE) && ! abortImplemented() ) {
- // Still clean up.
- _end() ; // This clears the transaction type.
- throw new JenaTransactionException("Can't abort a write lock-transaction") ;
- }
- _end() ;
- }
-
- /** Return whether abort is provided.
- * Just by locking, a transaction can not write-abort (the changes have been made and not recorded).
- * Subclasses may do better and still rely on this locking class.
- */
- protected boolean abortImplemented() { return false ; }
-
- @Override
- protected void _end() {
- if ( isInTransaction() ) {
- if ( dsChanges != null )
- dsChanges.finish();
- get().getLock().leaveCriticalSection() ;
- clearState() ;
- }
- }
-
- @Override
- protected void _close() {
- if ( get() != null )
- get().close() ;
- }
-
- private void clearState() {
- inTransaction.set(false) ;
- readWrite.set(null) ;
- }
-
- @Override
- public Context getContext() {
- return get().getContext() ;
- }
-
- @Override
- public void sync() {
- SystemARQ.sync(get()) ;
- }
-
- @Override
- public String toString() {
- try {
- return get().toString() ;
- } catch (Exception ex) {
- return Lib.className(this) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWrapper.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWrapper.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWrapper.java
deleted file mode 100644
index 98a56b5..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphWrapper.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hp.hpl.jena.sparql.core;
-
-import java.util.Iterator ;
-
-import org.apache.jena.atlas.lib.Sync ;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.shared.Lock ;
-import com.hp.hpl.jena.sparql.SystemARQ ;
-import com.hp.hpl.jena.sparql.util.Context ;
-
-public class DatasetGraphWrapper implements DatasetGraph, Sync
-{
- // Associated query engine factory - QueryEngineFactoryWrapper
- // which executes on the unwraped DSG.
- private final DatasetGraph dsg ;
-
- /** Return the DatasetGraph being wrapped. */
- public final DatasetGraph getWrapped() {
- // Maybe should be "getQueryExecutionDatasetGraph"
- return get() ;
- }
-
- /** The dataset to use for redirection - can be overridden.
- * It is also guarantee that this is called only once per
- * delegated call. Changes to the wrapped object can be
- * made based on that contract.
- */
- protected DatasetGraph get() { return dsg ; }
-
- public DatasetGraphWrapper(DatasetGraph dsg) {
- this.dsg = dsg ;
- }
-
- @Override
- public boolean containsGraph(Node graphNode)
- { return get().containsGraph(graphNode) ; }
-
- @Override
- public Graph getDefaultGraph()
- { return get().getDefaultGraph(); }
-
- @Override
- public Graph getGraph(Node graphNode)
- { return get().getGraph(graphNode) ; }
-
- @Override
- public void addGraph(Node graphName, Graph graph)
- { get().addGraph(graphName, graph) ; }
-
- @Override
- public void removeGraph(Node graphName)
- { get().removeGraph(graphName) ; }
-
- @Override
- public void setDefaultGraph(Graph g)
- { get().setDefaultGraph(g) ; }
-
- @Override
- public Lock getLock()
- { return get().getLock() ; }
-
- @Override
- public Iterator<Node> listGraphNodes()
- { return get().listGraphNodes() ; }
-
- @Override
- public void add(Quad quad)
- { get().add(quad) ; }
-
- @Override
- public void delete(Quad quad)
- { get().delete(quad) ; }
-
- @Override
- public void add(Node g, Node s, Node p, Node o)
- { get().add(g, s, p, o) ; }
-
- @Override
- public void delete(Node g, Node s, Node p, Node o)
- { get().delete(g, s, p, o) ; }
-
- @Override
- public void deleteAny(Node g, Node s, Node p, Node o)
- { get().deleteAny(g, s, p, o) ; }
-
- @Override
- public void clear()
- { get().clear() ; }
-
- @Override
- public boolean isEmpty()
- { return get().isEmpty() ; }
-
- @Override
- public Iterator<Quad> find()
- { return get().find() ; }
-
- @Override
- public Iterator<Quad> find(Quad quad)
- { return get().find(quad) ; }
-
- @Override
- public Iterator<Quad> find(Node g, Node s, Node p, Node o)
- { return get().find(g, s, p, o) ; }
-
- @Override
- public Iterator<Quad> findNG(Node g, Node s, Node p, Node o)
- { return get().findNG(g, s, p, o) ; }
-
- @Override
- public boolean contains(Quad quad)
- { return get().contains(quad) ; }
-
- @Override
- public boolean contains(Node g, Node s, Node p, Node o)
- { return get().contains(g, s, p, o) ; }
-
- @Override
- public Context getContext()
- { return get().getContext() ; }
-
- @Override
- public long size()
- { return get().size() ; }
-
- @Override
- public void close()
- { get().close() ; }
-
- @Override
- public String toString() { return get().toString() ; }
-
- @Override
- public void sync() {
- // Pass down sync.
- SystemARQ.sync(get()) ;
- }
-
-}