org.apache.jena.system.Txn Java Examples
The following examples show how to use
org.apache.jena.system.Txn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CypherLoaderIT.java From rdf2neo with GNU Lesser General Public License v3.0 | 6 votes |
@BeforeClass public static void initTDB () { try ( RdfDataManager rdfMgr = new RdfDataManager ( RdfDataManagerTest.TDB_PATH ); ) { Dataset ds = rdfMgr.getDataSet (); for ( String ttlPath: new String [] { "dbpedia_places.ttl", "dbpedia_people.ttl" } ) Txn.executeWrite ( ds, () -> ds.getDefaultModel ().read ( "file:target/test-classes/" + ttlPath, null, "TURTLE" )); } }
Example #2
Source File: DeltaEx01_DatasetWithPatchLog.java From rdf-delta with Apache License 2.0 | 6 votes |
public static void main(String ...args) { // -- Base dataset DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem(); // -- Destination for changes. // Text form of output. OutputStream out = System.out; // Create an RDFChanges that writes to "out". RDFChanges changeLog = RDFPatchOps.textWriter(out); // Combined datasetgraph and changes. DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog); // Wrap in the Dataset API Dataset ds = DatasetFactory.wrap(dsg); // -------- // Do something. Read in data.ttl inside a transaction. // (data.ttl is in src/main/resources/) Txn.executeWrite(ds, ()->RDFDataMgr.read(dsg, "data.ttl") ); }
Example #3
Source File: Rdf2NeoCliIT.java From rdf2neo with GNU Lesser General Public License v3.0 | 6 votes |
@BeforeClass public static void initTDB () { try ( RdfDataManager rdfMgr = new RdfDataManager ( TDB_PATH ); ) { Dataset ds = rdfMgr.getDataSet (); for ( String ttlPath: new String [] { "dbpedia_places.ttl", "dbpedia_people.ttl" } ) Txn.executeWrite ( ds, () -> ds.getDefaultModel ().read ( "file:target/examples/dbpedia/" + ttlPath, null, "TURTLE" )); } }
Example #4
Source File: AbstractTestDeltaConnection.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void change_1() { String NAME = "change_1s"; DeltaClient dClient = createRegister(NAME); try(DeltaConnection dConn = dClient.get(NAME)) { Version verLocal0 = dConn.getLocalVersion(); Version verRemotel0 = dConn.getRemoteVersionLatest(); DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->{ dsg.add(SSE.parseQuad("(:gx :sx :px :ox)")); }); Version verLocal1 = dConn.getLocalVersion(); Version verRemotel1 = dConn.getRemoteVersionLatest(); assertEquals(verLocal1, dConn.getLocalVersion()); assertEquals(verRemotel1, dConn.getRemoteVersionLatest()); assertFalse(dConn.getDatasetGraph().isEmpty()); if ( dConn.getStorage() != null ) assertFalse(dConn.getStorage().isEmpty()); } }
Example #5
Source File: AbstractTestDeltaConnection.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void change_2() { String NAME = "change_2"; DeltaClient dClient = createRegister(NAME); try(DeltaConnection dConn = dClient.get(NAME)) { Id dsRef = dConn.getDataSourceId(); Version version = dConn.getRemoteVersionLatest(); DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->{ Quad q = SSE.parseQuad("(_ :s1 :p1 :o1)"); dsg.add(q); }); // Rebuild directly. DatasetGraph dsg2 = DatasetGraphFactory.createTxnMem(); Version ver = dConn.getRemoteVersionLatest(); RDFPatch patch1 = dConn.getLink().fetch(dsRef, ver) ; RDFPatchOps.applyChange(dsg2, patch1); Set<Quad> set1 = Txn.calculateRead(dsg, ()->Iter.toSet(dsg.find())); Set<Quad> set2 = Txn.calculateRead(dsg2, ()->Iter.toSet(dsg2.find())); assertEquals(set1, set2); } }
Example #6
Source File: AbstractTestDeltaConnection.java From rdf-delta with Apache License 2.0 | 6 votes |
private void change_read_new(Runnable betweenSections) { Quad quad = DeltaTestLib.freshQuad(); String NAME = "DS-"+counter.incrementAndGet(); DeltaClient dClient = createRegister(NAME); Id dsRef; try(DeltaConnection dConn = dClient.get(NAME)) { dConn.getPatchLogInfo().getDataSourceId(); dsRef = dConn.getDataSourceId(); Version version = dConn.getRemoteVersionLatest(); DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->dsg.add(quad) ); } betweenSections.run(); // New client. // Rebuild. dClient = resetDeltaClient(NAME); try(DeltaConnection dConn = dClient.get(NAME)) { boolean b = dConn.getDatasetGraph().contains(quad); assertTrue(b); } }
Example #7
Source File: TestRDFChangesCancel.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void changeSuppressEmptyCommit_4() { Quad q = SSE.parseQuad("(_ :s :p 'object')"); Triple t = SSE.parseTriple("(:t :p 'object')"); Txn.executeRead(dsg, ()->{}); testCounters(counter.summary(), 0, 0); Txn.executeWrite(dsg, ()->{dsg.add(q);}); testCounters(counter.summary(), 1, 0); Txn.executeWrite(dsg, ()->{dsg.getDefaultGraph().add(t);}); testCounters(counter.summary(), 2, 0); Txn.executeWrite(dsg, ()->{dsg.getDefaultGraph().getPrefixMapping().setNsPrefix("", "http://example/");}); testCounters(counter.summary(), 2, 1); Txn.executeWrite(dsg, ()->{}); testCounters(counter.summary(), 2, 1); }
Example #8
Source File: AbstractTestDeltaClient.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void update_3() { // Create on the Delta link then setup DeltaClient DeltaLink dLink = getLink(); String DS_NAME = "12345"; Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_3"); DeltaClient dClient = createDeltaClient(); dClient.register(dsRef, LocalStorageType.MEM, SyncPolicy.NONE); DeltaConnection dConn = dClient.get(DS_NAME); Quad quad = SSE.parseQuad("(_ :s :p :o)"); DatasetGraph dsg = dConn.getDatasetGraph(); long x0 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) ); assertEquals(0, x0); dsg.begin(ReadWrite.WRITE); dsg.add(quad); dsg.abort(); long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) ); assertEquals(0, x1); }
Example #9
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_delete_2() { Txn.executeWrite(dsg, ()-> { dsg.add(quad1); dsg.delete(quad2); }); DatasetGraph dsg2 = replay(); check(dsg2, quad1); }
Example #10
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_add_1() { Txn.executeWrite(dsg, ()-> { dsg.add(quad1); dsg.add(quad2); }); DatasetGraph dsg2 = replay(); check(dsg2, quad1, quad2); }
Example #11
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_delete_3() { Txn.executeWrite(dsg, ()-> { dsg.delete(quad2); dsg.add(quad1); }); DatasetGraph dsg2 = replay(); check(dsg2, quad1); }
Example #12
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_delete_4() { Txn.executeWrite(dsg, ()-> { dsg.delete(quad1); dsg.add(quad1); }); DatasetGraph dsg2 = replay(); check(dsg2, quad1); }
Example #13
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_abort_1() { Txn.executeWrite(dsg, ()-> { dsg.delete(quad1); dsg.abort(); }); DatasetGraph dsg2 = replay(); check(dsg2); }
Example #14
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_graph_1() { Txn.executeWrite(dsg, ()-> { Graph g = dsg.getDefaultGraph(); g.add(triple1); }); DatasetGraph dsg2 = replay(); check(dsg2, Quad.create(Quad.defaultGraphIRI, triple1)); }
Example #15
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_graph_2() { Txn.executeWrite(dsg, ()-> { Graph g = dsg.getDefaultGraph(); g.add(triple1); g.delete(triple1); g.add(triple2); }); DatasetGraph dsg2 = replay(); check(dsg2, Quad.create(Quad.defaultGraphIRI, triple2)); }
Example #16
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_graph_3() { Txn.executeWrite(dsg, ()-> { Graph g = dsg.getDefaultGraph(); g.add(triple1); dsg.delete(Quad.create(Quad.defaultGraphIRI, triple1)); }); DatasetGraph dsg2 = replay(); check(dsg2); }
Example #17
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_remove_graph_1() { Txn.executeWrite(dsg, ()->dsg.add(quad1)); Node gn = quad1.getGraph(); Txn.executeWrite(dsg, ()-> { dsg.removeGraph(gn); }); DatasetGraph dsg2 = replay(); check(dsg2); }
Example #18
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_graph_1() { Txn.executeWrite(dsg, ()->dsg.add(quad1)); Graph data = GraphFactory.createDefaultGraph(); Node gn = quad1.getGraph(); data.add(triple1); Txn.executeWrite(dsg, ()-> { dsg.addGraph(gn, data); }); DatasetGraph dsg2 = replay(); check(dsg2, Quad.create(gn, triple1)); }
Example #19
Source File: TestAssemblerFileLog.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void assemData() { Dataset ds = (Dataset)AssemblerUtils.build(ADIR+"/assem-logged.ttl", VocabPatch.tLoggedDataset); Txn.executeWrite(ds, ()->RDFDataMgr.read(ds, ADIR+"/data.ttl")); String patchfile = "target/filelog/log.rdfp.0001"; assertTrue("Patch file does not exist: "+patchfile, FileOps.exists(patchfile)); RDFPatch patch = RDFPatchOps.read(patchfile); DatasetGraph dsg1 = DatasetGraphFactory.createTxnMem(); RDFPatchOps.applyChange(dsg1, patch); // Same term, no bnode isomorphism. boolean b = IsoMatcher.isomorphic(ds.asDatasetGraph(), dsg1); assertTrue(b); }
Example #20
Source File: TestDatasetGraphWithAbort.java From rdf-delta with Apache License 2.0 | 5 votes |
public void abort_data_1() { DatasetGraph dsg = create().asDatasetGraph() ; Txn.executeWrite(dsg, ()->dsg.add(q1)) ; Assert.assertTrue(dsg.contains(q1)) ; Assert.assertFalse(dsg.contains(q2)) ; dsg.begin(ReadWrite.WRITE); dsg.add(q2) ; dsg.abort(); dsg.end(); Assert.assertTrue(dsg.contains(q1)) ; Assert.assertFalse(dsg.contains(q2)) ; }
Example #21
Source File: DeltaEx02_DatasetCollectPatch.java From rdf-delta with Apache License 2.0 | 5 votes |
public static void main(String ...args) { // -- Base dataset DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem(); // -- Destination for changes. // Text form of output. OutputStream out = System.out; // Create an RDFChanges that writes to "out". RDFChanges changeLog = RDFPatchOps.textWriter(out); // ---- Collect up changes. //RDFPatchOps.collect(); RDFChangesCollector rcc = new RDFChangesCollector(); DatasetGraph dsg = RDFPatchOps.changes(dsgBase, rcc); Dataset ds = DatasetFactory.wrap(dsg); Txn.executeWrite(ds, ()->RDFDataMgr.read(dsg, "data.ttl") ); // Again - different bnodes. // Note all changes are recorded - even if they have no effect // (e.g the prefix, the triple "ex:s ex:p ex:o"). Txn.executeWrite(ds, ()->RDFDataMgr.read(dsg, "data.ttl") ); // Collected (in-memory) patch. RDFPatch patch = rcc.getRDFPatch(); // Write it. patch.apply(changeLog); }
Example #22
Source File: DeltaEx09_CreateDataSourceHTTP.java From rdf-delta with Apache License 2.0 | 5 votes |
public static void main2(String... args) { // The local state of the server. Location loc = Location.create("DeltaServer"); LocalServer localServer = LocalServers.createFile(loc.getDirectoryPath()); DeltaLink serverState = DeltaLinkLocal.connect(localServer); DeltaServer server = DeltaServer.create(1066, serverState); // -------- // Connect to a server DeltaLink dLink = DeltaLinkHTTP.connect("http://localhost:1066/"); // One one zone supported currently. Zone zone = Zone.connect("Zone"); Id clientId = Id.create(); // Create a new patch log. dLink.newDataSource("TEST", "http://example/test"); // Put it under client management. DeltaClient dClient = DeltaClient.create(zone, dLink); Id dsRef = dClient.register("TEST", LocalStorageType.MEM, SyncPolicy.TXN_RW); // and now connect to it try ( DeltaConnection dConn = dClient.get(dsRef) ) { Version version1 = dConn.getRemoteVersionLatest(); System.out.println("Version = "+version1); // Change the dataset DatasetGraph dsg = dConn.getDatasetGraph(); Txn.executeWrite(dsg, ()->{ dsg.add(quad); }); Version version2 = dConn.getRemoteVersionLatest(); System.out.println("Version = "+version2); } System.out.println("DONE"); }
Example #23
Source File: DeltaEx06_LocalDatasetToFuseki.java From rdf-delta with Apache License 2.0 | 5 votes |
public static void main2(String ...args) { // ---- Fuseki server with patch operation. int PORT = 2020 ; // In-memory dataset DatasetGraph dsgFuseki = DatasetGraphFactory.createTxnMem(); String serviceName = "patch"; FusekiServer server = fusekiServerWithPatch("/ds", PORT, dsgFuseki, serviceName); server.start(); // ---- Destination for changes is the Fuseki patch opration. String url = "http://localhost:"+PORT+"/ds/"+serviceName; RDFChanges changeSender = DeltaClientLib.destination(url); // In the case of http/https URLs, this is done with // RDFChanges changeSender = new RDFChangesHTTP(url); // ---- Local dataset. DatasetGraph dsgLocal = DatasetGraphFactory.createTxnMem(); // Combined datasetgraph and changes. // Changes will be POSTed to the URL. DatasetGraph dsg = RDFPatchOps.changes(dsgLocal, changeSender); // ---- Do something. Read in data.ttl inside a transaction. // (data.ttl is in src/main/resources/) Txn.executeWrite(dsg, ()->RDFDataMgr.read(dsg, "data.ttl") ); // ---- Query Fuseki RDFConnection conn = RDFConnectionFactory.connect("http://localhost:"+PORT+"/ds"); try( QueryExecution qExec = conn.query("PREFIX ex: <http://example.org/> SELECT * { ?s ?p ?o }") ) { ResultSet rs = qExec.execSelect(); ResultSetFormatter.out(rs, qExec.getQuery()); } }
Example #24
Source File: RdfDocumentGraphConsumer.java From baleen with Apache License 2.0 | 5 votes |
@Override protected void outputModel(String documentSourceName, OntModel model) throws AnalysisEngineProcessException { try (RDFConnection connect = createConnection()) { Txn.executeWrite(connect, () -> connect.load(model)); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
Example #25
Source File: RdfEntityGraphConsumer.java From baleen with Apache License 2.0 | 5 votes |
@Override protected void outputModel(String documentSourceName, OntModel model) throws AnalysisEngineProcessException { try (RDFConnection connect = createConnection()) { Txn.executeWrite(connect, () -> connect.load(model)); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
Example #26
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_add_2() { Txn.executeWrite(dsg, ()-> { dsg.add(quad1); dsg.add(quad1); }); DatasetGraph dsg2 = replay(); check(dsg2, quad1); }
Example #27
Source File: TestRDFChangesDataset.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void record_add_delete_1() { Txn.executeWrite(dsg, ()-> { dsg.add(quad1); dsg.delete(quad1); }); DatasetGraph dsg2 = replay(); check(dsg2); }
Example #28
Source File: TestRDFChangesCancel.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void changeSuppressEmptyCommit_3() { Txn.executeWrite(dsg, ()->dsg.add(quad1)); PatchSummary s1 = counter.summary(); assertEquals(1, s1.getCountTxnBegin()); assertEquals(1, s1.getCountTxnCommit()); assertEquals(0, s1.getCountTxnAbort()); }
Example #29
Source File: TestRDFChangesCancel.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void changeSuppressEmptyCommit_2() { Txn.executeWrite(dsg, ()->{}); PatchSummary s1 = counter.summary(); assertEquals(1, s1.getCountTxnBegin()); assertEquals(0, s1.getCountTxnCommit()); assertEquals(1, s1.getCountTxnAbort()); }
Example #30
Source File: TestRDFChangesCancel.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void changeSuppressEmptyCommit_1() { Txn.executeRead(dsg, ()->{}); PatchSummary s1 = counter.summary(); assertEquals(0, s1.getCountTxnBegin()); assertEquals(0, s1.getCountTxnCommit()); assertEquals(0, s1.getCountTxnAbort()); }