org.apache.jena.rdfconnection.RDFConnection Java Examples

The following examples show how to use org.apache.jena.rdfconnection.RDFConnection. 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: TestDeltaFusekiBad.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
@Test
public void fuseki_stop_start() {
    DeltaServer deltaServer = deltaServer();
    FusekiServer server1 = fuseki1();
    try {
        server1.stop();

        RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ;
        QueryExecution qExec = conn1.query("ASK{}");
        try { qExec.execAsk(); fail(); } catch(QueryExceptionHTTP ex) {}
        // Restart, same port.
        server1 = fuseki1(Start.RESTART);
        QueryExecution qExec1 = conn1.query("ASK{}");
        qExec1.execAsk();
    } finally {
        server1.stop();
        deltaServer.stop();
    }
}
 
Example #2
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a Triplestore-based Resource.
 * @param rdfConnection the triplestore connector
 * @param identifier the identifier
 * @param extensions a map of extensions
 * @param includeLdpType whether to include the LDP interaction model in the response
 */
public TriplestoreResource(final RDFConnection rdfConnection, final IRI identifier,
        final Map<String, IRI> extensions, final boolean includeLdpType) {
    this.identifier = identifier;
    this.rdfConnection = rdfConnection;
    this.includeLdpType = includeLdpType;
    graphMapper.put(Trellis.PreferUserManaged, this::fetchUserQuads);
    graphMapper.put(Trellis.PreferServerManaged, this::fetchServerQuads);
    graphMapper.put(Trellis.PreferAudit, this::fetchAuditQuads);
    graphMapper.put(Trellis.PreferAccessControl, this::fetchAclQuads);
    graphMapper.put(LDP.PreferContainment, this::fetchContainmentQuads);
    graphMapper.put(LDP.PreferMembership, this::fetchMembershipQuads);

    extensions.forEach((k, v) -> {
        if (!graphMapper.containsKey(v)) {
            this.extensions.put(v, k);
        }
    });
}
 
Example #3
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 #4
Source File: TriplestoreResourceService.java    From trellis with Apache License 2.0 6 votes vote down vote up
/**
 * Build an RDF connection from a location value.
 *
 * @implNote A null value will create an in-memory RDF store, a file path will create
 *           a TDB2 RDF store, and a URL will use a remote triplestore.
 * @param location the location of the RDF
 * @return a connection to the RDF store
 */
public static RDFConnection buildRDFConnection(final String location) {
    if (location != null) {
        if (location.startsWith("http://") || location.startsWith("https://")) {
            // Remote
            LOGGER.info("Using remote Triplestore for persistence at {}", location);
            return connect(location);
        }
        // TDB2
        LOGGER.info("Using local TDB2 database at {}", location);
        return connect(wrap(connectDatasetGraph(location)));
    }
    // in-memory
    LOGGER.info("Using an in-memory dataset for resources");
    return connect(createTxnMem());
}
 
Example #5
Source File: TriplestoreResourceServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testInitializeRoot2() {
    final Instant early = now();
    final Dataset dataset = rdf.createDataset();
    dataset.add(Trellis.PreferServerManaged, root, type, LDP.BasicContainer);
    dataset.add(Trellis.PreferServerManaged, root, DC.modified, rdf.createLiteral(early.toString(), XSD.dateTime));

    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    final TriplestoreResourceService svc = new TriplestoreResourceService(rdfConnection);
    svc.initialize();

    final Resource res = svc.get(root).toCompletableFuture().join();
    assertAll("Check resource", checkResource(res, root, LDP.BasicContainer, early));
    assertAll("Check resource stream", checkResourceStream(res, 0L, 0L, 0L, 0L, 0L));
}
 
Example #6
Source File: TestDeltaFusekiBad.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test(expected=QueryExceptionHTTP.class)
public void fuseki_stop() {
    DeltaServer deltaServer = deltaServer(CLEAN);
    FusekiServer server1 = fuseki1(CLEAN);
    try {
        server1.stop();
        RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ;
        QueryExecution qExec = conn1.query("ASK{}");
        qExec.execAsk();
    } finally {
        deltaServer.stop();
    }
}
 
Example #7
Source File: TestDeltaFusekiBad.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test
public void patchserver_stop_start() {
    DeltaServer deltaServer = deltaServer();
    FusekiServer server1 = fuseki1();
    try {
        deltaServer.stop();
        deltaServer = null;

        // Should fail
        try (RDFConnection conn0 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ) {
            conn0.update(PREFIX+"INSERT DATA { :s :p 'update_patchserver_stop_start' }");
            Assert.fail("Should not be able to update at the moment");
        } catch (HttpException ex) {
            assertEquals(503, ex.getStatusCode());
            // Expected - ignore.
            //assertTrue(ex.getResponseCode()>= 500);
        }

        deltaServer = deltaServer(Start.RESTART);

        try (RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1)) {
            conn1.query("ASK{}").execAsk();
        }

        // Should be able to update.
        try (RDFConnection conn0 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ) {
            conn0.update(PREFIX+"INSERT DATA { :s :p 'update_patchserver_stop_start' }");
        }
    } finally {
        server1.stop();
        if ( deltaServer != null )
            deltaServer.stop();
    }
}
 
Example #8
Source File: DeltaEx06_LocalDatasetToFuseki.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
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 #9
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 #10
Source File: Driver.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
static void client(int loops, CountDownLatch cdlStart, CountDownLatch cdlFinish) {
    //conn2 = RDFConnectionFactory.connect("http://localhost:"+F2_PORT+DS_NAME) ;

    Runnable r = ()->{
        RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+DS_NAME) ;
        try {
            cdlStart.countDown();
            cdlStart.await();
        }
        catch (InterruptedException e) {
            e.printStackTrace(System.err);
            return ;
        }

        try (RDFConnection conn = conn1) {
            for ( int i = 0 ; i < loops ; i++ ) {
                String now = DateTimeUtils.nowAsXSDDateTimeString()+"-"+i;
                try {
                    // This can abort and the update is then lost
                    conn.update("INSERT DATA { <x:s> <x:p> '"+now+"' }");

                } catch (DeltaException ex) {
                    System.out.flush();
                    System.err.println("\nSystem abort\n");
                }
                try ( QueryExecution qExec = conn.query("SELECT * { ?s ?p ?o}") ) {
                    ResultSetFormatter.consume(qExec.execSelect());
                    // QueryExecUtils.executeQuery(qExec);
                }

            }
        }
        cdlFinish.countDown();
    };

    new Thread(r).start();
}
 
Example #11
Source File: TriplestoreResourceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testIndirectContainer() {
    final Dataset dataset = buildLdpDataset(LDP.IndirectContainer);
    dataset.add(Trellis.PreferServerManaged, identifier, DC.isPartOf, root);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.member, member);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.membershipResource, member);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.hasMemberRelation, DC.relation);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.insertedContentRelation, DC.subject);
    dataset.add(Trellis.PreferServerManaged, member, DC.isPartOf, root);
    dataset.add(identifier, identifier, DC.alternative, rdf.createLiteral("An LDP-IC resource"));
    dataset.add(member, member, DC.alternative, rdf.createLiteral("A membership resource"));
    getChildIRIs().forEach(c -> {
        dataset.add(Trellis.PreferServerManaged, c, DC.isPartOf, identifier);
        dataset.add(Trellis.PreferServerManaged, c, type, LDP.RDFSource);
        dataset.add(c, c, DC.subject, rdf.createIRI("http://example.org/" + randomUUID()));
    });

    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    final TriplestoreResource res = new TriplestoreResource(rdfConnection, identifier, extensions, false);
    res.fetchData();
    assertTrue(res.exists(), "Missing resource!");
    assertAll("Check resource", checkResource(res, identifier, LDP.IndirectContainer, false, false, true));
    assertAll("Check LDP properties", checkLdpProperties(res, member, DC.relation, null, DC.subject));
    assertAll("Check RDF stream", checkRdfStream(res, 3L, 0L, 0L, 0L, 0L, 4L));

    final TriplestoreResource res2 = new TriplestoreResource(rdfConnection, member, extensions, false);
    res2.fetchData();
    assertTrue(res2.exists(), "Missing resource (2)!");
    assertAll("Check resource", checkResource(res2, member, LDP.RDFSource, false, false, true));
    assertAll("Check LDP properties", checkLdpProperties(res2, null, null, null, null));
    assertAll("Check RDF stream", checkRdfStream(res2, 2L, 0L, 0L, 0L, 4L, 0L));
    assertEquals(4L, res2.stream(singleton(LDP.PreferMembership)).map(Quad::getPredicate)
            .filter(isEqual(DC.relation)).count(), "Incorrect triple count!");

    assertNotEquals(res.getRevision(), res2.getRevision(), "Revisions not unequal");
}
 
Example #12
Source File: TriplestoreResourceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testDirectContainer() {
    final Dataset dataset = buildLdpDataset(LDP.DirectContainer);
    dataset.add(Trellis.PreferServerManaged, identifier, DC.isPartOf, root);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.member, member);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.membershipResource, member);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.hasMemberRelation, DC.subject);
    dataset.add(Trellis.PreferServerManaged, identifier, LDP.insertedContentRelation, LDP.MemberSubject);
    dataset.add(Trellis.PreferServerManaged, identifier, DC.modified, rdf.createLiteral(time, XSD.dateTime));
    dataset.add(Trellis.PreferServerManaged, member, DC.isPartOf, root);
    getChildIRIs().forEach(c -> {
        dataset.add(Trellis.PreferServerManaged, c, DC.isPartOf, identifier);
        dataset.add(Trellis.PreferServerManaged, c, type, LDP.RDFSource);
    });

    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    final TriplestoreResource res = new TriplestoreResource(rdfConnection, identifier, extensions, true);
    res.fetchData();
    assertTrue(res.exists(), "Missing resource!");
    assertAll("Check resource", checkResource(res, identifier, LDP.DirectContainer, false, false, true));
    assertAll("Check LDP properties", checkLdpProperties(res, member, DC.subject, null, LDP.MemberSubject));
    assertAll("Check RDF stream", checkRdfStream(res, 2L, 1L, 0L, 0L, 0L, 4L));

    final TriplestoreResource memberRes = new TriplestoreResource(rdfConnection, member, extensions, false);
    memberRes.fetchData();
    assertTrue(memberRes.exists(), "Missing resource!");
    assertAll("Check resource", checkResource(memberRes, member, LDP.RDFSource, false, false, true));
    assertAll("Check LDP properties", checkLdpProperties(memberRes, null, null, null, null));
    assertAll("Check RDF stream", checkRdfStream(memberRes, 1L, 0L, 0L, 0L, 4L, 0L));
    assertEquals(4L, memberRes.stream(singleton(LDP.PreferMembership)).map(Quad::getPredicate)
            .filter(isEqual(DC.subject)).count(), "Incorrect triple count!");

    assertNotEquals(res.getRevision(), memberRes.getRevision(), "Revisions not unequal");
}
 
Example #13
Source File: TriplestoreResourceServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testBuildRDFConnectionRemoteHTTPS() {
    final RDFConnection rdfConnection = TriplestoreResourceService.buildRDFConnection("https://localhost/sparql");
    assertNotNull(rdfConnection, "Missing RDFConnection, using local HTTP!");
    assertFalse(rdfConnection.isClosed(), "RDFConnection has been closed!");
    assertTrue(rdfConnection instanceof RDFConnectionRemote, "Incorrect type");
}
 
Example #14
Source File: TriplestoreResourceServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testBuildRDFConnectionRemote() {
    final RDFConnection rdfConnection = TriplestoreResourceService.buildRDFConnection("http://localhost/sparql");
    assertNotNull(rdfConnection, "Missing RDFConnection, using local HTTP!");
    assertFalse(rdfConnection.isClosed(), "RDFConnection has been closed!");
    assertTrue(rdfConnection instanceof RDFConnectionRemote, "Incorrect type");
}
 
Example #15
Source File: TriplestoreResourceServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testBuildRDFConnectionTDB() throws Exception {
    final File dir = new File(new File(getClass().getResource("/logback-test.xml").toURI()).getParent(), "data");
    final RDFConnection rdfConnection = TriplestoreResourceService.buildRDFConnection(dir.getAbsolutePath());
    assertNotNull(rdfConnection, "Missing RDFConnection, using local file!");
    assertFalse(rdfConnection.isClosed(), "RDFConnection has been closed!");
    assertTrue(rdfConnection instanceof RDFConnectionLocal, "Incorrect type");
}
 
Example #16
Source File: TriplestoreResourceServiceTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testBuildRDFConnectionMemory() {

    final RDFConnection rdfConnection = TriplestoreResourceService.buildRDFConnection(null);
    assertNotNull(rdfConnection, "Missing RDFConnection, using in-memory dataset!");
    assertFalse(rdfConnection.isClosed(), "RDFConnection has been closed!");
    assertTrue(rdfConnection instanceof RDFConnectionLocal, "Incorrect type");
}
 
Example #17
Source File: TriplestoreHealthCheckTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testUnhealthy() {
    final Dataset dataset = rdf.createDataset();
    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    rdfConnection.close();
    final HealthCheck check = new TriplestoreHealthCheck(rdfConnection);
    assertEquals(HealthCheckResponse.State.DOWN, check.call().getState(),
            "Closed RDFConnection doesn't report as unhealthy!");
}
 
Example #18
Source File: TriplestoreHealthCheckTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testHealthy() {
    final Dataset dataset = rdf.createDataset();
    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    final HealthCheck check = new TriplestoreHealthCheck(rdfConnection);
    assertEquals(HealthCheckResponse.State.UP, check.call().getState(), "RDFConnection isn't healthy!");
}
 
Example #19
Source File: RdfDocumentGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: TriplestoreResourceService.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * Create a triplestore-backed resource service.
 * @param rdfConnection the connection to an RDF datastore
 * @param identifierService an ID supplier service
 */
@Inject
public TriplestoreResourceService(final RDFConnection rdfConnection, final IdentifierService identifierService) {
    this.includeLdpType = getConfig().getOptionalValue(CONFIG_TRIPLESTORE_LDP_TYPE, Boolean.class)
        .orElse(Boolean.TRUE);
    this.rdfConnection = requireNonNull(rdfConnection, "RDFConnection may not be null!");
    this.supplier = requireNonNull(identifierService, "IdentifierService may not be null!").getSupplier();
    this.supportedIxnModels = unmodifiableSet(new HashSet<>(asList(LDP.Resource, LDP.RDFSource, LDP.NonRDFSource,
            LDP.Container, LDP.BasicContainer, LDP.DirectContainer, LDP.IndirectContainer)));
    this.extensions = buildExtensionMap();
}
 
Example #21
Source File: RdfEntityGraphConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * Try to load a Trellis resource.
 *
 * @implSpec This method will load a {@link Resource}, initializing the object with all resource metadata
 *           used with {@link #getModified}, {@link #getInteractionModel} and other data fetched by the accessors.
 *           The resource content is fetched on demand via the {@link #stream} method.
 * @param rdfConnection the triplestore connector
 * @param identifier the identifier
 * @param extensions a map of extensions
 * @param includeLdpType whether to include the LDP type in the body of the RDF
 * @return a new completion stage with a {@link Resource}, if one exists
 */
public static CompletableFuture<Resource> findResource(final RDFConnection rdfConnection, final IRI identifier,
        final Map<String, IRI> extensions, final boolean includeLdpType) {
    return supplyAsync(() -> {
        final TriplestoreResource res = new TriplestoreResource(rdfConnection, normalizeIdentifier(identifier),
                extensions, includeLdpType);
        res.fetchData();
        if (!res.exists()) {
            return MISSING_RESOURCE;
        } else if (res.isDeleted()) {
            return DELETED_RESOURCE;
        }
        return res;
    });
}
 
Example #23
Source File: RDFConnectionHealthCheckTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testNonConnected() {
    final Dataset dataset = rdf.createDataset();
    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    rdfConnection.close();
    final HealthCheck check = new RDFConnectionHealthCheck(rdfConnection);
    assertFalse(check.execute().isHealthy(), "Closed RDFConnection doesn't report as unhealthy!");
}
 
Example #24
Source File: RDFConnectionHealthCheckTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testIsConnected() {
    final Dataset dataset = rdf.createDataset();
    final RDFConnection rdfConnection = connect(wrap(toJena(dataset)));
    final HealthCheck check = new RDFConnectionHealthCheck(rdfConnection);
    assertTrue(check.execute().isHealthy(), "RDFConnection isn't healthy!");
}
 
Example #25
Source File: TrellisServiceBundler.java    From trellis with Apache License 2.0 5 votes vote down vote up
static ResourceService buildResourceService(final AppConfiguration config,
        final Environment environment, final Jdbi jdbi) {
    if (useTriplestore(config)) {
        // Use a triplestore
        final RDFConnection rdfConnection = TriplestoreResourceService.buildRDFConnection(config.getResources());

        // Health checks
        environment.healthChecks().register("rdfconnection", new RDFConnectionHealthCheck(rdfConnection));
        return new TriplestoreResourceService(rdfConnection);
    }
    return new DBResourceService(jdbi);
}
 
Example #26
Source File: RdfEntityGraphConsumer.java    From baleen with Apache License 2.0 4 votes vote down vote up
private RDFConnection createConnection() {
  return RDFConnectionFactory.connect(
      queryServiceEndpoint, updateServiceEndpoint, graphStoreProtocolEndpoint);
}
 
Example #27
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();
}
 
Example #28
Source File: RdfDocumentGraphConsumer.java    From baleen with Apache License 2.0 4 votes vote down vote up
private RDFConnection createConnection() {
  return RDFConnectionFactory.connect(
      queryServiceEndpoint, updateServiceEndpoint, graphStoreProtocolEndpoint);
}
 
Example #29
Source File: TestDeltaZkFuseki.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
private static long count(RDFConnection conn) {
    try ( QueryExecution qExec = conn.query("SELECT (count(*) AS ?count) { ?s ?p ?o }") ) {
        return qExec.execSelect().next().getLiteral("count").getLong();
    }
}
 
Example #30
Source File: TestDeltaZkFuseki.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
private static void assertCount(RDFConnection conn, long expected) {
    long x = count(conn);
    assertEquals(expected, x);
}