Search in sources :

Example 71 with Dataset

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

the class ExTDB4 method main.

public static void main(String... argv) {
    // Direct way: Make a TDB-back Jena model in the named directory.
    String directory = "MyDatabases/DB1";
    Dataset dataset = TDBFactory.createDataset(directory);
    // Potentially expensive query.
    String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }";
    // See http://incubator.apache.org/jena/documentation/query/app_api.html
    Query query = QueryFactory.create(sparqlQueryString);
    QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
    ResultSet results = qexec.execSelect();
    ResultSetFormatter.out(results);
    qexec.close();
    dataset.close();
}
Also used : Query(org.apache.jena.query.Query) Dataset(org.apache.jena.query.Dataset) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution)

Example 72 with Dataset

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

the class ExTDB_Txn1 method main.

public static void main(String... argv) {
    String directory = "MyDatabases/DB1";
    Dataset dataset = TDBFactory.createDataset(directory);
    // Start READ transaction. 
    //   No updates or changes to the dataset are possible while this
    //   dataset is used for a read transaction.
    //   An application can have other Datasets, in the same JVM, 
    //   tied to the same TDB database performing read or write
    //   transactions concurrently.
    dataset.begin(ReadWrite.READ);
    try {
        // Do some queries
        String sparqlQueryString1 = "SELECT (count(*) AS ?count) { ?s ?p ?o }";
        execQuery(sparqlQueryString1, dataset);
        String sparqlQueryString2 = "SELECT * { ?s ?p ?o }";
        execQuery(sparqlQueryString2, dataset);
    // Can also call dataset.abort() or dataset.commit() here 
    } finally {
        // Notify the end of the READ transaction.
        // Any use of dataset.abort() or dataset.commit() or dataset.end()
        // .end() can be called multiple times for the same .begin(READ)
        dataset.end();
    }
}
Also used : Dataset(org.apache.jena.query.Dataset)

Example 73 with Dataset

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

the class TDBBackup method backup.

public static void backup(Location location, OutputStream backupfile) {
    Dataset ds = TDBFactory.createDataset(location);
    StoreConnection sConn = StoreConnection.make(location);
    DatasetGraphTxn dsg = sConn.begin(ReadWrite.READ, "backup");
    RDFDataMgr.write(backupfile, dsg, Lang.NQUADS);
    dsg.end();
}
Also used : Dataset(org.apache.jena.query.Dataset) DatasetGraphTxn(org.apache.jena.tdb.transaction.DatasetGraphTxn)

Example 74 with Dataset

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

the class SpatialSearchUtil method joinDataset.

private static Dataset joinDataset(Dataset baseDataset, File indexDir) throws IOException {
    EntityDefinition entDef = new EntityDefinition("uri", "geo");
    // Lucene, index in File system.
    Directory dir = FSDirectory.open(indexDir.toPath());
    // Join together into a dataset
    Dataset ds = SpatialDatasetFactory.createLucene(baseDataset, dir, entDef);
    return ds;
}
Also used : Dataset(org.apache.jena.query.Dataset) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 75 with Dataset

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

the class TestTransactionTDB method transaction_50.

@Test
public void transaction_50() {
    // This assumes you have two datasets on the same location.
    // That's not necessarily true for uncached memory datasets, 
    // where you get two separate datasets so changes to one are
    // not seen by the other at all.
    Dataset ds1 = create();
    Dataset ds2 = create();
    ds1.begin(WRITE);
    ds1.getDefaultModel().getGraph().add(triple1);
    ds2.begin(READ);
    assertTrue(ds2.getDefaultModel().isEmpty());
    ds2.commit();
    ds1.commit();
    ds2.begin(READ);
    // See ds1 updates
    Graph g = ds2.getDefaultModel().getGraph();
    DatasetGraph dsg = ds2.asDatasetGraph();
    g = dsg.getDefaultGraph();
    boolean b0 = g.isEmpty();
    boolean b1 = ds2.getDefaultModel().isEmpty();
    assertFalse(ds2.getDefaultModel().isEmpty());
    assertEquals(1, ds2.getDefaultModel().size());
    ds2.commit();
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Dataset(org.apache.jena.query.Dataset) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) ConfigTest(org.apache.jena.tdb.ConfigTest)

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