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();
}
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();
}
}
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;
}
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();
}
use of org.apache.jena.query.Dataset in project webofneeds by researchstudio-sat.
the class BotActionUtils method createWonMessage.
public static WonMessage createWonMessage(final EventListenerContext context, final URI connectionURI, final String message) throws WonMessageBuilderException {
WonNodeInformationService wonNodeInformationService = context.getWonNodeInformationService();
Dataset connectionRDF = context.getLinkedDataSource().getDataForResource(connectionURI);
URI remoteNeed = WonRdfUtils.ConnectionUtils.getRemoteNeedURIFromConnection(connectionRDF, connectionURI);
URI localNeed = WonRdfUtils.ConnectionUtils.getLocalNeedURIFromConnection(connectionRDF, connectionURI);
URI wonNode = WonRdfUtils.ConnectionUtils.getWonNodeURIFromConnection(connectionRDF, connectionURI);
Dataset remoteNeedRDF = context.getLinkedDataSource().getDataForResource(remoteNeed);
URI messageURI = wonNodeInformationService.generateEventURI(wonNode);
return WonMessageBuilder.setMessagePropertiesForConnectionMessage(messageURI, connectionURI, localNeed, wonNode, WonRdfUtils.ConnectionUtils.getRemoteConnectionURIFromConnection(connectionRDF, connectionURI), remoteNeed, WonRdfUtils.NeedUtils.getWonNodeURIFromNeed(remoteNeedRDF, remoteNeed), message).build();
}
Aggregations