Search in sources :

Example 1 with SDBExceptionSQL

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

the class FmtLayout2IndexPGSQL method formatTableNodes.

@Override
protected void formatTableNodes() {
    dropTable(TableDescNodes.name());
    try {
        connection().exec(sqlStr("CREATE TABLE " + TableDescNodes.name() + " (", "   id SERIAL,", "   hash BIGINT NOT NULL,", "   lex TEXT NOT NULL,", "   lang varchar NOT NULL default '',", "   datatype varchar(" + TableDescNodes.DatatypeUriLength + ") NOT NULL default '',", "   type integer NOT NULL default '0',", "   PRIMARY KEY (id)", ")"));
        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 2 with SDBExceptionSQL

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

the class FmtLayout2IndexSAP method formatTableTriples.

@Override
protected void formatTableTriples() {
    dropTable(TableDescTriples.name());
    try {
        connection().exec(sqlStr("CREATE " + storageType.getStorageName() + " TABLE " + TableDescTriples.name() + " (", "    s integer NOT NULL,", "    p integer NOT NULL,", "    o integer NOT NULL", ")"));
        connection().exec(sqlStr("ALTER TABLE " + TableDescTriples.name() + " ADD 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)

Example 3 with SDBExceptionSQL

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

the class FmtLayout2IndexSAP method formatTableNodes.

@Override
protected void formatTableNodes() {
    dropTable(TableDescNodes.name());
    try {
        connection().exec(sqlStr("CREATE " + storageType.getStorageName() + " TABLE " + TableDescNodes.name() + " (", "   id INTEGER NOT NULL,", "   hash BIGINT NOT NULL,", "   lex nvarchar(5000) NOT NULL,", "   lang nvarchar(10) NOT NULL default '',", "   datatype nvarchar(" + TableDescNodes.DatatypeUriLength + ") NOT NULL default '',", "   type integer NOT NULL default '0'", ")"));
        connection().exec(sqlStr("ALTER TABLE " + TableDescNodes.name() + " ADD PRIMARY KEY (id)"));
        // 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", "NO CYCLE"));
        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 4 with SDBExceptionSQL

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

the class TupleTable method getDesc.

private static TableDesc getDesc(Store store, String tableName) {
    ResultSetJDBC tableData = null;
    List<String> colVars = new ArrayList<String>();
    try {
        // Need to portable get the column names.
        tableData = store.getConnection().execQuery("SELECT * FROM " + tableName);
        java.sql.ResultSetMetaData meta = tableData.get().getMetaData();
        int N = meta.getColumnCount();
        for (int i = 1; i <= N; i++) {
            String colName = meta.getColumnName(i);
            colVars.add(colName);
        }
        return new TableDesc(tableName, colVars);
    } catch (SQLException ex) {
        throw new SDBExceptionSQL(ex);
    } finally {
        RS.close(tableData);
    }
}
Also used : SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) ArrayList(java.util.ArrayList)

Example 5 with SDBExceptionSQL

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

the class TupleTable method iterator.

public QueryIterator iterator() {
    SDBRequest request = new SDBRequest(store, null);
    String tableName = desc.getTableName();
    SQLBridge b = store.getSQLBridgeFactory().create(request, sqlTable, vars);
    b.build();
    try {
        String sqlStr = store.getSQLGenerator().generateSQL(request, b.getSqlNode());
        //System.out.println(sqlStr) ;
        ResultSetJDBC tableData = store.getConnection().execQuery(sqlStr);
        ExecutionContext execCxt = new ExecutionContext(new Context(), null, null, null);
        return b.assembleResults(tableData, BindingRoot.create(), execCxt);
    } catch (SQLException ex) {
        throw new SDBExceptionSQL(ex);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) SDBExceptionSQL(org.apache.jena.sdb.sql.SDBExceptionSQL) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC) SDBRequest(org.apache.jena.sdb.core.SDBRequest)

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