Search in sources :

Example 31 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 32 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 33 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 34 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)

Example 35 with Dataset

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();
}
Also used : Dataset(org.apache.jena.query.Dataset) WonNodeInformationService(won.protocol.service.WonNodeInformationService) URI(java.net.URI)

Aggregations

Dataset (org.apache.jena.query.Dataset)725 Test (org.junit.Test)401 Model (org.apache.jena.rdf.model.Model)173 Ignore (org.junit.Ignore)93 URI (java.net.URI)80 Resource (org.apache.jena.rdf.model.Resource)70 QueryExecution (org.apache.jena.query.QueryExecution)53 ArrayList (java.util.ArrayList)46 QuerySolution (org.apache.jena.query.QuerySolution)46 ResultSet (org.apache.jena.query.ResultSet)45 WonNodeInformationService (won.protocol.service.WonNodeInformationService)28 Statement (org.apache.jena.rdf.model.Statement)26 Node (org.apache.jena.graph.Node)23 InputStream (java.io.InputStream)22 RDFNode (org.apache.jena.rdf.model.RDFNode)21 RdfUtils (won.protocol.util.RdfUtils)19 WonMessage (won.protocol.message.WonMessage)17 Literal (org.apache.jena.rdf.model.Literal)16 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16