Search in sources :

Example 16 with RDFConnection

use of org.apache.jena.rdfconnection.RDFConnection in project jena by apache.

the class RDFConnectionExample2 method main.

public static void main(String... args) {
    Query query = QueryFactory.create("SELECT * { {?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }");
    Dataset dataset = DatasetFactory.createTxnMem();
    try (RDFConnection conn = RDFConnectionFactory.connect(dataset)) {
        System.out.println("** Load a file");
        // ---- Transaction 1: load data. 
        Txn.executeWrite(conn, () -> conn.load("data.ttl"));
        // ---- Transaction 2: explicit styles 
        conn.begin(ReadWrite.WRITE);
        conn.load("http://example/g0", "data.ttl");
        System.out.println("** Inside multistep transaction - query dataset");
        conn.queryResultSet(query, ResultSetFormatter::out);
        conn.abort();
        conn.end();
        System.out.println("** After abort 1");
        // ---- Transaction 3: explicit styles
        Txn.executeWrite(conn, () -> {
            conn.load("http://example/g0", "data.ttl");
            System.out.println("** Inside multistep transaction - fetch dataset");
            Dataset ds2 = conn.fetchDataset();
            RDFDataMgr.write(System.out, ds2, Lang.TRIG);
            conn.abort();
        });
        System.out.println("** After abort 2");
        // Only default graph showing.
        conn.queryResultSet(query, ResultSetFormatter::out);
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection)

Example 17 with RDFConnection

use of org.apache.jena.rdfconnection.RDFConnection in project jena by apache.

the class AbstractTestRDFConnection method query_ask_02.

@Test
public void query_ask_02() {
    try (RDFConnection conn = connection()) {
        boolean b = conn.queryAsk("ASK{}");
        assertTrue(b);
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 18 with RDFConnection

use of org.apache.jena.rdfconnection.RDFConnection in project jena by apache.

the class AbstractTestRDFConnection method named_graph_load_1.

// DELETE
// Named graphs
@Test
public void named_graph_load_1() {
    String testDataFile = DIR + "data.ttl";
    Model m0 = RDFDataMgr.loadModel(testDataFile);
    try (RDFConnection conn = connection()) {
        conn.load(graphName, testDataFile);
        Model m = conn.fetch(graphName);
        assertTrue("Models not isomorphic", isomorphic(m0, m));
        Model mDft = conn.fetch();
        assertTrue(mDft.isEmpty());
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 19 with RDFConnection

use of org.apache.jena.rdfconnection.RDFConnection in project jena by apache.

the class AbstractTestRDFConnection method dataset_put_1.

@Test
public void dataset_put_1() {
    try (RDFConnection conn = connection()) {
        conn.putDataset(dataset);
        Dataset ds1 = conn.fetchDataset();
        assertTrue("Datasets not isomorphic", isomorphic(dataset, ds1));
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Dataset(org.apache.jena.query.Dataset) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 20 with RDFConnection

use of org.apache.jena.rdfconnection.RDFConnection in project jena by apache.

the class AbstractTestRDFConnection method query_select_01.

@Test
public void query_select_01() {
    AtomicInteger counter = new AtomicInteger(0);
    try (RDFConnection conn = connection()) {
        Txn.executeWrite(conn, () -> conn.loadDataset(DIR + "data.trig"));
        Txn.executeRead(conn, () -> conn.querySelect("SELECT * { ?s ?p ?o }", (r) -> counter.incrementAndGet()));
        assertEquals(2, counter.get());
    }
}
Also used : IsoMatcher(org.apache.jena.sparql.util.IsoMatcher) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) StrUtils(org.apache.jena.atlas.lib.StrUtils) Model(org.apache.jena.rdf.model.Model) SSE(org.apache.jena.sparql.sse.SSE) BaseTest(org.apache.jena.atlas.junit.BaseTest) Txn(org.apache.jena.system.Txn) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasetFactory(org.apache.jena.query.DatasetFactory) RDFDataMgr(org.apache.jena.riot.RDFDataMgr) ReadWrite(org.apache.jena.query.ReadWrite) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Assume(org.junit.Assume) Iter(org.apache.jena.atlas.iterator.Iter) ModelFactory(org.apache.jena.rdf.model.ModelFactory) Dataset(org.apache.jena.query.Dataset) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

RDFConnection (org.apache.jena.rdfconnection.RDFConnection)29 BaseTest (org.apache.jena.atlas.junit.BaseTest)25 Test (org.junit.Test)25 Model (org.apache.jena.rdf.model.Model)16 Dataset (org.apache.jena.query.Dataset)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Iter (org.apache.jena.atlas.iterator.Iter)1 StrUtils (org.apache.jena.atlas.lib.StrUtils)1 DatasetFactory (org.apache.jena.query.DatasetFactory)1 Query (org.apache.jena.query.Query)1 ReadWrite (org.apache.jena.query.ReadWrite)1 ResultSetFormatter (org.apache.jena.query.ResultSetFormatter)1 ModelFactory (org.apache.jena.rdf.model.ModelFactory)1 RDFDataMgr (org.apache.jena.riot.RDFDataMgr)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 SSE (org.apache.jena.sparql.sse.SSE)1 IsoMatcher (org.apache.jena.sparql.util.IsoMatcher)1 Txn (org.apache.jena.system.Txn)1 Assume (org.junit.Assume)1