Search in sources :

Example 6 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestUpdateOperations method load1.

@Test
public void load1() {
    DatasetGraph gs = graphStore();
    UpdateRequest req = UpdateFactory.create("LOAD <" + DIR + "/D.nt>");
    UpdateAction.execute(req, gs);
    assertEquals(1, gs.getDefaultGraph().size());
    assertFalse(gs.listGraphNodes().hasNext());
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 7 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestUpdateOperations method delete_insert_where_01.

// Check constant and template quads 
@Test
public void delete_insert_where_01() {
    DatasetGraph dsg0 = DatasetGraphFactory.create();
    UpdateRequest req = UpdateFactory.create("INSERT DATA { <x> <p> 2 . <z> <q> 2 . <z> <q> 3 . }");
    UpdateAction.execute(req, dsg0);
    assertEquals(3, dsg0.getDefaultGraph().size());
    AtomicLong counterIns = new AtomicLong(0);
    AtomicLong counterDel = new AtomicLong(0);
    DatasetGraph dsg = new DatasetGraphWrapper(dsg0) {

        @Override
        public void add(Quad quad) {
            counterIns.incrementAndGet();
            super.add(quad);
        }

        @Override
        public void delete(Quad quad) {
            counterDel.incrementAndGet();
            super.delete(quad);
        }
    };
    // WHERE clause doubles the effect.
    String s = "DELETE { ?x <p> 2 . <z> <q> 2 } INSERT { ?x <p> 1 . <x> <q> 1  } WHERE { ?x <p> ?o {} UNION {} }";
    req = UpdateFactory.create(s);
    UpdateAction.execute(req, dsg);
    // 3 : 1 constant, 2 from template.
    assertEquals(3, counterIns.get());
    assertEquals(3, counterIns.get());
    assertEquals(3, dsg.getDefaultGraph().size());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) AtomicLong(java.util.concurrent.atomic.AtomicLong) DatasetGraphWrapper(org.apache.jena.sparql.core.DatasetGraphWrapper) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 8 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestUpdateOperations method load4.

// Bad: loading quads into a named graph
@Test(expected = UpdateException.class)
public void load4() {
    DatasetGraph gs = graphStore();
    UpdateRequest req = UpdateFactory.create("LOAD <" + DIR + "/D.nq> INTO GRAPH <" + gName.getURI() + ">");
    UpdateAction.execute(req, gs);
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 9 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestUpdateOperations method load3.

// Quad loading
@Test
public void load3() {
    DatasetGraph gs = graphStore();
    UpdateRequest req = UpdateFactory.create("LOAD <" + DIR + "/D.nq>");
    UpdateAction.execute(req, gs);
    assertEquals(0, gs.getDefaultGraph().size());
    gs.containsGraph(NodeFactory.createURI("http://example/"));
    assertEquals(1, gs.getGraph(gName).size());
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 10 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class AbstractTestUpdateGraph method testUpdateScript4.

@Test
public void testUpdateScript4() {
    DatasetGraph gStore = getEmptyDatasetGraph();
    script(gStore, "data-1.ru");
    assertTrue(graphContains(gStore.getDefaultGraph(), new Triple(s, p, NodeFactoryExtra.parseNode("123"))));
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Aggregations

DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)222 Test (org.junit.Test)132 BaseTest (org.apache.jena.atlas.junit.BaseTest)59 Quad (org.apache.jena.sparql.core.Quad)47 Node (org.apache.jena.graph.Node)29 Graph (org.apache.jena.graph.Graph)18 StoreConnection (org.apache.jena.tdb.StoreConnection)17 DatasetGraphTxn (org.apache.jena.tdb.transaction.DatasetGraphTxn)15 Model (org.apache.jena.rdf.model.Model)10 IOException (java.io.IOException)7 Triple (org.apache.jena.graph.Triple)7 Dataset (org.apache.jena.query.Dataset)7 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 ResultSet (org.apache.jena.query.ResultSet)5 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)5 Element (org.apache.jena.sparql.syntax.Element)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RiotException (org.apache.jena.riot.RiotException)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4