private static Object calcKey(Graph graph) { if ( graph instanceof GraphView ) // Use the database as the key so that transactions are started once-per-storage. // This the case of a graph from some storage being placed in a general dataset. return ((GraphView)graph).getDataset(); if ( graph instanceof InfGraph ) // InfGraph TransactionHandler passes the graph transaction to the base graph. // This calcKey allows the base graph to be included in the dataset as well as the InfGraph. return calcKey(((InfGraph)graph).getRawGraph()); // These should be handled by their respective graph transaction handler // or the graph is overriding that behaviour for some reason. // if ( graph instanceof GraphWrapper ) // return calcKey(((GraphWrapper)graph).get()); // if ( graph instanceof WrappedGraph ) // return calcKey(((WrappedGraph)graph).getWrapped()); return graph; }
public static DatasetGraph create(Graph graph) { // Find the deepest graph, the one that may be attached to a DatasetGraph. Graph graph2 = unwrap(graph); if ( graph2 instanceof GraphView ) { // This becomes a simple class that passes all transaction operations the // underlying dataset and masks the fact here are other graphs in the storage. return new DatasetGraphOne(graph, ((GraphView)graph2).getDataset()); } // Didn't find a GraphView so no backing DatasetGraph; work on the graph as given. return new DatasetGraphOne(graph); }
protected ExtendedIterator<Triple> graphUnionFind(Node s, Node p, Node o) { Node g = graphNode(gn) ; // Implementations may wish to do better so this is separated out. // For example, Iter.distinctAdjacent is a lot cheaper than Iter.distinct // but assumes things come back in a particular order Iterator<Quad> iterQuads = getDataset().find(g, s, p, o) ; Iterator<Triple> iter = GLib.quads2triples(iterQuads) ; // Suppress duplicates after projecting to triples. iter = Iter.distinct(iter) ; return WrappedIterator.createNoRemove(iter) ; }
protected static QueryExecution make(Query query, Model model) { Dataset dataset = DatasetFactory.wrap(model); Graph g = unwrap(model.getGraph()); if ( g instanceof GraphView ) { GraphView gv = (GraphView)g; // Copy context of the storage dataset to the wrapper dataset. dataset.getContext().putAll(gv.getDataset().getContext()); } return make(query, dataset); }
@Test public void graphDSG_basic_1() { Graph g = makeDefaultGraph(baseDSG) ; assertTrue(g instanceof GraphView) ; GraphView gv = (GraphView)g ; assertEquals(baseDSG, gv.getDataset()) ; assertEquals(null, gv.getGraphName()) ; }
@Test public void graphDSG_basic_2() { Node gn1 = SSE.parseNode("<g1>") ; Graph g = makeNamedGraph(baseDSG, gn1) ; assertTrue(g instanceof GraphView) ; GraphView gv = (GraphView)g ; assertEquals(baseDSG, gv.getDataset()) ; assertEquals(gn1, gv.getGraphName()) ; }