Search in sources :

Example 11 with ResultSetJDBC

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) SDBException(org.apache.jena.sdb.SDBException) ResultSet(java.sql.ResultSet)

Example 12 with ResultSetJDBC

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC)

Aggregations

ResultSetJDBC (org.apache.jena.sdb.sql.ResultSetJDBC)12 SQLException (java.sql.SQLException)11 SDBExceptionSQL (org.apache.jena.sdb.sql.SDBExceptionSQL)8 ResultSet (java.sql.ResultSet)6 ArrayList (java.util.ArrayList)1 TerminationException (jena.cmd.TerminationException)1 SDBException (org.apache.jena.sdb.SDBException)1 SDBRequest (org.apache.jena.sdb.core.SDBRequest)1 SqlConstant (org.apache.jena.sdb.core.sqlexpr.SqlConstant)1 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)1 Context (org.apache.jena.sparql.util.Context)1