Java Code Examples for org.apache.jena.rdfconnection.RDFConnection#update()

The following examples show how to use org.apache.jena.rdfconnection.RDFConnection#update() . 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: DeltaEx03_FusekiLogChanges.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
public static void main2(String ...args) {
        int PORT = 2020;
        DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();
        RDFChanges changeLog = RDFPatchOps.textWriter(System.out);
        DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);

        // Create a server with the changes-enables dataset.
        // Plain server. No other registration necessary.
        FusekiServer server =
            FusekiServer.create()
                .port(PORT)
                .add("/ds", dsg)
                .build();
        server.start();

        RDFConnection conn = RDFConnectionFactory.connect("http://localhost:"+PORT+"/ds");
        UpdateRequest update = UpdateFactory.create("PREFIX : <http://example/> INSERT DATA { :s :p 123 }");
        // Note - no prefix in changes. The SPARQL Update prefix is not a chnage to the dataset prefixes.
        conn.update(update);

        server.stop();
//        // Server in the background so explicitly exit.
//        System.exit(0);
    }
 
Example 2
Source File: TestDeltaZkFuseki.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test
public void t1_fusekiOne() {
    DeltaLink dLink1 = DeltaLinkHTTP.connect(deltaServerURL1);
    DeltaLink dLink2 = DeltaLinkHTTP.connect(deltaServerURL2);
    dLink1.ping();
    dLink2.ping();

    assertFalse(dLink1.existsByName("ABC"));
    Id logABC = dLink1.newDataSource("ABC", "http://example/abc");
    Lib.sleep(500);
    assertTrue(dLink1.existsByName("ABC"));
    assertTrue(dLink2.existsByName("ABC"));

    int fusekiPort = Matrix.choosePort();
    DeltaLinkSwitchable dLinkFuseki = (DeltaLinkSwitchable)Matrix.setupFuseki("ABC", "target/Zone", fusekiPort, deltaServerURL1, deltaServerURL2);
    String fusekiURL = "http://localhost:"+fusekiPort+"/ABC";
    RDFConnection conn = RDFConnectionFactory.connect(fusekiURL);

    conn.update("PREFIX : <http://delta/> INSERT DATA { :s :p :o }");
    assertCount("Count, before failover", conn, 1);

    if ( true )
        Matrix.deltaServer1.stop();
    else
        dLinkFuseki.switchover();

    assertCount("Count, after failover", conn, 1);
    conn.update("PREFIX : <http://delta/> INSERT DATA { :s :p :o2 }");
    assertCount(conn, 2);
}
 
Example 3
Source File: TestDeltaZkFuseki.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
@Test
    public void t2_fuseki2() {
        DeltaLink dLink1 = DeltaLinkHTTP.connect(deltaServerURL1);
        DeltaLink dLink2 = DeltaLinkHTTP.connect(deltaServerURL2);
        dLink1.ping();
        dLink2.ping();
        
        if ( dLink1.existsByName("ABC") ) {
            System.err.println("Exists");
        }
        
        Id log2 = dLink2.newDataSource("ABC", "http://example/abc");
        // Updaing the system is asynchronous
        await().atMost(5, SECONDS).until(()->dLink1.exists(log2));
        
        int fusekiPort1 = Matrix.choosePort();
        int fusekiPort2 = Matrix.choosePort();

        
        // Set primary delta server.
        // Retry needed?
        Matrix.setupFuseki("ABC", "target/Zone1", fusekiPort1, deltaServerURL1, deltaServerURL2);
        Matrix.setupFuseki("ABC", "target/Zone2", fusekiPort2, deltaServerURL2, deltaServerURL1);
        
        String fusekiURL1 = "http://localhost:"+fusekiPort1+"/ABC";
        String fusekiURL2 = "http://localhost:"+fusekiPort1+"/ABC";
        
//        System.err.printf("Fuseki servers %s , %s\n", fusekiURL1, fusekiURL2);
//        System.err.printf("Delta servers %s , %s\n", deltaServerURL1, deltaServerURL2);
        
        RDFConnection conn1 = RDFConnectionFactory.connect(fusekiURL1);
        RDFConnection conn2 = RDFConnectionFactory.connect(fusekiURL2);
        
        //boolean b = conn1.queryAsk("ASK{}");
        
        conn1.update("PREFIX : <http://delta/> INSERT DATA { :s :p :o }");
        assertCount(conn1, 1);
        assertCount(conn2, 1);
        
        Matrix.deltaServer1.stop();
        
        conn2.update("PREFIX : <http://delta/> INSERT DATA { :s :p :o2 }");

        assertCount(conn1, 2);
        assertCount(conn2, 2);

    }
 
Example 4
Source File: DeltaEx_FusekiHighAvailability.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
public static void main2(String ...args) {
    setup();
    // Patch Log Server
    FileOps.exists(PLOG_DIR);
    FileOps.clearAll(PLOG_DIR);

    DeltaServer patchLogServer = DeltaServer.server(PLOG_PORT, PLOG_DIR);
    try { patchLogServer.start(); }
    catch (BindException ex) {
        System.err.println("Can't start the patch log server: "+ex.getMessage());
        System.exit(1);
    }

    // For high availability, need a load balancer that switches between the two Fuskei servers.

    // Fuseki server 1
    FusekiServer fuseki1 = fuseki1();
    RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+"/ds1") ;

    // Fuseki server 2
    FusekiServer fuseki2 = fuseki2();
    RDFConnection conn2 = RDFConnectionFactory.connect("http://localhost:"+F2_PORT+"/ds2") ;

    // Some data (data.ttl is in src/main/resources).
    Model model = RDFDataMgr.loadModel("data.ttl");
    conn1.put(model);

    // Kill fuseki1.
    fuseki1.stop();

    // And fetch data.
    Model model2 = conn2.fetch();
    System.out.println();
    RDFDataMgr.write(System.out, model2, Lang.NT);
    System.out.println();

    // Remove a triple via conn2.
    conn2.update("PREFIX ex: <http://example.org/> DELETE DATA { ex:s ex:p ex:o }");

    // Restart Fuseki1.
    fuseki1 = fuseki1();
    // Not necesary.
    // conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+"/ds1") ;
    Model model1 = conn1.fetch();
    System.out.println();
    // Data in Fuseki1. One less triple.
    RDFDataMgr.write(System.out, model1, Lang.NT);
    System.out.println();
}