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);
}
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;
}
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;
}
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;
}
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();
}
Aggregations