Author: andy Date: Fri Oct 25 13:06:58 2013 New Revision: 1535724 URL: http://svn.apache.org/r1535724 Log: JENA-571
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/graph/Graph.java jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/graph/Graph.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/graph/Graph.java?rev=1535724&r1=1535723&r2=1535724&view=diff ============================================================================== --- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/graph/Graph.java (original) +++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/graph/Graph.java Fri Oct 25 13:06:58 2013 @@ -163,7 +163,7 @@ public interface Graph extends GraphAdd int size(); /** - Answer true iff .close() has been called onn this Graph. + Answer true iff .close() has been called on this Graph. */ boolean isClosed(); } Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java?rev=1535724&r1=1535723&r2=1535724&view=diff ============================================================================== --- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java (original) +++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java Fri Oct 25 13:06:58 2013 @@ -16,7 +16,7 @@ * limitations under the License. */ -package com.hp.hpl.jena.tdb.store; +package com.hp.hpl.jena.tdb.store ; import java.util.Iterator ; @@ -38,25 +38,28 @@ import com.hp.hpl.jena.tdb.nodetable.Nod 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 class GraphTDB extends GraphView implements Closeable, Sync -{ - private final BulkUpdateHandler bulkUpdateHandler = new BulkUpdateHandlerTDB(this) ; +/** + * General operations for TDB graphs (free-standing graph, default graph and + * named graphs) + */ +public class GraphTDB extends GraphView implements Closeable, Sync { + private final BulkUpdateHandler bulkUpdateHandler = new BulkUpdateHandlerTDB(this) ; private final TransactionHandler transactionHandler = new TransactionHandlerTDB(this) ; - + // Switch this to DatasetGraphTransaction - private final DatasetGraphTDB dataset ; - - public GraphTDB(DatasetGraphTDB dataset, Node graphName) { + private final DatasetGraphTDB dataset ; + + public GraphTDB(DatasetGraphTDB dataset, Node graphName) { super(dataset, graphName) ; this.dataset = dataset ; } - - /** get the current TDB dataset graph - changes for transactions */ - public DatasetGraphTDB getDSG() - { return dataset ; } - /** The NodeTupleTable for this graph */ + /** get the current TDB dataset graph - changes for transactions */ + public DatasetGraphTDB getDSG() { + return dataset ; + } + + /** The NodeTupleTable for this graph */ public NodeTupleTable getNodeTupleTable() { return getDSG().chooseNodeTupleTable(getGraphName()) ; } @@ -68,7 +71,7 @@ public class GraphTDB extends GraphView public static NodeTupleTable chooseNodeTupleTable(DatasetGraphTDB dsg, Node graphNode) { return dsg.chooseNodeTupleTable(graphNode) ; } - + @Override protected PrefixMapping createPrefixMapping() { if ( isDefaultGraph() ) @@ -77,9 +80,9 @@ public class GraphTDB extends GraphView return getDSG().getPrefixes().getPrefixMapping() ; return getDSG().getPrefixes().getPrefixMapping(getGraphName().getURI()) ; } - + @Override - public final void performAdd(Triple triple) { + public final void performAdd(Triple triple) { startUpdate() ; super.performAdd(triple) ; finishUpdate() ; @@ -91,40 +94,45 @@ public class GraphTDB extends GraphView super.performDelete(triple) ; finishUpdate() ; } - + @Override - public final void sync() { dataset.sync(); } - + public final void sync() { + dataset.sync() ; + } + @Override - final public void close() { sync() ; } - - protected static ExtendedIterator<Triple> graphBaseFindDft(DatasetGraphTDB dataset, TripleMatch m) - { + final public void close() { + sync() ; + super.close() ; + } + + protected static ExtendedIterator<Triple> graphBaseFindDft(DatasetGraphTDB dataset, TripleMatch m) { Iterator<Quad> iterQuads = dataset.find(Quad.defaultGraphIRI, m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) ; if ( iterQuads == null ) return com.hp.hpl.jena.util.iterator.NullIterator.instance() ; // Can't be duplicates - fixed graph node.. - Iterator<Triple> iterTriples = new ProjectQuadsToTriples(Quad.defaultGraphIRI , iterQuads) ; + Iterator<Triple> iterTriples = new ProjectQuadsToTriples(Quad.defaultGraphIRI, iterQuads) ; return WrappedIterator.createNoRemove(iterTriples) ; } - + protected static ExtendedIterator<Triple> graphBaseFindNG(DatasetGraphTDB dataset, Node graphNode, TripleMatch m) { Node gn = graphNode ; - // Explicitly named union graph. + // Explicitly named union graph. if ( isUnionGraph(gn) ) gn = Node.ANY ; - Iterator<Quad> iter = dataset.getQuadTable().find(gn, m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) ; + Iterator<Quad> iter = dataset.getQuadTable().find(gn, m.getMatchSubject(), m.getMatchPredicate(), + m.getMatchObject()) ; if ( iter == null ) return com.hp.hpl.jena.util.iterator.NullIterator.instance() ; - - Iterator<Triple> iterTriples = new ProjectQuadsToTriples((gn == Node.ANY ? null : gn) , iter) ; - + + Iterator<Triple> iterTriples = new ProjectQuadsToTriples((gn == Node.ANY ? null : gn), iter) ; + if ( gn == Node.ANY ) iterTriples = Iter.distinct(iterTriples) ; return WrappedIterator.createNoRemove(iterTriples) ; } - + @Override protected ExtendedIterator<Triple> graphUnionFind(Node s, Node p, Node o) { Node g = Quad.unionGraph ; @@ -136,21 +144,31 @@ public class GraphTDB extends GraphView iter = Iter.distinctAdjacent(iter) ; return WrappedIterator.createNoRemove(iter) ; } - - public void startRead() { getDSG().startRead() ; } - public void finishRead() { getDSG().finishRead() ; } - public final void startUpdate() { getDSG().startUpdate() ; } - public final void finishUpdate() { getDSG().finishUpdate() ; } + public void startRead() { + getDSG().startRead() ; + } + + public void finishRead() { + getDSG().finishRead() ; + } + + public final void startUpdate() { + getDSG().startUpdate() ; + } + + public final void finishUpdate() { + getDSG().finishUpdate() ; + } @Override protected final int graphBaseSize() { if ( isDefaultGraph() ) return (int)getNodeTupleTable().size() ; - + Node gn = getGraphName() ; - boolean unionGraph = isUnionGraph(gn) ; - gn = unionGraph ? Node.ANY : gn ; + 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) ; @@ -158,88 +176,134 @@ public class GraphTDB extends GraphView } 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.createTuple(item.get(1), item.get(2), item.get(3)) ; - }} ; - + + 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.createTuple(item.get(1), + item.get(2), + item.get(3)) ; + } + } ; + // Convert from Iterator<Quad> to Iterator<Triple> static class ProjectQuadsToTriples implements Iterator<Triple> { private final Iterator<Quad> iter ; - private final Node graphNode ; - /** Project quads to triples - check the graphNode is as expected if not null */ - ProjectQuadsToTriples(Node graphNode, Iterator<Quad> iter) { this.graphNode = graphNode ; this.iter = iter ; } + private final Node graphNode ; + + /** + * Project quads to triples - check the graphNode is as expected if not + * null + */ + ProjectQuadsToTriples(Node graphNode, Iterator<Quad> iter) { + this.graphNode = graphNode ; + this.iter = iter ; + } + @Override - public boolean hasNext() { return iter.hasNext() ; } - + public boolean hasNext() { + return iter.hasNext() ; + } + @Override - public Triple next() { - Quad q = iter.next(); - if ( graphNode != null && ! q.getGraph().equals(graphNode)) - throw new InternalError("ProjectQuadsToTriples: Quads from unexpected graph (expected="+graphNode+", got="+q.getGraph()+")") ; + public Triple next() { + Quad q = iter.next() ; + if ( graphNode != null && !q.getGraph().equals(graphNode) ) + throw new InternalError("ProjectQuadsToTriples: Quads from unexpected graph (expected=" + graphNode + + ", got=" + q.getGraph() + ")") ; return q.asTriple() ; } + @Override - public void remove() { iter.remove(); } + public void remove() { + iter.remove() ; + } } - + @Override public Capabilities getCapabilities() { if ( capabilities == null ) - capabilities = new Capabilities(){ + capabilities = new Capabilities() { @Override - public boolean sizeAccurate() { return true; } + public boolean sizeAccurate() { + return true ; + } + @Override - public boolean addAllowed() { return true ; } + public boolean addAllowed() { + return true ; + } + @Override - public boolean addAllowed( boolean every ) { return true; } + public boolean addAllowed(boolean every) { + return true ; + } + @Override - public boolean deleteAllowed() { return true ; } + public boolean deleteAllowed() { + return true ; + } + @Override - public boolean deleteAllowed( boolean every ) { return true; } + public boolean deleteAllowed(boolean every) { + return true ; + } + @Override - public boolean canBeEmpty() { return true; } + public boolean canBeEmpty() { + return true ; + } + @Override - public boolean iteratorRemoveAllowed() { return false; } /* ** */ + public boolean iteratorRemoveAllowed() { + return false ; + } /* ** */ + @Override - public boolean findContractSafe() { return true; } + public boolean findContractSafe() { + return true ; + } + @Override - public boolean handlesLiteralTyping() { return false; } /* ** */ - } ; - + public boolean handlesLiteralTyping() { + return false ; + } /* ** */ + } ; + return super.getCapabilities() ; } - + @Deprecated @Override - public BulkUpdateHandler getBulkUpdateHandler() - { return bulkUpdateHandler ; } - + public BulkUpdateHandler getBulkUpdateHandler() { + return bulkUpdateHandler ; + } + @Override - public TransactionHandler getTransactionHandler() - { return transactionHandler ; } + public TransactionHandler getTransactionHandler() { + return transactionHandler ; + } @Override public void clear() { dataset.deleteAny(getGraphName(), Node.ANY, Node.ANY, Node.ANY) ; - getEventManager().notifyEvent(this, GraphEvents.removeAll ) ; + getEventManager().notifyEvent(this, GraphEvents.removeAll) ; } - + @Override - public void remove( Node s, Node p, Node o ) { - if ( getEventManager().listening() ) - { + public void remove(Node s, Node p, Node o) { + if ( getEventManager().listening() ) { // Have to do it the hard way so that triple events happen. super.remove(s, p, o) ; return ; } - - dataset.deleteAny(getGraphName(), s, p, o); + + dataset.deleteAny(getGraphName(), s, p, o) ; // We know no one is listening ... - //getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ; + // getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ; } }