use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class TupleLoaderOneIndex method getIndex.
/// ----------
private static int getIndex(SDBConnection conn, Node node, boolean create) throws SQLException {
long hash = NodeLayout2.hash(node);
String lex = NodeLayout2.nodeToLex(node);
String hashStr = Long.toString(hash);
String sqlStmt = "SELECT id FROM Nodes WHERE hash = " + hashStr;
ResultSetJDBC rsx = null;
try {
rsx = conn.execQuery(sqlStmt);
ResultSet rs = rsx.get();
if (!rs.next()) {
if (!create)
throw new SDBException("No such node in table: " + node);
insertNode(conn, lex, node);
// And get it again to find the auto-allocate ID.
return getIndex(conn, node, false);
}
int id = rs.getInt("id");
if (rs.next())
log.warn("More than one hit for : " + sqlStmt + " (ignored)");
return id;
} catch (SQLException ex) {
log.warn("SQLException: " + ex.getMessage());
throw ex;
} finally {
RS.close(rsx);
}
}
use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class TestStoreUpdateBase method size.
protected int size(String name) {
ResultSetJDBC result = null;
try {
int size = -1;
result = store.getConnection().execQuery("SELECT COUNT(*) FROM " + name);
if (result.get().next())
size = result.get().getInt(1);
result.close();
result = store.getConnection().execQuery("SELECT * FROM " + name);
while (result.get().next()) System.err.println("Row: " + result.get().getObject(1));
return size;
} catch (SQLException e) {
throw new RuntimeException("Can't get size of table '" + name + "'", e);
} finally {
RS.close(result);
}
}
Aggregations