Search in sources :

Example 6 with Store

use of org.apache.jena.sdb.Store in project jena by apache.

the class TestAssembler method create.

private Store create(Model assem) {
    // Create a store and format
    Dataset ds = DatasetFactory.assemble(assem);
    Store store = ((DatasetGraphSDB) ds.asDatasetGraph()).getStore();
    store.getTableFormatter().create();
    return store;
}
Also used : Dataset(org.apache.jena.query.Dataset) DatasetGraphSDB(org.apache.jena.sdb.store.DatasetGraphSDB) Store(org.apache.jena.sdb.Store)

Example 7 with Store

use of org.apache.jena.sdb.Store in project jena by apache.

the class TestAssembler method model_4.

@Test
public void model_4() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xDft = assem.getResource("http://example/test#graphDft");
    Resource xNamed = assem.getResource("http://example/test#graphNamed");
    Store store = create(assem);
    Model model1 = (Model) Assembler.general.open(xDft);
    Model model2 = (Model) Assembler.general.open(xNamed);
    // Check they are not connected to the same place in the store 
    Resource s = model1.createResource();
    Property p = model1.createProperty("http://example/p");
    Literal o = model1.createLiteral("foo");
    model1.add(s, p, o);
    assertTrue(model1.contains(s, p, o));
    assertTrue(model1.size() == 1);
    assertTrue(model2.size() == 0);
    assertFalse(model1.isIsomorphicWith(model2));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Store(org.apache.jena.sdb.Store) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 8 with Store

use of org.apache.jena.sdb.Store in project jena by apache.

the class ExModelSDB method main.

public static void main(String... argv) {
    Store store = StoreFactory.create("sdb.ttl");
    Model model = SDBFactory.connectDefaultModel(store);
    StmtIterator sIter = model.listStatements();
    for (; sIter.hasNext(); ) {
        Statement stmt = sIter.nextStatement();
        System.out.println(stmt);
    }
    sIter.close();
    store.close();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Store(org.apache.jena.sdb.Store)

Example 9 with Store

use of org.apache.jena.sdb.Store in project jena by apache.

the class Ex2 method main.

public static void main(String... argv) {
    String queryString = "SELECT * { ?s ?p ?o }";
    Query query = QueryFactory.create(queryString);
    StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.Derby);
    // Multiple choices for Derby - load the embedded driver
    JDBC.loadDriverDerby();
    String jdbcURL = "jdbc:derby:DB/SDB2";
    // Passing null for user and password causes them to be extracted
    // from the environment variables SDB_USER and SDB_PASSWORD
    SDBConnection conn = new SDBConnection(jdbcURL, null, null);
    // Make store from connection and store description. 
    Store store = SDBFactory.connectStore(conn, storeDesc);
    Dataset ds = DatasetStore.create(store);
    QueryExecution qe = QueryExecutionFactory.create(query, ds);
    try {
        ResultSet rs = qe.execSelect();
        ResultSetFormatter.out(rs);
    } finally {
        qe.close();
    }
    store.close();
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBConnection(org.apache.jena.sdb.sql.SDBConnection) Store(org.apache.jena.sdb.Store) DatasetStore(org.apache.jena.sdb.store.DatasetStore)

Example 10 with Store

use of org.apache.jena.sdb.Store in project jena by apache.

the class Ex1 method main.

public static void main(String... argv) {
    String queryString = "SELECT * { ?s ?p ?o }";
    Query query = QueryFactory.create(queryString);
    Store store = SDBFactory.connectStore("sdb.ttl");
    // Must be a DatasetStore to trigger the SDB query engine.
    // Creating a graph from the Store, and adding it to a general
    // purpose dataset will not necesarily exploit full SQL generation.
    // The right answers will be obtained but slowly.
    Dataset ds = DatasetStore.create(store);
    QueryExecution qe = QueryExecutionFactory.create(query, ds);
    try {
        ResultSet rs = qe.execSelect();
        ResultSetFormatter.out(rs);
    } finally {
        qe.close();
    }
    // Close the SDB conenction which also closes the underlying JDBC connection.
    store.getConnection().close();
    store.close();
}
Also used : Store(org.apache.jena.sdb.Store) DatasetStore(org.apache.jena.sdb.store.DatasetStore)

Aggregations

Store (org.apache.jena.sdb.Store)18 Test (org.junit.Test)8 Model (org.apache.jena.rdf.model.Model)6 Resource (org.apache.jena.rdf.model.Resource)5 SDBConnection (org.apache.jena.sdb.sql.SDBConnection)5 Property (org.apache.jena.rdf.model.Property)4 StoreDesc (org.apache.jena.sdb.StoreDesc)4 Literal (org.apache.jena.rdf.model.Literal)3 DatasetStore (org.apache.jena.sdb.store.DatasetStore)3 TupleTable (org.apache.jena.sdb.store.TupleTable)2 Connection (java.sql.Connection)1 Graph (org.apache.jena.graph.Graph)1 Triple (org.apache.jena.graph.Triple)1 Dataset (org.apache.jena.query.Dataset)1 Statement (org.apache.jena.rdf.model.Statement)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1 DatasetGraphSDB (org.apache.jena.sdb.store.DatasetGraphSDB)1 TableDesc (org.apache.jena.sdb.store.TableDesc)1 BeforeClass (org.junit.BeforeClass)1