Search in sources :

Example 41 with SDBExceptionSQL

use of org.apache.jena.sdb.sql.SDBExceptionSQL 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)

Example 42 with SDBExceptionSQL

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

the class FmtLayout2IndexDB2 method formatTableNodes.

@Override
protected void formatTableNodes() {
    dropTable(TableDescNodes.name());
    try {
        connection().exec(sqlStr("CREATE TABLE " + TableDescNodes.name() + " (", "   id INT NOT NULL ,", "   hash BIGINT NOT NULL,", "   lex CLOB NOT NULL,", "   lang VARCHAR(10),", "   datatype VARCHAR(" + TableDescNodes.DatatypeUriLength + "),", "   type INTEGER  NOT NULL,", "   PRIMARY KEY (id)", ")  CCSID UNICODE"));
        //connection().exec("CREATE UNIQUE INDEX Hash ON " + TableNodes.tableName + " (hash)");
        // Urgh. How do we find out if a sequence exists?
        connection().execSilent("DROP SEQUENCE nodeid");
        connection().exec(sqlStr("CREATE SEQUENCE nodeid AS INT", "START WITH 1", "INCREMENT BY 1", "CACHE 5000", "ORDER", "NO MAXVALUE", "NO CYCLE"));
    } catch (SQLException ex) {
        throw new SDBExceptionSQL("SQLException resetting table '" + TableDescNodes.name() + "'", ex);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException)

Example 43 with SDBExceptionSQL

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

the class FmtLayout2IndexDerby method formatTableTriples.

@Override
protected void formatTableTriples() {
    // TODO Generalize : return a template
    TableDescTriples desc = new TableDescTriples();
    dropTable(desc.getTableName());
    try {
        String x = sqlStr("CREATE TABLE %s (", "    %2$s int NOT NULL,", "    %3$s int NOT NULL,", "    %4$s int NOT NULL,", "    PRIMARY KEY (%2$s, %3$s, %4$s)", ")");
        x = String.format(x, desc.getTableName(), desc.getSubjectColName(), desc.getPredicateColName(), desc.getObjectColName());
        connection().exec(sqlStr("CREATE TABLE " + desc.getTableName() + " (", "    s int NOT NULL,", "    p int NOT NULL,", "    o int NOT NULL,", "    PRIMARY KEY (s, p, o)", ")"));
    } catch (SQLException ex) {
        throw new SDBExceptionSQL("SQLException formatting table '" + TableDescTriples.name() + "'", ex);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) TableDescTriples(org.apache.jena.sdb.layout2.TableDescTriples)

Example 44 with SDBExceptionSQL

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

the class FmtLayout2IndexMySQL method formatTableNodes.

@Override
protected void formatTableNodes() {
    dropTable(TableDescNodes.name());
    try {
        connection().exec(sqlStr("CREATE TABLE " + TableDescNodes.name() + " (", "   id int unsigned NOT NULL auto_increment,", "   hash BIGINT NOT NULL DEFAULT 0,", "   lex LONGTEXT BINARY CHARACTER SET utf8 ,", "   lang VARCHAR(10) BINARY CHARACTER SET utf8 NOT NULL default '',", "   datatype VARCHAR(" + TableDescNodes.DatatypeUriLength + ") BINARY CHARACTER SET utf8 NOT NULL default '',", // SDB built-in
        "   type int unsigned NOT NULL default '0',", "   PRIMARY KEY Id  (id)", ") ENGINE=" + engineType.getEngineName() + " DEFAULT CHARSET=utf8;"));
        connection().exec("CREATE UNIQUE INDEX Hash ON " + TableDescNodes.name() + " (hash)");
    } catch (SQLException ex) {
        throw new SDBExceptionSQL("SQLException formatting table '" + TableDescNodes.name() + "'", ex);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException)

Example 45 with SDBExceptionSQL

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

the class FmtLayout2IndexOracle method formatTableNodes.

@Override
protected void formatTableNodes() {
    dropTable(TableDescNodes.name());
    try {
        connection().exec(sqlStr("CREATE TABLE " + TableDescNodes.name() + " (", "   id int NOT NULL ,", "   hash NUMBER(20) NOT NULL,", // No NOT NULL on char data in Oracle. '' is NULL!
        "   lex NCLOB,", "   lang NVARCHAR2(10),", "   datatype NVARCHAR2(" + TableDescNodes.DatatypeUriLength + "),", "   type integer  NOT NULL,", "   PRIMARY KEY (id)", ")"));
        //connection().exec("CREATE UNIQUE INDEX Hash ON " + TableNodes.tableName + " (hash)");
        // Urgh. How do we find out if a sequence exists?
        connection().execSilent("DROP SEQUENCE nodeid");
        connection().exec(sqlStr("CREATE SEQUENCE nodeid", "START WITH 1", "INCREMENT BY 1", "CACHE 5000", "NOCYCLE"));
    } catch (SQLException ex) {
        throw new SDBExceptionSQL("SQLException resetting table '" + TableDescNodes.name() + "'", ex);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)47 SDBExceptionSQL (org.apache.jena.sdb.sql.SDBExceptionSQL)47 ResultSetJDBC (org.apache.jena.sdb.sql.ResultSetJDBC)8 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)1 SDBException (org.apache.jena.sdb.SDBException)1 SDBRequest (org.apache.jena.sdb.core.SDBRequest)1 TableDescQuads (org.apache.jena.sdb.layout2.TableDescQuads)1 TableDescTriples (org.apache.jena.sdb.layout2.TableDescTriples)1 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)1 Context (org.apache.jena.sparql.util.Context)1