Search in sources :

Example 1 with SqlConstant

use of org.apache.jena.sdb.core.sqlexpr.SqlConstant in project jena by apache.

the class TupleLoaderOneHash method insertNode.

@Override
public SqlConstant insertNode(Node node) throws SQLException {
    int typeId = NodeLayout2.nodeToType(node);
    String lex = NodeLayout2.nodeToLex(node);
    String lang = "";
    String datatype = "";
    if (node.isLiteral()) {
        lang = node.getLiteralLanguage();
        datatype = node.getLiteralDatatypeURI();
        if (NodeUtils.isSimpleString(node) || NodeUtils.isLangString(node))
            datatype = "";
    }
    long hash = NodeLayout2.hash(lex, lang, datatype, typeId);
    // Existance check
    String sqlStmtTest = strjoinNL("SELECT hash FROM " + TableDescNodes.name(), "WHERE hash = " + hash);
    ResultSetJDBC rsx = null;
    try {
        rsx = connection().execQuery(sqlStmtTest);
        ResultSet rs = rsx.get();
        boolean b = rs.next();
        if (b)
            // Exists
            return new SqlConstant(hash);
    } finally {
        RS.close(rsx);
    }
    String sqlStmt = strjoinNL("INSERT INTO " + TableDescNodes.name() + "(hash,lex,lang,datatype,type) VALUES", "  (" + hash + ", ", "   " + SQLUtils.quoteStr(lex) + ", ", "   " + SQLUtils.quoteStr(lang) + ", ", "   " + SQLUtils.quoteStr(datatype) + ", ", "   " + typeId, ")");
    connection().execUpdate(sqlStmt);
    return new SqlConstant(hash);
}
Also used : SqlConstant(org.apache.jena.sdb.core.sqlexpr.SqlConstant) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) ResultSet(java.sql.ResultSet)

Aggregations

ResultSet (java.sql.ResultSet)1 SqlConstant (org.apache.jena.sdb.core.sqlexpr.SqlConstant)1 ResultSetJDBC (org.apache.jena.sdb.sql.ResultSetJDBC)1