Java Code Examples for org.apache.jena.system.Txn#calculateRead()

The following examples show how to use org.apache.jena.system.Txn#calculateRead() . 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: AbstractTestDeltaConnection.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: AbstractTestDeltaClient.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: AbstractTestDeltaClient.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test
public void update_1() {
    // Create on the Delta link then setup DeltaClient
    DeltaLink dLink = getLink();
    String DS_NAME = "123";

    Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_1");
    DeltaClient dClient = createDeltaClient();
    dClient.register(dsRef, LocalStorageType.MEM, SyncPolicy.NONE);
    DeltaConnection dConn = dClient.get(DS_NAME);
    assertNotNull(dConn);
    assertEquals(Version.INIT, dConn.getLocalVersion());
    assertEquals(Version.INIT, dConn.getRemoteVersionLatest());

    Quad quad = SSE.parseQuad("(_ :s :p :o)");
    DatasetGraph dsg = dConn.getDatasetGraph();
    long x0 = Iter.count(dsg.find());
    assertEquals(0, x0);
    Txn.executeWrite(dsg, ()->dsg.add(quad));

    long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()));
    assertEquals(1, x1);

    DatasetGraph dsgx = dConn.getStorage();
    long x2 = Txn.calculateRead(dsgx, ()->Iter.count(dsgx.find()));
    assertEquals(1, x1);

}
 
Example 4
Source File: AbstractTestDeltaClient.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test
public void update_2() {
    // Create on the Delta link then setup DeltaClient
    DeltaLink dLink = getLink();
    String DS_NAME = "1234";

    Id dsRef = dLink.newDataSource(DS_NAME, "http://example/datasource_update_2");
    DeltaClient dClient = createDeltaClient();
    dClient.register(dsRef, LocalStorageType.MEM, SyncPolicy.NONE);
    DeltaConnection dConn = dClient.get(DS_NAME);
    assertNotNull(dConn);
    assertEquals(Version.INIT, dConn.getLocalVersion());
    assertEquals(Version.INIT, dConn.getRemoteVersionLatest());

    Quad quad = SSE.parseQuad("(_ :s :p :o)");
    DatasetGraph dsg = dConn.getDatasetGraph();

    long x0 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) );
    assertEquals(0, x0);

    Txn.executeWrite(dsg, ()->dsg.add(quad));
    long x1 = Txn.calculateRead(dsg, ()->Iter.count(dsg.find()) );
    assertEquals(1, x1);

    long x2 = Iter.count(dConn.getStorage().find());
    assertEquals(1, x1);
}