Search in sources :

Example 6 with SDBConnection

use of org.apache.jena.sdb.sql.SDBConnection 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 7 with SDBConnection

use of org.apache.jena.sdb.sql.SDBConnection in project jena by apache.

the class StoreCreator method getIndexPgSQL.

public static Store getIndexPgSQL() {
    if (sdbpgi == null) {
        JDBC.loadDriverPGSQL();
        SDBConnection sdb = SDBFactory.createConnection("jdbc:postgresql://localhost/test2-index", "user", "password");
        StoreDesc desc = new StoreDesc(LayoutType.LayoutTripleNodesIndex, DatabaseType.PostgreSQL);
        sdbpgi = new StoreTriplesNodesIndexPGSQL(sdb, desc);
        sdbpgi.getTableFormatter().create();
    } else
        sdbpgi.getTableFormatter().truncate();
    return sdbpgi;
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBConnection(org.apache.jena.sdb.sql.SDBConnection)

Example 8 with SDBConnection

use of org.apache.jena.sdb.sql.SDBConnection in project jena by apache.

the class StoreCreator method getIndexSQLServer.

public static Store getIndexSQLServer() {
    if (sdbssi == null) {
        JDBC.loadDriverSQLServer();
        SDBConnection sdb = SDBFactory.createConnection(MSSQL_url + "test2-index", MSSQL_user, MSSQL_password);
        StoreDesc desc = new StoreDesc(LayoutType.LayoutTripleNodesIndex, DatabaseType.SQLServer);
        sdbssi = new StoreTriplesNodesIndexSQLServer(sdb, desc);
        sdbssi.getTableFormatter().create();
    } else
        sdbssi.getTableFormatter().truncate();
    return sdbssi;
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBConnection(org.apache.jena.sdb.sql.SDBConnection)

Example 9 with SDBConnection

use of org.apache.jena.sdb.sql.SDBConnection in project jena by apache.

the class StoreCreator method getHashSAP.

public static Store getHashSAP() {
    if (sdbsaph == null) {
        JDBC.loadDriverSAP();
        SDBConnection sdb = SDBFactory.createConnection("jdbc:sap://localhost/test2-hash", "user", "password");
        StoreDesc desc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.SAP);
        sdbsaph = new StoreTriplesNodesHashSAP(sdb, desc);
        sdbsaph.getTableFormatter().create();
    } else
        sdbsaph.getTableFormatter().truncate();
    return sdbsaph;
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBConnection(org.apache.jena.sdb.sql.SDBConnection)

Example 10 with SDBConnection

use of org.apache.jena.sdb.sql.SDBConnection 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)

Aggregations

SDBConnection (org.apache.jena.sdb.sql.SDBConnection)21 StoreDesc (org.apache.jena.sdb.StoreDesc)18 Store (org.apache.jena.sdb.Store)5 DatasetStore (org.apache.jena.sdb.store.DatasetStore)2 Test (org.junit.Test)2 Graph (org.apache.jena.graph.Graph)1 Triple (org.apache.jena.graph.Triple)1 Model (org.apache.jena.rdf.model.Model)1 Property (org.apache.jena.rdf.model.Property)1 Resource (org.apache.jena.rdf.model.Resource)1