Search in sources :

Example 11 with RDFConnection

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

the class AbstractTestRDFConnection method named_graph_put_2_different.

@Test
public void named_graph_put_2_different() {
    try (RDFConnection conn = connection()) {
        conn.put(graphName, model1);
        conn.put(graphName2, model2);
        Model m1 = conn.fetch(graphName);
        Model m2 = conn.fetch(graphName2);
        assertTrue("Models not isomorphic", isomorphic(m1, model1));
        assertTrue("Models not isomorphic", isomorphic(m2, model2));
    }
}
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 12 with RDFConnection

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

the class AbstractTestRDFConnection method transaction_abort_read02.

// Not all RDFConnections support abort.
@Test
public void transaction_abort_read02() {
    Assume.assumeTrue(supportsAbort());
    String testDataFile = DIR + "data.trig";
    try (RDFConnection conn = connection()) {
        conn.begin(ReadWrite.WRITE);
        conn.loadDataset(testDataFile);
        conn.abort();
        conn.end();
        conn.begin(ReadWrite.READ);
        Model m = conn.fetch();
        assertTrue(m.isEmpty());
        conn.end();
    }
}
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 13 with RDFConnection

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

the class AbstractTestRDFConnection method connect_01.

// ---- Data
@Test
public void connect_01() {
    @SuppressWarnings("resource") RDFConnection conn = connection();
    assertFalse(conn.isClosed());
    conn.close();
    assertTrue(conn.isClosed());
    // Allow multiple close()
    conn.close();
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 14 with RDFConnection

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

the class AbstractTestRDFConnection method transaction_bad_01.

//@Test(expected=JenaTransactionException.class)
public void transaction_bad_01() {
    try (RDFConnection conn = connection()) {
        conn.begin(ReadWrite.WRITE);
        // Should have conn.commit();
        conn.end();
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection)

Example 15 with RDFConnection

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

the class RDFConnectionExample1 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();
    RDFConnection conn = RDFConnectionFactory.connect(dataset);
    Txn.executeWrite(conn, () -> {
        System.out.println("Load a file");
        conn.load("data.ttl");
        conn.load("http://example/g0", "data.ttl");
        System.out.println("In write transaction");
        conn.queryResultSet(query, ResultSetFormatter::out);
    });
    // And again - implicit READ transaction.
    System.out.println("After write transaction");
    conn.queryResultSet(query, ResultSetFormatter::out);
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection)

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