Search in sources :

Example 6 with Session

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

the class DatabaseInformationFull method ROLE_USAGE_GRANTS.

Table ROLE_USAGE_GRANTS() {
    Table t = sysTables[ROLE_USAGE_GRANTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROLE_USAGE_GRANTS]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        addColumn(t, "OBJECT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "OBJECT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "OBJECT_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "OBJECT_TYPE", CHARACTER_DATA);
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_USAGE_GRANTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, 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, OBJECT_CATALOG, OBJECT_SCHEMA, OBJECT_NAME, " + "OBJECT_TYPE, PRIVILEGE_TYPE, IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.USAGE_PRIVILEGES " + "JOIN INFORMATION_SCHEMA.APPLICABLE_ROLES ON GRANTEE = ROLE_NAME;");
    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 7 with Session

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

the class DatabaseInformationFull method COLUMN_DOMAIN_USAGE.

/**
     * Domains are shown if the authorization is the user or a role given to the
     * user.
     *
     * <p>
     *
     * @return Table
     */
Table COLUMN_DOMAIN_USAGE() {
    Table t = sysTables[COLUMN_DOMAIN_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMN_DOMAIN_USAGE]);
        addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_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_DOMAIN_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 DOMAIN_CATALOG, DOMAIN_SCHEMA, DOMAIN_NAME, TABLE_CATALOG, " + "TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE DOMAIN_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 8 with Session

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

the class DatabaseInformationFull method SYSTEM_SESSIONS.

/**
     * Retrieves a <code>Table</code> object describing all visible
     * sessions. ADMIN users see *all* sessions
     * while non-admin users see only their own session.<p>
     *
     * Each row is a session state description with the following columns: <p>
     *
     * <pre class="SqlCodeExample">
     * SESSION_ID         INTEGER   session identifier
     * CONNECTED          TIMESTAMP time at which session was created
     * USER_NAME          VARCHAR   db user name of current session user
     * IS_ADMIN           BOOLEAN   is session user an admin user?
     * AUTOCOMMIT         BOOLEAN   is session in autocommit mode?
     * READONLY           BOOLEAN   is session in read-only mode?
     * MAXROWS            INTEGER   session's MAXROWS setting
     * LAST_IDENTITY      INTEGER   last identity value used by this session
     * TRANSACTION_SIZE   INTEGER   # of undo items in current transaction
     * SCHEMA             VARCHAR   current schema for session
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing all visible
     *      sessions
     */
Table SYSTEM_SESSIONS() {
    Table t = sysTables[SYSTEM_SESSIONS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_SESSIONS]);
        addColumn(t, "SESSION_ID", CARDINAL_NUMBER);
        addColumn(t, "CONNECTED", TIME_STAMP);
        addColumn(t, "USER_NAME", SQL_IDENTIFIER);
        addColumn(t, "IS_ADMIN", Type.SQL_BOOLEAN);
        addColumn(t, "AUTOCOMMIT", Type.SQL_BOOLEAN);
        addColumn(t, "READONLY", Type.SQL_BOOLEAN);
        addColumn(t, "MAXROWS", CARDINAL_NUMBER);
        // Note: some sessions may have a NULL LAST_IDENTITY value
        addColumn(t, "LAST_IDENTITY", CARDINAL_NUMBER);
        addColumn(t, "TRANSACTION_SIZE", CARDINAL_NUMBER);
        addColumn(t, "SCHEMA", SQL_IDENTIFIER);
        // order:  SESSION_ID
        // true primary key
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_SESSIONS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    // column number mappings
    final int isid = 0;
    final int ict = 1;
    final int iuname = 2;
    final int iis_admin = 3;
    final int iautocmt = 4;
    final int ireadonly = 5;
    final int imaxrows = 6;
    final int ilast_id = 7;
    final int it_size = 8;
    final int it_schema = 9;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // intermediate holders
    Session[] sessions;
    Session s;
    Object[] row;
    // Initialisation
    sessions = ns.listVisibleSessions(session);
    // Do it.
    for (int i = 0; i < sessions.length; i++) {
        s = sessions[i];
        row = t.getEmptyRowData();
        row[isid] = ValuePool.getLong(s.getId());
        row[ict] = new TimestampData(s.getConnectTime() / 1000);
        row[iuname] = s.getUsername();
        row[iis_admin] = ValuePool.getBoolean(s.isAdmin());
        row[iautocmt] = ValuePool.getBoolean(s.isAutoCommit());
        row[ireadonly] = ValuePool.getBoolean(s.isReadOnlyDefault());
        row[imaxrows] = ValuePool.getInt(s.getSQLMaxRows());
        row[ilast_id] = ValuePool.getLong(((Number) s.getLastIdentity()).longValue());
        row[it_size] = ValuePool.getInt(s.getTransactionSize());
        row[it_schema] = s.getCurrentSchemaHsqlName().name;
        t.insertSys(store, row);
    }
    return t;
}
Also used : TimestampData(org.hsqldb_voltpatches.types.TimestampData) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) Session(org.hsqldb_voltpatches.Session)

Example 9 with Session

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

the class DataFileDefrag method writeTableToDataFile.

int[] writeTableToDataFile(Table table) throws IOException {
    Session session = database.getSessionManager().getSysSession();
    PersistentStore store = session.sessionData.getRowStore(table);
    RowOutputInterface rowOut = new RowOutputBinary();
    DoubleIntIndex pointerLookup = new DoubleIntIndex(table.getPrimaryIndex().sizeEstimate(store), false);
    int[] rootsArray = table.getIndexRootsArray();
    long pos = fileOffset;
    int count = 0;
    pointerLookup.setKeysSearchTarget();
    Error.printSystemOut("lookup begins: " + stopw.elapsedTime());
    RowIterator it = table.rowIterator(session);
    for (; it.hasNext(); count++) {
        CachedObject row = it.getNextRow();
        pointerLookup.addUnsorted(row.getPos(), (int) (pos / scale));
        if (count % 50000 == 0) {
            Error.printSystemOut("pointer pair for row " + count + " " + row.getPos() + " " + pos);
        }
        pos += row.getStorageSize();
    }
    Error.printSystemOut(table.getName().name + " list done ", stopw.elapsedTime());
    count = 0;
    it = table.rowIterator(session);
    for (; it.hasNext(); count++) {
        CachedObject row = it.getNextRow();
        rowOut.reset();
        row.write(rowOut, pointerLookup);
        fileStreamOut.write(rowOut.getOutputStream().getBuffer(), 0, rowOut.size());
        fileOffset += row.getStorageSize();
        if ((count) % 50000 == 0) {
            Error.printSystemOut(count + " rows " + stopw.elapsedTime());
        }
    }
    for (int i = 0; i < rootsArray.length; i++) {
        if (rootsArray[i] == -1) {
            continue;
        }
        int lookupIndex = pointerLookup.findFirstEqualKeyIndex(rootsArray[i]);
        if (lookupIndex == -1) {
            throw Error.error(ErrorCode.DATA_FILE_ERROR);
        }
        rootsArray[i] = pointerLookup.getValue(lookupIndex);
    }
    setTransactionRowLookups(pointerLookup);
    Error.printSystemOut(table.getName().name + " : table converted");
    return rootsArray;
}
Also used : RowOutputInterface(org.hsqldb_voltpatches.rowio.RowOutputInterface) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) DoubleIntIndex(org.hsqldb_voltpatches.lib.DoubleIntIndex) RowOutputBinary(org.hsqldb_voltpatches.rowio.RowOutputBinary) Session(org.hsqldb_voltpatches.Session)

Example 10 with Session

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

the class LobManager method createSchema.

public void createSchema() {
    sysLobSession = database.sessionManager.getSysLobSession();
    Session session = sysLobSession;
    InputStream fis = getClass().getResourceAsStream(resourceFileName);
    InputStreamReader reader = null;
    try {
        reader = new InputStreamReader(fis, "ISO-8859-1");
    } catch (Exception e) {
    }
    LineNumberReader lineReader = new LineNumberReader(reader);
    LineGroupReader lg = new LineGroupReader(lineReader, starters);
    HashMappedList map = lg.getAsMap();
    lg.close();
    String sql = (String) map.get("/*lob_schema_definition*/");
    Statement statement = session.compileStatement(sql);
    Result result = statement.execute(session);
    Table table = database.schemaManager.getTable(session, "BLOCKS", "SYSTEM_LOBS");
    //            table.isTransactional = false;
    getLob = session.compileStatement(getLobSQL);
    getLobPart = session.compileStatement(getLobPartSQL);
    createLob = session.compileStatement(createLobSQL);
    createLobPart = session.compileStatement(createLobPartSQL);
    divideLobPart = session.compileStatement(divideLobPartSQL);
    deleteLob = session.compileStatement(deleteLobSQL);
    deleteLobPart = session.compileStatement(deleteLobPartSQL);
    setLobLength = session.compileStatement(updateLobLengthSQL);
    setLobUsage = session.compileStatement(updateLobUsageSQL);
    getNextLobId = session.compileStatement(getNextLobIdSQL);
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) Table(org.hsqldb_voltpatches.Table) InputStreamReader(java.io.InputStreamReader) LineGroupReader(org.hsqldb_voltpatches.lib.LineGroupReader) HsqlByteArrayInputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayInputStream) InputStream(java.io.InputStream) Statement(org.hsqldb_voltpatches.Statement) IOException(java.io.IOException) EOFException(java.io.EOFException) HsqlException(org.hsqldb_voltpatches.HsqlException) Session(org.hsqldb_voltpatches.Session) LineNumberReader(java.io.LineNumberReader) 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