Search in sources :

Example 1 with Store

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

the class sdbtuple method execPrint.

private void execPrint(String tableName) {
    Store store = getStore();
    TupleTable table = null;
    if (tableName.equalsIgnoreCase(store.getNodeTableDesc().getTableName())) {
        // A hack.
        // Need to chage SQLBridge to work on Node tables directly (no special build of value getters)
        TableDesc desc = new TableDesc(tableName, store.getNodeTableDesc().getNodeRefColName());
        table = new TupleTable(store, desc);
    } else
        table = new TupleTable(store, tableName);
    divider();
    table.dump();
}
Also used : Store(org.apache.jena.sdb.Store) TableDesc(org.apache.jena.sdb.store.TableDesc) TupleTable(org.apache.jena.sdb.store.TupleTable)

Example 2 with Store

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

the class TestConnection method connection_1.

@Test
public void connection_1() {
    SDBConnection conn1 = SDBFactory.createConnection(conn);
    Store store1 = StoreFactory.create(storeDesc, conn1);
    // Reset
    store1.getTableFormatter().format();
    SDBConnection conn2 = SDBFactory.createConnection(conn);
    Store store2 = StoreFactory.create(storeDesc, conn2);
    Model model1 = SDBFactory.connectDefaultModel(store1);
    Model model2 = SDBFactory.connectDefaultModel(store2);
    Resource s = model1.createResource();
    Property p = model1.createProperty("http://example/p");
    // These are autocommit so two stores should be OK (but not a good design paradigm)
    model1.add(s, p, "model1");
    model2.add(s, p, "model2");
    assertEquals(2, model1.size());
    assertEquals(2, model2.size());
    assertTrue(model1.isIsomorphicWith(model2));
}
Also used : SDBConnection(org.apache.jena.sdb.sql.SDBConnection) 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 3 with Store

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

the class TestConnectionPooled method reuseJDBCConection.

@Test
public void reuseJDBCConection() {
    Triple t1 = SSE.parseTriple("(:x1 :p :z)");
    Triple t2 = SSE.parseTriple("(:x2 :p :z)");
    boolean explicitTransactions = false;
    // Make store.
    {
        SDBConnection sConn1 = SDBConnectionFactory.create(conn);
        Store store1 = StoreFactory.create(sConn1, store.getLayoutType(), store.getDatabaseType());
        if (explicitTransactions)
            store1.getConnection().getTransactionHandler().begin();
        Graph graph1 = SDBFactory.connectDefaultGraph(store1);
        graph1.add(t1);
        assertTrue(graph1.contains(t1));
        if (explicitTransactions) {
            store1.getConnection().getTransactionHandler().commit();
            assertTrue(graph1.contains(t1));
        }
    //store1.close() ;
    }
    // Mythically return conn to the pool.
    // Get from pool
    // i.e. same connection.  Make a store around it
    {
        SDBConnection sConn2 = SDBConnectionFactory.create(conn);
        Store store2 = StoreFactory.create(sConn2, store.getLayoutType(), store.getDatabaseType());
        if (explicitTransactions)
            store2.getConnection().getTransactionHandler().begin();
        Graph graph2 = SDBFactory.connectDefaultGraph(store2);
        assertTrue(graph2.contains(t1));
        graph2.add(t2);
        assertTrue(graph2.contains(t2));
        if (explicitTransactions)
            store2.getConnection().getTransactionHandler().commit();
    //store2.close() ;
    }
    System.exit(0);
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) SDBConnection(org.apache.jena.sdb.sql.SDBConnection) Store(org.apache.jena.sdb.Store) Test(org.junit.Test)

Example 4 with Store

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

the class StoreList method testStore.

public static Store testStore(StoreDesc desc) {
    Store store = StoreFactory.create(desc);
    // HSQL and H2 (in memory) need formatting
    // Better would be to know in memory/on disk
    // Relies on StoreDesc getting the label correctly (SDBConnectionFactory)
    String jdbcURL = store.getConnection().getJdbcURL();
    boolean isInMem = (jdbcURL == null ? false : jdbcURL.contains(":mem:"));
    if (formatStores || inMem(store))
        store.getTableFormatter().create();
    return store;
}
Also used : Store(org.apache.jena.sdb.Store)

Example 5 with Store

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

the class TestAssembler method model_5.

@Test
public void model_5() {
    Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
    Resource xDft = assem.getResource("http://example/test#graphDft");
    Store store = create(assem);
    // Default graph: Check they are connected to the same place in the store 
    Model model2 = (Model) Assembler.general.open(xDft);
    Model model3 = (Model) Assembler.general.open(xDft);
    Resource s = model2.createResource();
    Property p = model2.createProperty("http://example/p");
    // Check two models connected to the same graph 
    Literal o2 = model2.createLiteral("xyz");
    model2.add(s, p, o2);
    assertTrue(model3.contains(s, p, o2));
}
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)

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