public Graph generateGraph() {
   try {
     if (this.connection == null) {
       this.connection = ds.getConnection();
     } else if (this.connection.isClosed()) {
       try {
         this.connection.close();
       } catch (SQLException e) {
         // The connection will throw an "Already closed"
         // SQLException that we need to catch.  We need to
         // make this extra call to .close() in order to make
         // sure that the connection is returned to the pool.
         // This depends on the particular behavior of version
         // 1.4 of the Apache Commons connection pool library.
         // Earlier versions threw the exception right away,
         // making this impossible. Future versions may do the
         // same.
       }
       this.connection = ds.getConnection();
     }
     Store store = SDBFactory.connectStore(connection, storeDesc);
     return SDBFactory.connectNamedGraph(store, graphID);
   } catch (SQLException e) {
     String errMsg = "Unable to generate SDB graph";
     log.error(errMsg, e);
     throw new RuntimeException(errMsg, e);
   }
 }
Esempio n. 2
0
  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();
  }
 @Override
 public Graph getGraph() {
   Store store = StoreCreator.getHashMySQL();
   return SDBFactory.connectNamedGraph(store, "http://example.com/graph");
 }
 @Override
 public Graph getGraph() {
   Store store = StoreCreator.getHashMySQL();
   return SDBFactory.connectDefaultGraph(store);
 }