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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations