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 2011/11/02 18:02:52 UTC
svn commit: r1196689 - in
/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena:
query/Dataset.java query/ReadWrite.java sparql/core/DataSourceImpl.java
sparql/core/DatasetImpl.java sparql/engine/main/iterator/QueryIterGraph.java
Author: andy
Date: Wed Nov 2 17:02:52 2011
New Revision: 1196689
URL: http://svn.apache.org/viewvc?rev=1196689&view=rev
Log: (empty)
Added:
incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/ReadWrite.java (with props)
Modified:
incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/Dataset.java
incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DataSourceImpl.java
incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DatasetImpl.java
incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/iterator/QueryIterGraph.java
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/Dataset.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/Dataset.java?rev=1196689&r1=1196688&r2=1196689&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/Dataset.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/Dataset.java Wed Nov 2 17:02:52 2011
@@ -43,7 +43,23 @@ public interface Dataset
public Iterator<String> listNames() ;
/** Get the lock for this dataset */
- public Lock getLock() ;
+ public Lock getLock() ;
+
+ /** Does this dataset support transactions?
+ * Supporting transactions mean that the dataset implementation
+ * provides {@link #begin}, {@link #commit}, {@link #abort},
+ * which otherwise may throw {@link UnsupportedOperationException}
+ */
+ public boolean supportsTransactions() ;
+
+
+ /** Start a transaction */
+ public void begin(ReadWrite mode) ;
+ public void commit() ;
+ public void abort() ;
+
+
+
/** Get the dataset in graph form */
public DatasetGraph asDatasetGraph() ;
Added: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/ReadWrite.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/ReadWrite.java?rev=1196689&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/ReadWrite.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/ReadWrite.java Wed Nov 2 17:02:52 2011
@@ -0,0 +1,25 @@
+/**
+ * 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.query;
+
+public enum ReadWrite
+{
+ READ,
+ WRITE
+}
Propchange: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/query/ReadWrite.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DataSourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DataSourceImpl.java?rev=1196689&r1=1196688&r2=1196689&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DataSourceImpl.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DataSourceImpl.java Wed Nov 2 17:02:52 2011
@@ -18,20 +18,23 @@
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 ;
-import com.hp.hpl.jena.query.DataSource ;
-import com.hp.hpl.jena.query.Dataset ;
-import com.hp.hpl.jena.query.LabelExistsException ;
-import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.ModelFactory ;
-import com.hp.hpl.jena.shared.Lock ;
-import com.hp.hpl.jena.sparql.util.NodeUtils ;
-import com.hp.hpl.jena.sparql.util.graph.GraphFactory ;
+import java.util.Iterator ;
+
+import org.openjena.atlas.lib.Cache ;
+import org.openjena.atlas.lib.CacheFactory ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.DataSource ;
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.LabelExistsException ;
+import com.hp.hpl.jena.query.ReadWrite ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.shared.Lock ;
+import com.hp.hpl.jena.sparql.ARQException ;
+import com.hp.hpl.jena.sparql.util.NodeUtils ;
+import com.hp.hpl.jena.sparql.util.graph.GraphFactory ;
/** A implementation of a DataSource, which is a mutable Dataset,
* a set of a single unnamed graph and a number (zero or
@@ -39,40 +42,31 @@ import com.hp.hpl.jena.sparql.util.graph
*/
public class DataSourceImpl implements DataSource
-{
- /*
- * synchronization: The ARQ policy is MRSW so read operations here
- * that cause internal datastructure changes need protecting to ensure
- * multiple read access does not corrupt those structures.
- * Write operations (add/remove models) do not because there
- * should be only one writer by contract.
- */
+{
+ // Use this as DatasetGraphImpl
- protected DatasetGraph dsg = null ;
- private Map<Graph, Model> cache = new HashMap<Graph, Model>() ;
+ protected DatasetGraph dsg = null ;
+ // Cache of graph -> model so that
+ // ds.getNamedGraph(...).operation1(...)
+ // ds.getNamedGraph(...).operation2(...)
+ // isn't too bad.
+ private Cache<Graph, Model> cache = CacheFactory.createCache(0.75f, 20) ;
+ private Object internalLock = new Object() ;
protected DataSourceImpl()
{}
-
-// public DataSourceImpl(DataSourceGraph otherDSG)
-// {
-// this.dsg = otherDSG ;
-// }
-
-
public static DataSource createMem()
{
// This may not be a defaultJena model - during testing,
- // we use a graph that is not value-awar for xsd:String vs plain literals.
-
+ // we use a graph that is not value-aware for xsd:String vs plain literals.
return new DataSourceImpl(ModelFactory.createModelForGraph(GraphFactory.createDefaultGraph())) ;
}
public static DataSource wrap(DatasetGraph datasetGraph)
{
DataSourceImpl ds = new DataSourceImpl() ;
- ds.dsg = datasetGraph ;
+ ds.dsg = datasetGraph ;
return ds ;
}
public static DataSource cloneStructure(DatasetGraph datasetGraph)
@@ -82,11 +76,6 @@ public class DataSourceImpl implements D
return ds ;
}
-// public DataSourceImpl(DatasetGraph datasetGraph)
-// {
-// dsg = new DatasetGraphMap(datasetGraph) ;
-// }
-
public DataSourceImpl(Model model)
{
addToCache(model) ;
@@ -96,35 +85,49 @@ public class DataSourceImpl implements D
public DataSourceImpl(Dataset ds)
{
- this.dsg = DatasetGraphFactory.create(ds.asDatasetGraph()) ;
+ this.dsg = DatasetGraphFactory.create(ds.asDatasetGraph()) ;
}
// Does it matter if this is not the same model each time?
@Override
public Model getDefaultModel()
- {
- return graph2model(dsg.getDefaultGraph()) ;
+ {
+ synchronized(internalLock)
+ {
+ return graph2model(dsg.getDefaultGraph()) ;
+ }
}
@Override
- public Lock getLock() { return dsg.getLock() ; }
-
+ public Lock getLock() { return dsg.getLock() ; }
+
+ @Override public boolean supportsTransactions() { return false ; }
+ @Override public void begin(ReadWrite mode) { throw new UnsupportedOperationException("Transactions not supported") ; }
+ @Override public void commit() { throw new UnsupportedOperationException("Transactions not supported") ; }
+ @Override public void abort() { throw new UnsupportedOperationException("Transactions not supported") ; }
+
@Override
public DatasetGraph asDatasetGraph() { return dsg ; }
@Override
public Model getNamedModel(String uri)
- {
- Node n = Node.createURI(uri) ;
- Graph g = dsg.getGraph(n) ;
- if ( g == null )
- return null ;
- return graph2model(g) ;
+ {
+ checkGraphName(uri) ;
+ Node n = Node.createURI(uri) ;
+ synchronized(internalLock)
+ {
+ Graph g = dsg.getGraph(n) ;
+ if ( g == null )
+ return null ;
+ return graph2model(g) ;
+ }
}
@Override
public void addNamedModel(String uri, Model model) throws LabelExistsException
{
+ checkGraphName(uri) ;
+ // Assumes single writer.
addToCache(model) ;
Node n = Node.createURI(uri) ;
dsg.addGraph(n, model.getGraph()) ;
@@ -133,14 +136,18 @@ public class DataSourceImpl implements D
@Override
public void removeNamedModel(String uri)
{
- Node n = Node.createURI(uri) ;
+ checkGraphName(uri) ;
+ Node n = Node.createURI(uri) ;
+ // Assumes single writer.
removeFromCache(dsg.getGraph(n)) ;
dsg.removeGraph(n) ;
}
@Override
public void replaceNamedModel(String uri, Model model)
- {
+ {
+ // Assumes single writer.
+ checkGraphName(uri) ;
Node n = Node.createURI(uri) ;
removeFromCache(dsg.getGraph(n)) ;
dsg.removeGraph(n) ;
@@ -150,7 +157,8 @@ public class DataSourceImpl implements D
@Override
public void setDefaultModel(Model model)
- {
+ {
+ // Assumes single writer.
removeFromCache(dsg.getDefaultGraph()) ;
addToCache(model) ;
dsg.setDefaultGraph(model.getGraph()) ;
@@ -158,12 +166,13 @@ public class DataSourceImpl implements D
@Override
public boolean containsNamedModel(String uri)
- {
- Node n = Node.createURI(uri) ;
- return dsg.containsGraph(n) ;
+ {
+ // Does not touch the cache.
+ checkGraphName(uri) ;
+ Node n = Node.createURI(uri) ;
+ return dsg.containsGraph(n) ;
}
- // Don't look in the cache - go direct to source
@Override
public Iterator<String> listNames()
{
@@ -171,8 +180,10 @@ public class DataSourceImpl implements D
}
-// -------
-// Cache models wrapping graph
+ // -------
+ // Cache models wrapping graphs
+ // Assumes outser syncrhonization of necessary (multiple readers possible).
+ // Assume MRSW (Multiple Reader OR Single Writer)
@Override
public void close()
@@ -181,29 +192,36 @@ public class DataSourceImpl implements D
cache = null ;
}
- synchronized
private void removeFromCache(Graph graph)
{
+ // Assume MRSW - no synchronized needed.
if ( graph == null )
return ;
- cache.remove(graph) ;
+ cache.remove(graph) ;
}
- synchronized
private void addToCache(Model model)
{
- cache.put(model.getGraph(), model) ;
+ // Assume MRSW - no synchronized needed.
+ cache.put(model.getGraph(), model) ;
}
- synchronized
private Model graph2model(Graph graph)
- {
+ {
+ // Called from readers -- outer synchronation needed.
Model model = cache.get(graph) ;
if ( model == null )
{
model = ModelFactory.createModelForGraph(graph) ;
cache.put(graph, model) ;
}
- return model ;
- }
+ return model ;
+ }
+
+ private static void checkGraphName(String uri)
+ {
+ if ( uri == null )
+ throw new ARQException("null for graph name") ;
+ }
+
}
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DatasetImpl.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DatasetImpl.java?rev=1196689&r1=1196688&r2=1196689&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DatasetImpl.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/core/DatasetImpl.java Wed Nov 2 17:02:52 2011
@@ -26,6 +26,7 @@ import org.openjena.atlas.lib.CacheFacto
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.ReadWrite ;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.rdf.model.ModelFactory ;
import com.hp.hpl.jena.shared.Lock ;
@@ -71,7 +72,12 @@ public class DatasetImpl implements Data
@Override
public Lock getLock() { return dsg.getLock() ; }
-
+
+ @Override public boolean supportsTransactions() { return false ; }
+ @Override public void begin(ReadWrite mode) { throw new UnsupportedOperationException("Transactions not supported") ; }
+ @Override public void commit() { throw new UnsupportedOperationException("Transactions not supported") ; }
+ @Override public void abort() { throw new UnsupportedOperationException("Transactions not supported") ; }
+
@Override
public DatasetGraph asDatasetGraph() { return dsg ; }
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/iterator/QueryIterGraph.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/iterator/QueryIterGraph.java?rev=1196689&r1=1196688&r2=1196689&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/iterator/QueryIterGraph.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/engine/main/iterator/QueryIterGraph.java Wed Nov 2 17:02:52 2011
@@ -151,13 +151,6 @@ public class QueryIterGraph extends Quer
return null ;
Node gn = graphNames.next() ;
-// Graph g = getExecContext().getDataset().getGraph(gn) ;
-// if ( g == null )
-// return null ;
-//
-// // Create a new context with a different active graph
-// ExecutionContext execCxt2 = new ExecutionContext(getExecContext(), g) ;
-
Binding b = parentBinding ;
if ( Var.isVar(opGraph.getNode()) )
// (graph ?g (...))
@@ -172,11 +165,9 @@ public class QueryIterGraph extends Quer
{
if ( !graphNode.isURI() )
// e.g. variable bound to a literal or blank node.
- // Alow this?
throw new ARQInternalErrorException("QueryIterGraphInner.buildIterator") ;
- //return null ;
- // TODO Think about avoiding substitution.
+ // Think about avoiding substitution.
// If the subpattern does not involve the vars from the binding, avoid the substitute.
Op op = QC.substitute(opGraph.getSubOp(), binding) ;
Graph g = outerCxt.getDataset().getGraph(graphNode) ;