Search in sources :

Example 1 with Session

use of org.hsqldb_voltpatches.Session in project voltdb by VoltDB.

the class DatabaseInformationFull method COLUMN_UDT_USAGE.

/**
     * UDT's are shown if the authorization is the user or a role given to the
     * user.
     *
     * <p>
     *
     * @return Table
     */
Table COLUMN_UDT_USAGE() {
    Table t = sysTables[COLUMN_UDT_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMN_UDT_USAGE]);
        addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMN_UDT_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    Result rs = sys.executeDirectStatement("SELECT UDT_CATALOG, UDT_SCHEMA, UDT_NAME, TABLE_CATALOG, " + "TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE UDT_NAME IS NOT NULL;");
    t.insertSys(store, rs);
    sys.close();
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 2 with Session

use of org.hsqldb_voltpatches.Session in project voltdb by VoltDB.

the class DatabaseInformationFull method SQL_SIZING_PROFILES.

Table SQL_SIZING_PROFILES() {
    Table t = sysTables[SQL_SIZING_PROFILES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SQL_SIZING_PROFILES]);
        addColumn(t, "SIZING_ID", CARDINAL_NUMBER);
        addColumn(t, "SIZING_NAME", CHARACTER_DATA);
        addColumn(t, "PROFILE_ID", CARDINAL_NUMBER);
        addColumn(t, "PROFILE_NAME", CHARACTER_DATA);
        addColumn(t, "REQUIRED_VALUE", CARDINAL_NUMBER);
        addColumn(t, "COMMENTS", CHARACTER_DATA);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_SIZING_PROFILES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    /*
                Result rs = sys.executeDirectStatement(
                    "VALUES "
                    + ";");

                t.insertSys(store, rs);
        */
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session)

Example 3 with Session

use of org.hsqldb_voltpatches.Session in project voltdb by VoltDB.

the class ScriptRunner method runScript.

/**
     *  This is used to read the *.log file and manage any necessary
     *  transaction rollback.
     */
public static void runScript(Database database, String logFilename, int logType) {
    IntKeyHashMap sessionMap = new IntKeyHashMap();
    Session current = null;
    int currentId = 0;
    database.setReferentialIntegrity(false);
    ScriptReaderBase scr = null;
    String statement;
    int statementType;
    try {
        StopWatch sw = new StopWatch();
        scr = ScriptReaderBase.newScriptReader(database, logFilename, logType);
        while (scr.readLoggedStatement(current)) {
            int sessionId = scr.getSessionNumber();
            if (current == null || currentId != sessionId) {
                currentId = sessionId;
                current = (Session) sessionMap.get(currentId);
                if (current == null) {
                    current = database.getSessionManager().newSession(database, database.getUserManager().getSysUser(), false, true, 0);
                    sessionMap.put(currentId, current);
                }
            }
            if (current.isClosed()) {
                sessionMap.remove(currentId);
                continue;
            }
            Result result = null;
            statementType = scr.getStatementType();
            switch(statementType) {
                case ScriptReaderBase.ANY_STATEMENT:
                    statement = scr.getLoggedStatement();
                    result = current.executeDirectStatement(statement);
                    if (result != null && result.isError()) {
                        if (result.getException() != null) {
                            throw result.getException();
                        }
                        throw Error.error(result);
                    }
                    break;
                case ScriptReaderBase.SEQUENCE_STATEMENT:
                    scr.getCurrentSequence().reset(scr.getSequenceValue());
                    break;
                case ScriptReaderBase.COMMIT_STATEMENT:
                    current.commit(false);
                    break;
                case ScriptReaderBase.INSERT_STATEMENT:
                    {
                        current.beginAction(null);
                        Object[] data = scr.getData();
                        scr.getCurrentTable().insertNoCheckFromLog(current, data);
                        current.endAction(Result.updateOneResult);
                        break;
                    }
                case ScriptReaderBase.DELETE_STATEMENT:
                    {
                        current.beginAction(null);
                        Object[] data = scr.getData();
                        scr.getCurrentTable().deleteNoCheckFromLog(current, data);
                        current.endAction(Result.updateOneResult);
                        break;
                    }
                case ScriptReaderBase.SET_SCHEMA_STATEMENT:
                    {
                        current.setSchema(scr.getCurrentSchema());
                    }
            }
            if (current.isClosed()) {
                sessionMap.remove(currentId);
            }
        }
    } catch (Throwable e) {
        String message;
        // catch out-of-memory errors and terminate
        if (e instanceof EOFException) {
        // end of file - normal end
        } else if (e instanceof OutOfMemoryError) {
            message = "out of memory processing " + logFilename + " line: " + scr.getLineNumber();
            database.logger.appLog.logContext(SimpleLog.LOG_ERROR, message);
            throw Error.error(ErrorCode.OUT_OF_MEMORY);
        } else {
            // stop processing on bad log line
            message = logFilename + " line: " + scr.getLineNumber() + " " + e.toString();
            database.logger.appLog.logContext(SimpleLog.LOG_ERROR, message);
        }
    } finally {
        if (scr != null) {
            scr.close();
        }
        database.getSessionManager().closeAllSessions();
        database.setReferentialIntegrity(true);
    }
}
Also used : EOFException(java.io.EOFException) ScriptReaderBase(org.hsqldb_voltpatches.scriptio.ScriptReaderBase) IntKeyHashMap(org.hsqldb_voltpatches.lib.IntKeyHashMap) Session(org.hsqldb_voltpatches.Session) StopWatch(org.hsqldb_voltpatches.lib.StopWatch) Result(org.hsqldb_voltpatches.result.Result)

Example 4 with Session

use of org.hsqldb_voltpatches.Session in project voltdb by VoltDB.

the class DatabaseInformationFull method ROLE_ROUTINE_GRANTS.

Table ROLE_ROUTINE_GRANTS() {
    Table t = sysTables[ROLE_ROUTINE_GRANTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROLE_ROUTINE_GRANTS]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_ROUTINE_GRANTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    Result rs = sys.executeDirectStatement("SELECT GRANTOR, GRANTEE, SPECIFIC_CATALOG, SPECIFIC_SCHEMA, " + "SPECIFIC_NAME, ROUTINE_CATALOG, ROUTINE_SCHEMA, ROUTINE_NAME, " + "PRIVILEGE_TYPE, IS_GRANTABLE, 'NO' " + "FROM INFORMATION_SCHEMA.ROUTINE_PRIVILEGES " + "JOIN INFORMATION_SCHEMA.APPLICABLE_ROLES ON GRANTEE = ROLE_NAME;");
    t.insertSys(store, rs);
    sys.close();
    // Column number mappings
    final int grantor = 0;
    final int grantee = 1;
    final int table_name = 2;
    final int specific_catalog = 3;
    final int specific_schema = 4;
    final int specific_name = 5;
    final int routine_catalog = 6;
    final int routine_schema = 7;
    final int routine_name = 8;
    final int privilege_type = 9;
    final int is_grantable = 10;
    //
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Constraint(org.hsqldb_voltpatches.Constraint) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 5 with Session

use of org.hsqldb_voltpatches.Session in project voltdb by VoltDB.

the class DatabaseInformationFull method SQL_FEATURES.

Table SQL_FEATURES() {
    Table t = sysTables[SQL_FEATURES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SQL_FEATURES]);
        addColumn(t, "FEATURE_ID", CHARACTER_DATA);
        addColumn(t, "FEATURE_NAME", CHARACTER_DATA);
        addColumn(t, "SUB_FEATURE_ID", CHARACTER_DATA);
        addColumn(t, "SUB_FEATURE_NAME", CHARACTER_DATA);
        addColumn(t, "IS_SUPPORTED", YES_OR_NO);
        addColumn(t, "IS_VERIFIED_BY", CHARACTER_DATA);
        addColumn(t, "COMMENTS", CHARACTER_DATA);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_FEATURES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 2 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    String sql = (String) statementMap.get("/*sql_features*/");
    Result rs = sys.executeDirectStatement(sql);
    t.insertSys(store, rs);
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Aggregations

Session (org.hsqldb_voltpatches.Session)24 Result (org.hsqldb_voltpatches.result.Result)18 Table (org.hsqldb_voltpatches.Table)17 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)16 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 TextTable (org.hsqldb_voltpatches.TextTable)15 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 Constraint (org.hsqldb_voltpatches.Constraint)2 HsqlException (org.hsqldb_voltpatches.HsqlException)2 ScriptReaderBase (org.hsqldb_voltpatches.scriptio.ScriptReaderBase)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 SchemaObject (org.hsqldb_voltpatches.SchemaObject)1 Statement (org.hsqldb_voltpatches.Statement)1 DoubleIntIndex (org.hsqldb_voltpatches.lib.DoubleIntIndex)1 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)1