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 2013/05/16 19:03:16 UTC
svn commit: r1483446 - in /jena/trunk/jena-tdb/src:
main/java/com/hp/hpl/jena/tdb/ main/java/com/hp/hpl/jena/tdb/graph/
main/java/com/hp/hpl/jena/tdb/solver/ main/java/com/hp/hpl/jena/tdb/store/
main/java/com/hp/hpl/jena/tdb/sys/ main/java/com/hp/hpl/j...
Author: andy
Date: Thu May 16 17:03:15 2013
New Revision: 1483446
URL: http://svn.apache.org/r1483446
Log:
Part of JENA-458.
Rework GraphTDB so that there is one class for graph views of the database.
Use as much of the machinery of ARQ general GraphView system while
still carrying around the necessary information for TDB SPARQL evaluation.
Graphs are still restricted to be within a transaction boundary.
Added:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java
- copied, changed from r1481108, jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java
Removed:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphNamedTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTriplesTDB.java
Modified:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/TDBLoader.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/TransactionHandlerTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/QueryEngineTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java
jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java
jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDB.java
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/TDBLoader.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/TDBLoader.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/TDBLoader.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/TDBLoader.java Thu May 16 17:03:15 2013
@@ -119,8 +119,6 @@ public class TDBLoader
loadModel(model, url, false) ;
}
-
-
/** Load the contents of URL into a model - may not be as efficient as bulk loading into a TDB graph */
public static void loadModel(Model model, String url, boolean showProgress)
{
@@ -240,21 +238,21 @@ public class TDBLoader
throw new TDBException("Not a triples language") ;
}
}
-
- if ( graph.getGraphNode() == null )
- loadDefaultGraph$(graph.getDataset(), urls, showProgress) ;
+
+ if ( graph.getGraphName() == null )
+ loadDefaultGraph$(graph.getDSG(), urls, showProgress) ;
else
- loadNamedGraph$(graph.getDataset(), graph.getGraphNode(), urls, showProgress) ;
+ loadNamedGraph$(graph.getDSG(), graph.getGraphName(), urls, showProgress) ;
}
// These are the basic operations for TDBLoader.
private static void loadGraph$(GraphTDB graph, InputStream input, boolean showProgress)
{
- if ( graph.getGraphNode() == null )
- loadDefaultGraph$(graph.getDataset(), input, showProgress) ;
+ if ( graph.getGraphName() == null )
+ loadDefaultGraph$(graph.getDSG(), input, showProgress) ;
else
- loadNamedGraph$(graph.getDataset(), graph.getGraphNode(), input, showProgress) ;
+ loadNamedGraph$(graph.getDSG(), graph.getGraphName(), input, showProgress) ;
}
private static void loadDefaultGraph$(DatasetGraphTDB dataset, List<String> urls, boolean showProgress)
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/BulkUpdateHandlerTDB.java Thu May 16 17:03:15 2013
@@ -22,13 +22,12 @@ import com.hp.hpl.jena.graph.BulkUpdateH
import com.hp.hpl.jena.graph.GraphEvents ;
import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler ;
-import com.hp.hpl.jena.tdb.store.GraphTDBBase ;
+import com.hp.hpl.jena.tdb.store.GraphTDB ;
public class BulkUpdateHandlerTDB extends SimpleBulkUpdateHandler implements BulkUpdateHandler
{
- GraphTDBBase graphTDB ;
-
- public BulkUpdateHandlerTDB(GraphTDBBase graph)
+ private final GraphTDB graphTDB ;
+ public BulkUpdateHandlerTDB(GraphTDB graph)
{
super(graph) ;
this.graphTDB = graph ;
@@ -41,7 +40,7 @@ public class BulkUpdateHandlerTDB extend
s = fix(s) ;
p = fix(p) ;
o = fix(o) ;
- GraphTDBBase.removeWorker(graphTDB, s,p,o) ;
+ graphTDB.remove(s, p, o) ;
manager.notifyEvent( graph, GraphEvents.remove( s, p, o ) );
}
@@ -51,7 +50,7 @@ public class BulkUpdateHandlerTDB extend
@Override
public void removeAll()
{
- GraphTDBBase.removeWorker(graphTDB, null, null, null) ;
- notifyRemoveAll();
+ graphTDB.remove(null, null, null) ;
+ notifyRemoveAll();
}
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/TransactionHandlerTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/TransactionHandlerTDB.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/TransactionHandlerTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/graph/TransactionHandlerTDB.java Thu May 16 17:03:15 2013
@@ -18,17 +18,18 @@
package com.hp.hpl.jena.tdb.graph;
-import com.hp.hpl.jena.graph.impl.TransactionHandlerBase;
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.impl.TransactionHandlerBase ;
+import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.store.GraphTDB ;
-import com.hp.hpl.jena.tdb.store.GraphTDB;
-
-/** TDB does not support ACID transactions - it uses the SPARQL/Update events.
- * It (weakly) flushes if commit is called although it denies supporting transactions
+/** Support for when TDB is used non-transactionally.does not support ACID transactions.
+ * Flushes if commit is called although it denies supporting transactions
*/
public class TransactionHandlerTDB extends TransactionHandlerBase //implements TransactionHandler
{
- private final GraphTDB graph ;
+ private final Graph graph ;
public TransactionHandlerTDB(GraphTDB graph)
{
@@ -38,6 +39,7 @@ public class TransactionHandlerTDB exten
@Override
public void abort()
{
+ // Not the Jena old-style transaction interface
throw new UnsupportedOperationException("TDB: 'abort' of a transaction not supported") ;
//log.warn("'Abort' of a transaction not supported - ignored") ;
}
@@ -49,7 +51,7 @@ public class TransactionHandlerTDB exten
@Override
public void commit()
{
- graph.sync() ;
+ TDB.sync(graph) ;
}
@Override
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/OpExecutorTDB.java Thu May 16 17:03:15 2013
@@ -45,9 +45,7 @@ import com.hp.hpl.jena.sparql.engine.opt
import com.hp.hpl.jena.sparql.expr.ExprList ;
import com.hp.hpl.jena.sparql.mgt.Explain ;
import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
-import com.hp.hpl.jena.tdb.store.GraphNamedTDB ;
import com.hp.hpl.jena.tdb.store.GraphTDB ;
-import com.hp.hpl.jena.tdb.store.GraphTriplesTDB ;
import com.hp.hpl.jena.tdb.store.NodeId ;
/** TDB executor for algebra expressions. It is the standard ARQ executor
@@ -170,11 +168,11 @@ public class OpExecutorTDB extends OpExe
ExecutionContext execCxt)
{
// Is it the real default graph (normal route or explicitly named)?
- if ( ! isDefaultGraphStorage(graph.getGraphNode()))
+ if ( ! isDefaultGraphStorage(graph.getGraphName()))
{
// Not default storage - it's a named graph in storage.
- DatasetGraphTDB ds = graph.getDataset() ;
- return optimizeExecuteQuads(ds, input, graph.getGraphNode(), opBGP.getPattern(), exprs, execCxt) ;
+ DatasetGraphTDB ds = graph.getDSG() ;
+ return optimizeExecuteQuads(ds, input, graph.getGraphName(), opBGP.getPattern(), exprs, execCxt) ;
}
// Execute a BGP on the real default graph
@@ -194,7 +192,7 @@ public class OpExecutorTDB extends OpExe
if ( pattern.size() >= 2 )
{
// Must be 2 or triples to reorder.
- ReorderTransformation transform = graph.getDataset().getReorderTransform() ;
+ ReorderTransformation transform = graph.getDSG().getReorderTransform() ;
if ( transform != null )
{
QueryIterPeek peek = QueryIterPeek.create(input, execCxt) ;
@@ -375,7 +373,10 @@ public class OpExecutorTDB extends OpExe
BasicPattern bgp = opBGP.getPattern() ;
Explain.explain("Execute", bgp, execCxt.getContext()) ;
// Triple-backed (but may be named as explicit default graph).
- return SolverLib.execute((GraphTDB)g, bgp, input, filter, execCxt) ;
+ //return SolverLib.execute((GraphTDB)g, bgp, input, filter, execCxt) ;
+ GraphTDB gtdb = (GraphTDB)g ;
+ Node gn = decideGraphNode(gtdb.getGraphName(), execCxt) ;
+ return SolverLib.execute(gtdb.getDSG(), gn, bgp, input, filter, execCxt) ;
}
Log.warn(this, "Non-GraphTDB passed to OpExecutorPlainTDB") ;
return super.execute(opBGP, input) ;
@@ -398,23 +399,12 @@ public class OpExecutorTDB extends OpExe
Graph g = execCxt.getActiveGraph() ;
if ( g instanceof GraphTDB )
{
- if ( g instanceof GraphTriplesTDB )
- {
- // Triples graph from TDB (which is the default graph of the dataset),
- // used a named graph in a composite dataset.
- BasicPattern bgp = opQuadPattern.getBasicPattern() ;
- Explain.explain("Execute", bgp, execCxt.getContext()) ;
- return SolverLib.execute((GraphTDB)g, bgp, input, filter, execCxt) ;
- }
-
- if ( g instanceof GraphNamedTDB )
- {
- // Legacy?/ Does not now happen?
- Explain.explain("Execute", opQuadPattern.getPattern(), execCxt.getContext()) ;
- // Quad-backed graph
- return SolverLib.execute(((GraphTDB)g).getDataset(), opQuadPattern.getGraphNode(), opQuadPattern.getBasicPattern(),
- input, filter, execCxt) ;
- }
+ // Triples graph from TDB (which is the default graph of the dataset),
+ // used a named graph in a composite dataset.
+ BasicPattern bgp = opQuadPattern.getBasicPattern() ;
+ Explain.explain("Execute", bgp, execCxt.getContext()) ;
+ // Don't pass in G -- gn may be different.
+ return SolverLib.execute(((GraphTDB)g).getDSG(), gn, bgp, input, filter, execCxt) ;
}
Log.warn(this, "Non-DatasetGraphTDB passed to OpExecutorPlainTDB") ;
return super.execute(opQuadPattern, input) ;
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/QueryEngineTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/QueryEngineTDB.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/QueryEngineTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/QueryEngineTDB.java Thu May 16 17:03:15 2013
@@ -38,7 +38,7 @@ import com.hp.hpl.jena.tdb.TDB ;
import com.hp.hpl.jena.tdb.TDBException ;
import com.hp.hpl.jena.tdb.migrate.A2 ;
import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
-import com.hp.hpl.jena.tdb.store.GraphNamedTDB ;
+import com.hp.hpl.jena.tdb.store.GraphTDB ;
import com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction ;
// This exists to intercept the query execution setup.
@@ -110,7 +110,7 @@ public class QueryEngineTDB extends Quer
// Rewrite so that any explicitly named "default graph" is union graph.
// And set the default graph to be the union graph as well.
DatasetGraphTDB ds = ((DatasetGraphTDB)dsg).duplicate() ;
- ds.setEffectiveDefaultGraph(new GraphNamedTDB(ds, Quad.unionGraph)) ;
+ ds.setEffectiveDefaultGraph(new GraphTDB(ds, Quad.unionGraph)) ;
Explain.explain("REWRITE(Union default graph)", op, context) ;
dsg = ds ;
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java Thu May 16 17:03:15 2013
@@ -70,8 +70,9 @@ public class SolverLib
QueryIterator input, Filter<Tuple<NodeId>> filter,
ExecutionContext execCxt)
{
+ // Maybe default graph or named graph.
NodeTupleTable ntt = graph.getNodeTupleTable() ;
- return execute(ntt, null, pattern, input, filter, execCxt) ;
+ return execute(ntt, graph.getGraphName(), pattern, input, filter, execCxt) ;
}
/** Non-reordering execution of a quad pattern, given a iterator of bindings as input.
@@ -82,7 +83,8 @@ public class SolverLib
QueryIterator input, Filter<Tuple<NodeId>> filter,
ExecutionContext execCxt)
{
- return execute(ds.getQuadTable().getNodeTupleTable(), graphNode, pattern, input, filter, execCxt) ;
+ NodeTupleTable ntt = GraphTDB.chooseNodeTupleTable(ds, graphNode) ;
+ return execute(ntt, graphNode, pattern, input, filter, execCxt) ;
}
public static Iterator<BindingNodeId> convertToIds(Iterator<Binding> iterBindings, NodeTable nodeTable)
@@ -93,7 +95,7 @@ public class SolverLib
// The worker. Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
- // graphNode may be null, meaning we should make triples unique.
+ // graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern,
QueryIterator input, Filter<Tuple<NodeId>> filter,
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java Thu May 16 17:03:15 2013
@@ -203,26 +203,24 @@ public class DatasetGraphTDB extends Dat
@Override
protected Graph _createDefaultGraph()
{
- return new GraphTriplesTDB(this) ;
- // This also works - but it's close to a release so leave as is.
- //return new GraphNamedTDB(this, null) ;
+ return new GraphTDB(this, null) ;
}
@Override
protected Graph _createNamedGraph(Node graphNode)
{
- return new GraphNamedTDB(this, graphNode) ;
+ return new GraphTDB(this, graphNode) ;
}
- public void setEffectiveDefaultGraph(GraphTDB g) { effectiveDefaultGraph = g ; }
+ public void setEffectiveDefaultGraph(GraphTDB g) { effectiveDefaultGraph = g ; }
- public GraphTDB getEffectiveDefaultGraph() { return effectiveDefaultGraph ; }
+ public GraphTDB getEffectiveDefaultGraph() { return effectiveDefaultGraph ; }
- public StorageConfig getConfig() { return config ; }
+ public StorageConfig getConfig() { return config ; }
- public ReorderTransformation getReorderTransform() { return transform ; }
+ public ReorderTransformation getReorderTransform() { return transform ; }
- public DatasetPrefixesTDB getPrefixes() { return prefixes ; }
+ public DatasetPrefixesTDB getPrefixes() { return prefixes ; }
static private Transform<Tuple<NodeId>, NodeId> project0 = new Transform<Tuple<NodeId>, NodeId>()
{
Copied: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java (from r1481108, jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java)
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java?p2=jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java&p1=jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java&r1=1481108&r2=1483446&rev=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java Thu May 16 17:03:15 2013
@@ -18,63 +18,77 @@
package com.hp.hpl.jena.tdb.store;
-import static com.hp.hpl.jena.sparql.core.Quad.isUnionGraph ;
-
import java.util.Iterator ;
import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.iterator.Transform ;
+import org.apache.jena.atlas.lib.Closeable ;
+import org.apache.jena.atlas.lib.Sync ;
import org.apache.jena.atlas.lib.Tuple ;
-import org.slf4j.Logger ;
+import org.apache.jena.riot.other.GLib ;
-import com.hp.hpl.jena.graph.BulkUpdateHandler ;
-import com.hp.hpl.jena.graph.Capabilities ;
-import com.hp.hpl.jena.graph.GraphEvents ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.TransactionHandler ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.graph.TripleMatch ;
-import com.hp.hpl.jena.graph.impl.GraphBase ;
+import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.shared.PrefixMapping ;
+import com.hp.hpl.jena.sparql.core.GraphView ;
import com.hp.hpl.jena.sparql.core.Quad ;
-import com.hp.hpl.jena.tdb.TDB ;
import com.hp.hpl.jena.tdb.TDBException ;
import com.hp.hpl.jena.tdb.graph.BulkUpdateHandlerTDB ;
import com.hp.hpl.jena.tdb.graph.TransactionHandlerTDB ;
-import com.hp.hpl.jena.tdb.lib.NodeFmtLib ;
import com.hp.hpl.jena.tdb.nodetable.NodeTupleTable ;
-import com.hp.hpl.jena.tdb.sys.SystemTDB ;
import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
import com.hp.hpl.jena.util.iterator.WrappedIterator ;
/** General operations for TDB graphs (free-standing graph, default graph and named graphs) */
-public abstract class GraphTDBBase extends GraphBase implements GraphTDB
+public class GraphTDB extends GraphView implements Closeable, Sync
{
- private final TransactionHandler transactionHandler = new TransactionHandlerTDB(this) ;
private final BulkUpdateHandler bulkUpdateHandler = new BulkUpdateHandlerTDB(this) ;
- protected final DatasetGraphTDB dataset ;
- protected final Node graphNode ;
-
- public GraphTDBBase(DatasetGraphTDB dataset, Node graphName)
+ private final TransactionHandler transactionHandler = new TransactionHandlerTDB(this) ;
+
+ // Switch this to DatasetGraphTransaction
+ private final DatasetGraphTDB dataset ;
+
+ public GraphTDB(DatasetGraphTDB dataset, Node graphName)
{
- super() ;
- this.dataset = dataset ;
- this.graphNode = graphName ;
+ super(dataset, graphName) ;
+ this.dataset = dataset ;
}
- @Override
- public final Node getGraphNode() { return graphNode ; }
- @Override
- public final DatasetGraphTDB getDataset() { return dataset ; }
+ /** get the current TDB dataset graph - changes for transactions */
+ public DatasetGraphTDB getDSG()
+ //{ return dataset.get() ; }
+ { return dataset ; }
- // Intercept performAdd/preformDelete and bracket in start/finish markers
+ /** The NodeTupleTable for this graph */
+ public NodeTupleTable getNodeTupleTable()
+ {
+ return chooseNodeTupleTable(getDSG(), getGraphName()) ;
+ }
+
+ public static NodeTupleTable chooseNodeTupleTable(DatasetGraphTDB dsg, Node graphNode)
+ {
+ if ( graphNode == null || Quad.isDefaultGraph(graphNode) )
+ return dsg.getTripleTable().getNodeTupleTable() ;
+ else
+ // Includes Node.ANY and union graph
+ return dsg.getQuadTable().getNodeTupleTable() ;
+ }
+
+ @Override
+ protected PrefixMapping createPrefixMapping()
+ {
+ if ( isDefaultGraph() )
+ return getDSG().getPrefixes().getPrefixMapping() ;
+ if ( isUnionGraph() )
+ return getDSG().getPrefixes().getPrefixMapping() ;
+ return getDSG().getPrefixes().getPrefixMapping(getGraphName().getURI()) ;
+ }
@Override
public final void performAdd(Triple triple)
{
- // Should we do try{}finally{}?
- // Here, no, if there is an exeception, the database is bad.
startUpdate() ;
- _performAdd(triple) ;
+ super.performAdd(triple) ;
finishUpdate() ;
}
@@ -82,61 +96,16 @@ public abstract class GraphTDBBase exten
public final void performDelete(Triple triple)
{
startUpdate() ;
- _performDelete(triple) ;
+ super.performDelete(triple) ;
finishUpdate() ;
}
@Override
- protected final ExtendedIterator<Triple> graphBaseFind(TripleMatch m)
- {
- // Explicitly named default graph
- if ( isDefaultGraph(graphNode) )
- // Default graph.
- return graphBaseFindDft(getDataset(), m) ;
- // Includes union graph
- return graphBaseFindNG(getDataset(), graphNode, m) ;
- }
-
- protected final void _performAdd( Triple t )
- {
- if ( isUnionGraph(graphNode) )
- throw new TDBException("Can't add a triple to the RDF merge of all named graphs") ;
- dataset.add(graphNode(), t.getSubject(), t.getPredicate(), t.getObject()) ;
- }
-
- protected final void _performDelete( Triple t )
- {
- if ( isUnionGraph(graphNode) )
- throw new TDBException("Can't delete triple from the RDF merge of all named graphs") ;
- dataset.delete(graphNode(), t.getSubject(), t.getPredicate(), t.getObject()) ;
- }
-
- @Override
public final void sync() { dataset.sync(); }
@Override
final public void close() { sync() ; }
- @Override
- // make submodels think about this.
- public abstract String toString() ;
-
- private Node graphNode() { return ( graphNode != null ) ? graphNode : Quad.defaultGraphNodeGenerated ; }
-
- protected static boolean isDefaultGraph(Node g)
- {
- return g == null || Quad.isDefaultGraph(g) ;
- }
-
- protected void duplicate(Triple t)
- {
- if ( TDB.getContext().isTrue(SystemTDB.symLogDuplicates) && getLog().isInfoEnabled() )
- {
- String $ = NodeFmtLib.displayStr(t, this.getPrefixMapping()) ;
- getLog().info("Duplicate: ("+$+")") ;
- }
- }
-
protected static ExtendedIterator<Triple> graphBaseFindDft(DatasetGraphTDB dataset, TripleMatch m)
{
Iterator<Quad> iterQuads = dataset.find(Quad.defaultGraphIRI, m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) ;
@@ -165,24 +134,52 @@ public abstract class GraphTDBBase exten
return WrappedIterator.createNoRemove(iterTriples) ;
}
- protected abstract Logger getLog() ;
+ @Override
+ protected ExtendedIterator<Triple> graphUnionFind(Node s, Node p, Node o)
+ {
+ Node g = Quad.unionGraph ;
+ Iterator<Quad> iterQuads = getDSG().find(g, s, p, o) ;
+ Iterator<Triple> iter = GLib.quads2triples(iterQuads) ;
+ // Suppress duplicates after projecting to triples.
+ // TDB guarantees that duplicates are adjacent.
+ // See SolverLib.
+ iter = Iter.distinctAdjacent(iter) ;
+ return WrappedIterator.createNoRemove(iter) ;
+ }
- /** Iterator over something that, when counted, is the graph size. */
- protected abstract Iterator<?> countThis() ;
-
- public void startRead() { dataset.startRead() ; }
- public void finishRead() { dataset.finishRead() ; }
+ public void startRead() { getDSG().startRead() ; }
+ public void finishRead() { getDSG().finishRead() ; }
- public final void startUpdate() { dataset.startUpdate() ; }
- public final void finishUpdate() { dataset.finishUpdate() ; }
+ public final void startUpdate() { getDSG().startUpdate() ; }
+ public final void finishUpdate() { getDSG().finishUpdate() ; }
@Override
protected final int graphBaseSize()
{
- Iterator<?> iter = countThis() ;
+ if ( isDefaultGraph() )
+ return (int)getNodeTupleTable().size() ;
+
+ Node gn = getGraphName() ;
+ boolean unionGraph = isUnionGraph(gn) ;
+ gn = unionGraph ? Node.ANY : gn ;
+ Iterator<Tuple<NodeId>> iter = getDSG().getQuadTable().getNodeTupleTable().findAsNodeIds(gn, null, null, null) ;
+ if ( unionGraph )
+ {
+ iter = Iter.map(iter, project4TupleTo3Tuple) ;
+ iter = Iter.distinctAdjacent(iter) ;
+ }
return (int)Iter.count(iter) ;
}
+ private static Transform<Tuple<NodeId>, Tuple<NodeId>> project4TupleTo3Tuple = new Transform<Tuple<NodeId>, Tuple<NodeId>>(){
+ @Override
+ public Tuple<NodeId> convert(Tuple<NodeId> item)
+ {
+ if ( item.size() != 4 )
+ throw new TDBException("Expected a Tuple of 4, got: "+item) ;
+ return Tuple.create(item.get(1), item.get(2), item.get(3)) ;
+ }} ;
+
// Convert from Iterator<Quad> to Iterator<Triple>
static class ProjectQuadsToTriples implements Iterator<Triple>
{
@@ -205,10 +202,6 @@ public abstract class GraphTDBBase exten
public void remove() { iter.remove(); }
}
- @Deprecated
- @Override
- public BulkUpdateHandler getBulkUpdateHandler() { return bulkUpdateHandler ; }
-
@Override
public Capabilities getCapabilities()
{
@@ -237,6 +230,11 @@ public abstract class GraphTDBBase exten
return super.getCapabilities() ;
}
+ @Deprecated
+ @Override
+ public BulkUpdateHandler getBulkUpdateHandler()
+ { return bulkUpdateHandler ; }
+
@Override
public TransactionHandler getTransactionHandler()
{ return transactionHandler ; }
@@ -263,20 +261,19 @@ public abstract class GraphTDBBase exten
//getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ;
}
-
private static final int sliceSize = 1000 ;
- public static void removeWorker(GraphTDBBase g, Node s, Node p, Node o)
+ public static void removeWorker(GraphTDB gv, Node s, Node p, Node o)
{
- g.startUpdate() ;
-
+ NodeTupleTable t = gv.getNodeTupleTable() ;
+ DatasetGraphTDB dsg = gv.getDSG() ;
+ dsg.startUpdate() ;
+ Node gn = gv.getGraphName() ;
+
// Delete in batches.
// That way, there is no active iterator when a delete
// from the indexes happens.
- NodeTupleTable t = g.getNodeTupleTable() ;
- Node gn = g.getGraphNode() ;
-
@SuppressWarnings("unchecked")
Tuple<NodeId>[] array = (Tuple<NodeId>[])new Tuple<?>[sliceSize] ;
@@ -313,7 +310,6 @@ public abstract class GraphTDBBase exten
break ;
}
- g.finishUpdate() ;
+ dsg.finishUpdate() ;
}
-
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/sys/TDBInternal.java Thu May 16 17:03:15 2013
@@ -113,7 +113,5 @@ public class TDBInternal
return ((DatasetGraphTransaction)datasetGraph).getBaseDatasetGraph() ;
throw new TDBException("Not a suitable DatasetGraph to get it's base storage: "+Utils.classShortName(datasetGraph.getClass())) ;
}
-
-
}
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetGraphTransaction.java Thu May 16 17:03:15 2013
@@ -83,14 +83,16 @@ public class DatasetGraphTransaction ext
return get() ;
}
+ /** Access the base storage - use with care */
public DatasetGraphTDB getBaseDatasetGraph()
{
checkNotClosed() ;
return sConn.getBaseDataset() ;
}
+ /** Get the current DatasetGraphTDB */
@Override
- protected DatasetGraphTDB get()
+ public DatasetGraphTDB get()
{
if ( isInTransaction() )
{
Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/assembler/TestTDBAssembler.java Thu May 16 17:03:15 2013
@@ -102,7 +102,7 @@ public class TestTDBAssembler extends Ba
Graph graph = ((Model)thing).getGraph() ;
assertTrue(graph instanceof GraphTDB) ;
- DatasetGraphTDB ds = ((GraphTDB)graph).getDataset() ;
+ DatasetGraphTDB ds = ((GraphTDB)graph).getDSG() ;
if ( ds != null )
ds.close();
}
@@ -137,7 +137,7 @@ public class TestTDBAssembler extends Ba
assertTrue(graph instanceof GraphTDB) ;
- DatasetGraphTDB ds = ((GraphTDB)graph).getDataset() ;
+ DatasetGraphTDB ds = ((GraphTDB)graph).getDSG() ;
if ( ds != null )
ds.close();
}
Modified: jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDB.java?rev=1483446&r1=1483445&r2=1483446&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDB.java (original)
+++ jena/trunk/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/store/TestDatasetTDB.java Thu May 16 17:03:15 2013
@@ -18,14 +18,22 @@
package com.hp.hpl.jena.tdb.store;
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
import org.junit.Test ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.NodeFactory ;
import com.hp.hpl.jena.query.* ;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.rdf.model.ModelFactory ;
import com.hp.hpl.jena.rdf.model.Property ;
import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
import com.hp.hpl.jena.sparql.core.Quad ;
import com.hp.hpl.jena.sparql.sse.SSE ;
import com.hp.hpl.jena.tdb.TDB ;
@@ -60,18 +68,18 @@ public class TestDatasetTDB extends Base
private static void load2(Model model)
{
- Resource r1 = model.createResource(base1+"r2") ;
+ Resource r2 = model.createResource(base1+"r2") ;
Property p1 = model.createProperty(baseNS+"p1") ;
- model.add(r1, p1, "x1") ;
- model.add(r1, p1, "x2") ;
+ model.add(r2, p1, "x1") ;
+ model.add(r2, p1, "x2") ;
}
private static void load3(Model model)
{
- Resource r1 = model.createResource(base1+"r3") ;
+ Resource r3 = model.createResource(base1+"r3") ;
Property p1 = model.createProperty(baseNS+"p2") ;
- model.add(r1, p1, "x1") ;
- model.add(r1, p1, "x2") ;
+ model.add(r3, p1, "x1") ;
+ model.add(r3, p1, "x2") ;
}
@Test public void prefix1()
@@ -184,6 +192,24 @@ public class TestDatasetTDB extends Base
}
assertTrue(m.isIsomorphicWith(m2)) ;
}
+
+ @Test public void special_debug()
+ {
+ Dataset ds = create() ;
+
+ load1(ds.getDefaultModel()) ;
+ load2(ds.getNamedModel("http://example/graph1")) ;
+ load3(ds.getNamedModel("http://example/graph2")) ;
+
+ DatasetGraph dsg = ds.asDatasetGraph() ;
+ Node s = null ;
+ Node p = NodeFactory.createURI(baseNS+"p1") ;
+ Node o = SSE.parseNode("'x1'") ;
+
+ Iterator<Quad> iter = dsg.find(Node.ANY, s,p,o) ;
+ Iter.print(iter) ;
+ }
+
@Test public void special4()
{
@@ -196,18 +222,39 @@ public class TestDatasetTDB extends Base
Model m = ModelFactory.createDefaultModel() ;
load2(m) ;
load3(m) ;
- TDB.sync(ds) ;
String qs = "PREFIX : <"+baseNS+"> SELECT (COUNT(?x) as ?c) WHERE { ?x (:p1|:p2) 'x1' }" ;
- Query q = QueryFactory.create(qs, Syntax.syntaxARQ) ;
- QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
+ Query q = QueryFactory.create(qs) ;
+
+ // Model
+ QueryExecution qExec = QueryExecutionFactory.create(q, m) ;
+ long c_m = qExec.execSelect().next().getLiteral("c").getLong() ;
+
+ // dataset
+ qExec = QueryExecutionFactory.create(q, ds) ;
qExec.getContext().set(TDB.symUnionDefaultGraph, true) ;
- long c1 = qExec.execSelect().next().getLiteral("c").getLong() ;
+ long c_ds = qExec.execSelect().next().getLiteral("c").getLong() ;
qExec.close() ;
- qExec = QueryExecutionFactory.create(q, m) ;
- long c2 = qExec.execSelect().next().getLiteral("c").getLong() ;
- assertEquals(c1, c2) ;
+ // --------
+ SSE.write(m) ;
+ System.out.println() ;
+ SSE.write(ds) ;
+
+ String qs2 = "PREFIX : <"+baseNS+"> SELECT * WHERE { ?x (:p1|:p2) 'x1' }" ;
+ Query q2 = QueryFactory.create(qs2) ;
+ System.out.println("Dataset") ;
+ qExec = QueryExecutionFactory.create(q2, ds) ;
+ qExec.getContext().set(TDB.symUnionDefaultGraph, true) ;
+ ResultSetFormatter.out(qExec.execSelect()) ;
+
+ System.out.println("Model") ;
+ qExec = QueryExecutionFactory.create(q2, m) ;
+ ResultSetFormatter.out(qExec.execSelect()) ;
+ // --------
+
+
+ assertEquals(c_m, c_ds) ;
qExec.close() ;
}
@@ -259,6 +306,16 @@ public class TestDatasetTDB extends Base
Query q = QueryFactory.create(qs) ;
QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
Model m2 = qExec.execConstruct() ;
+ if ( ! m.isIsomorphicWith(m2) )
+ {
+ System.out.println(m.getGraph().getClass().getSimpleName()+"/"+m.size()+" : "+m2.getGraph().getClass().getSimpleName()+"/"+m2.size()) ;
+ System.out.println("---- Different:" ) ;
+ RDFDataMgr.write(System.out, m, Lang.TTL) ;
+ System.out.println("---- ----" ) ;
+ RDFDataMgr.write(System.out, m2, Lang.TTL) ;
+ System.out.println("---- ----") ;
+ }
+
assertTrue(m.isIsomorphicWith(m2)) ;
}