Search in sources :

Example 1 with GraphStore

use of org.apache.jena.update.GraphStore in project jena by apache.

the class ExTDB_Txn2 method main.

public static void main(String... argv) {
    String directory = "MyDatabases/DB1";
    Dataset dataset = TDBFactory.createDataset(directory);
    // Start WRITE transaction. 
    //   It's possible to read from the datet inside the write transaction.
    //   An application can have other Datasets, in the same JVM, 
    //   tied to the same TDB database performing read
    //   transactions concurrently. If another write transaction
    //   starts, the call of dataset.begin(WRITE) blocks until
    //   existing writer finishes.
    dataset.begin(ReadWrite.WRITE);
    try {
        GraphStore graphStore = GraphStoreFactory.create(dataset);
        // Do a SPARQL Update.
        String sparqlUpdateString = StrUtils.strjoinNL("PREFIX . <http://example/>", "INSERT { :s :p ?now } WHERE { BIND(now() AS ?now) }");
        execUpdate(sparqlUpdateString, graphStore);
        dataset.commit();
    // Or call .abort()
    } finally {
        // Notify the end of the transaction.
        // The transaction was finished at the point .commit or .abort was called.
        // .end will force an abort() if no previous call to .commit() or .abort()
        // has occurred, so .end() help manage track the state of the transaction.
        // .end() can be called multiple times for the same .begin(WRITE)
        dataset.end();
    }
}
Also used : GraphStore(org.apache.jena.update.GraphStore) Dataset(org.apache.jena.query.Dataset)

Aggregations

Dataset (org.apache.jena.query.Dataset)1 GraphStore (org.apache.jena.update.GraphStore)1