Search in sources :

Example 96 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestTransactionLifecycle method transaction_r02.

@Test
public void transaction_r02() {
    Dataset ds = create();
    ds.begin(ReadWrite.READ);
    assertTrue(ds.isInTransaction());
    ds.commit();
    assertFalse(ds.isInTransaction());
    ds.end();
    assertFalse(ds.isInTransaction());
}
Also used : Dataset(org.apache.jena.query.Dataset) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 97 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestTransactionLifecycle method transaction_pattern_01.

// Patterns.
@Test
public void transaction_pattern_01() {
    Dataset ds = create();
    read1(ds);
    read1(ds);
}
Also used : Dataset(org.apache.jena.query.Dataset) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 98 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestTransactionLifecycle method transaction_err_nontxn_commit_1.

// Cycle misalignment.
// test : commit
// test : abort
// Permit explain .end() - the case of "end" when not sure:  begin...end.end. 
@Test(expected = JenaTransactionException.class)
public void transaction_err_nontxn_commit_1() {
    Dataset ds = create();
    ds.commit();
}
Also used : Dataset(org.apache.jena.query.Dataset) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 99 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class TestInMemDatasetAssembler method emptyDataset.

@Test
public void emptyDataset() {
    final Model model = createDefaultModel();
    final Resource empty = model.createResource("test:empty");
    empty.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
    Dataset dataset = assemble(empty);
    assertFalse(dataset.asDatasetGraph().find().hasNext());
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test)

Example 100 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class TestInMemDatasetAssembler method directDataLinkToQuads.

@Test
public void directDataLinkToQuads() throws IOException {
    // first make a file of quads to load later
    final Model model = createDefaultModel();
    final Path quads = createTempFile("quadExample", ".nq");
    final Resource quadsURI = model.createResource(quads.toFile().toURI().toString());
    final Resource simpleExample = model.createResource("test:simpleExample");
    simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
    simpleExample.addProperty(data, quadsURI);
    final DatasetGraph dsg = createTxnMem().asDatasetGraph();
    model.listStatements().mapWith(Statement::asTriple).mapWith(t -> new Quad(quadsURI.asNode(), t)).forEachRemaining(dsg::add);
    try (OutputStream out = new FileOutputStream(quads.toFile())) {
        write(out, dsg, NQUADS);
    }
    final Dataset dataset = assemble(simpleExample);
    final Model assembledDefaultModel = dataset.getDefaultModel();
    final Model assembledNamedModel = dataset.getNamedModel(quadsURI.getURI());
    assertTrue(assembledDefaultModel.isEmpty());
    assertTrue(assembledNamedModel.contains(assembledNamedModel.createStatement(simpleExample, data, quadsURI)));
}
Also used : Path(java.nio.file.Path) DEFAULT(org.apache.jena.assembler.Mode.DEFAULT) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) JA(org.apache.jena.assembler.JA) Model(org.apache.jena.rdf.model.Model) Statement(org.apache.jena.rdf.model.Statement) NTRIPLES(org.apache.jena.riot.RDFFormat.NTRIPLES) Quad(org.apache.jena.sparql.core.Quad) Resource(org.apache.jena.rdf.model.Resource) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) Path(java.nio.file.Path) Dataset(org.apache.jena.query.Dataset) OutputStream(java.io.OutputStream) DatasetAssemblerVocab.pGraphName(org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pGraphName) Iterator(java.util.Iterator) DatasetAssemblerVocab.pNamedGraph(org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pNamedGraph) NQUADS(org.apache.jena.riot.Lang.NQUADS) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test) RDFDataMgr.write(org.apache.jena.riot.RDFDataMgr.write) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Files.createTempFile(java.nio.file.Files.createTempFile) Node(org.apache.jena.graph.Node) DatasetFactory.createTxnMem(org.apache.jena.query.DatasetFactory.createTxnMem) RDF.type(org.apache.jena.vocabulary.RDF.type) CannotConstructException(org.apache.jena.assembler.exceptions.CannotConstructException) JA.data(org.apache.jena.assembler.JA.data) Assert(org.junit.Assert) Quad(org.apache.jena.sparql.core.Quad) Statement(org.apache.jena.rdf.model.Statement) Dataset(org.apache.jena.query.Dataset) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Model(org.apache.jena.rdf.model.Model) MemoryModel(org.apache.jena.assembler.JA.MemoryModel) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) Resource(org.apache.jena.rdf.model.Resource) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Aggregations

Dataset (org.apache.jena.query.Dataset)138 Test (org.junit.Test)63 BaseTest (org.apache.jena.atlas.junit.BaseTest)39 Model (org.apache.jena.rdf.model.Model)31 Resource (org.apache.jena.rdf.model.Resource)20 Node (org.apache.jena.graph.Node)13 RDFNode (org.apache.jena.rdf.model.RDFNode)8 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)7 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)7 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)7 ConfigTest (org.apache.jena.tdb.ConfigTest)7 CmdException (jena.cmd.CmdException)6 Graph (org.apache.jena.graph.Graph)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5 JenaTransactionException (org.apache.jena.sparql.JenaTransactionException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Path (java.nio.file.Path)4 Property (org.apache.jena.rdf.model.Property)4 OutputStream (java.io.OutputStream)3 Triple (org.apache.jena.graph.Triple)3