Search in sources :

Example 6 with ResultSetJDBC

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

the class StoreBaseHash method getSize.

public static long getSize(SDBConnection connection, TableDescQuads tableDescQuads, Node node) {
    String lex = NodeLayout2.nodeToLex(node);
    int typeId = NodeLayout2.nodeToType(node);
    String lang = "";
    String datatype = "";
    if (node.isLiteral()) {
        lang = node.getLiteralLanguage();
        datatype = node.getLiteralDatatypeURI();
        if (NodeUtils.isSimpleString(node) || NodeUtils.isLangString(node))
            datatype = "";
    }
    ResultSetJDBC rsx = null;
    long hash = NodeLayout2.hash(lex, lang, datatype, typeId);
    try {
        rsx = connection.exec("SELECT COUNT(*) FROM " + tableDescQuads.getTableName() + " WHERE g = " + hash);
        ResultSet res = rsx.get();
        res.next();
        long result = res.getLong(1);
        return result;
    } catch (SQLException e) {
        throw new SDBExceptionSQL("Failed to get graph size", e);
    } finally {
        RS.close(rsx);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) ResultSet(java.sql.ResultSet)

Example 7 with ResultSetJDBC

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

the class PrefixMappingSDB method readFromPrefixMap.

private String readFromPrefixMap(String prefix) {
    ResultSetJDBC rsx = null;
    try {
        String sqlStmt = sqlStr("SELECT uri FROM " + prefixTableName, "   WHERE prefix = " + quoteStr(prefix));
        rsx = connection.execQuery(sqlStmt);
        ResultSet rs = rsx.get();
        String uri = null;
        while (rs.next()) {
            String v = rs.getString("uri");
            uri = v;
            if (rs.next())
                log.warn("Multiple prefix mappings for '" + prefix + "'");
            break;
        }
        return uri;
    } catch (SQLException ex) {
        throw new SDBExceptionSQL(format("Failed to read prefix (%s)", prefix), ex);
    } finally {
        RS.close(rsx);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) ResultSet(java.sql.ResultSet)

Example 8 with ResultSetJDBC

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

the class PrefixMappingSDB method readPrefixMapping.

// Super class implementation loops and calls setNsPrefix calls set() for each entry.
//@Override
//public PrefixMapping setNsPrefixes(PrefixMapping arg0)
// Super class implementation will suffice.
// It (creates a map copy and) loops on each entry.
//@Override
//public PrefixMapping setNsPrefixes(Map arg0)
// -------- Worker implementations
private void readPrefixMapping() {
    ResultSetJDBC rsx = null;
    try {
        String sqlStmt = "SELECT prefix, uri FROM " + prefixTableName;
        rsx = connection.execSilent(sqlStmt);
        if (rsx == null || rsx.get() == null)
            return;
        ResultSet rs = rsx.get();
        while (rs.next()) {
            String p = rs.getString("prefix");
            p = decode(p);
            String v = rs.getString("uri");
            // Load in-memory copy.
            super.set(p, v);
        }
    } catch (SQLException ex) {
        throw new SDBExceptionSQL("Failed to get prefixes", ex);
    } finally {
        RS.close(rsx);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) ResultSet(java.sql.ResultSet)

Example 9 with ResultSetJDBC

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

the class TupleLoaderOne method entryExists.

protected boolean entryExists(String[] vals) {
    String rowValues = whereRow(vals);
    String selectTemplate = "SELECT count(*) FROM %s WHERE %s\n";
    String sqlStmt = String.format(selectTemplate, getTableName(), rowValues);
    ResultSetJDBC rs = null;
    try {
        rs = connection().execQuery(sqlStmt);
        rs.get().next();
        int count = rs.get().getInt(1);
        if (count > 0) {
            log.debug("Duplicate tuple detected: count=" + count + " :: " + vals);
            return true;
        }
        // Otherwise deos not exist
        return false;
    } catch (SQLException ex) {
        throw new SDBExceptionSQL(ex);
    } finally {
        RS.close(rs);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC)

Example 10 with ResultSetJDBC

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

the class StoreBaseIndex method getSize.

public static long getSize(SDBConnection connection, TableDescQuads tableDescQuads, Node node) {
    String lex = NodeLayout2.nodeToLex(node);
    int typeId = NodeLayout2.nodeToType(node);
    String lang = "";
    String datatype = "";
    if (node.isLiteral()) {
        lang = node.getLiteralLanguage();
        datatype = node.getLiteralDatatypeURI();
        if (NodeUtils.isSimpleString(node) || NodeUtils.isLangString(node))
            datatype = "";
    }
    ResultSetJDBC rsx = null;
    long hash = NodeLayout2.hash(lex, lang, datatype, typeId);
    try {
        rsx = connection.exec("SELECT id FROM Nodes WHERE hash = " + hash);
        ResultSet res = rsx.get();
        int id = -1;
        if (res.next())
            id = res.getInt(1);
        else
            // no graph, size == 0
            return 0;
        rsx.close();
        rsx = connection.exec("SELECT COUNT(*) FROM " + tableDescQuads.getTableName() + " WHERE g = " + id);
        res = rsx.get();
        res.next();
        long result = res.getLong(1);
        return result;
    } catch (SQLException e) {
        throw new SDBExceptionSQL("Failed to get graph size", e);
    } finally {
        RS.close(rsx);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) ResultSet(java.sql.ResultSet)

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