Search in sources :

Example 76 with Table

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

the class DatabaseInformationFull method CHECK_CONSTRAINTS.

/**
     * The CHECK_CONSTRAINTS view has one row for each domain
     * constraint, table check constraint, and assertion. <p>
     *
     * <b>Definition:</b><p>
     *
     * <pre class="SqlCodeExample">
     *      CONSTRAINT_CATALOG  VARCHAR NULL,
     *      CONSTRAINT_SCHEMA   VARCHAR NULL,
     *      CONSTRAINT_NAME     VARCHAR NOT NULL,
     *      CHECK_CLAUSE        VARCHAR NOT NULL,
     * </pre>
     *
     * <b>Description:</b><p>
     *
     * <ol>
     * <li> A constraint is shown in this view if the authorization for the
     *      schema that contains the constraint is the current user or is a role
     *      assigned to the current user. <p>
     *
     * <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA and
     *      CONSTRAINT_NAME are the catalog name, unqualified schema name,
     *      and qualified identifier, respectively, of the constraint being
     *      described. <p>
     *
     * <li> Case: <p>
     *
     *      <table>
     *          <tr>
     *               <td valign="top" halign="left">a)</td>
     *               <td> If the character representation of the
     *                    &lt;search condition&gt; contained in the
     *                    &lt;check constraint definition&gt;,
     *                    &lt;domain constraint definition&gt;, or
     *                    &lt;assertion definition&gt; that defined
     *                    the check constraint being described can be
     *                    represented without truncation, then the
     *                    value of CHECK_CLAUSE is that character
     *                    representation. </td>
     *          </tr>
     *          <tr>
     *              <td align="top" halign="left">b)</td>
     *              <td>Otherwise, the value of CHECK_CLAUSE is the
     *                  null value.</td>
     *          </tr>
     *      </table>
     * </ol>
     *
     * @return Table
     */
Table CHECK_CONSTRAINTS() {
    Table t = sysTables[CHECK_CONSTRAINTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[CHECK_CONSTRAINTS]);
        addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "CHECK_CLAUSE", CHARACTER_DATA);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CHECK_CONSTRAINTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 2, 1, 0 }, false);
        return t;
    }
    // column number mappings
    final int constraint_catalog = 0;
    final int constraint_schema = 1;
    final int constraint_name = 2;
    final int check_clause = 3;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    // Intermediate holders
    Iterator tables;
    Table table;
    Constraint[] tableConstraints;
    int constraintCount;
    Constraint constraint;
    Object[] row;
    //
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (table.isView() || !session.getGrantee().isFullyAccessibleByRole(table)) {
            continue;
        }
        tableConstraints = table.getConstraints();
        constraintCount = tableConstraints.length;
        for (int i = 0; i < constraintCount; i++) {
            constraint = tableConstraints[i];
            if (constraint.getConstraintType() != Constraint.CHECK) {
                continue;
            }
            row = t.getEmptyRowData();
            row[constraint_catalog] = database.getCatalogName().name;
            row[constraint_schema] = table.getSchemaName().name;
            row[constraint_name] = constraint.getName().name;
            try {
                row[check_clause] = constraint.getCheckSQL();
            } catch (Exception e) {
            }
            t.insertSys(store, row);
        }
    }
    Iterator it = database.schemaManager.databaseObjectIterator(SchemaObject.DOMAIN);
    while (it.hasNext()) {
        Type domain = (Type) it.next();
        if (!domain.isDomainType()) {
            continue;
        }
        if (!session.getGrantee().isFullyAccessibleByRole(domain)) {
            continue;
        }
        tableConstraints = domain.userTypeModifier.getConstraints();
        constraintCount = tableConstraints.length;
        for (int i = 0; i < constraintCount; i++) {
            constraint = tableConstraints[i];
            row = t.getEmptyRowData();
            row[constraint_catalog] = database.getCatalogName().name;
            row[constraint_schema] = domain.getSchemaName().name;
            row[constraint_name] = constraint.getName().name;
            try {
                row[check_clause] = constraint.getCheckSQL();
            } catch (Exception e) {
            }
            t.insertSys(store, row);
        }
    }
    return t;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) CharacterType(org.hsqldb_voltpatches.types.CharacterType) NumberType(org.hsqldb_voltpatches.types.NumberType) IntervalType(org.hsqldb_voltpatches.types.IntervalType) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Constraint(org.hsqldb_voltpatches.Constraint) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 77 with Table

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

the class DataFileDefrag method process.

void process() throws IOException {
    boolean complete = false;
    Error.printSystemOut("Defrag Transfer begins");
    transactionRowLookup = database.txManager.getTransactionIDList();
    HsqlArrayList allTables = database.schemaManager.getAllTables();
    rootsList = new int[allTables.size()][];
    Storage dest = null;
    try {
        OutputStream fos = database.getFileAccess().openOutputStreamElement(filename + ".new");
        fileStreamOut = new BufferedOutputStream(fos, 1 << 12);
        for (int i = 0; i < DataFileCache.INITIAL_FREE_POS; i++) {
            fileStreamOut.write(0);
        }
        fileOffset = DataFileCache.INITIAL_FREE_POS;
        for (int i = 0, tSize = allTables.size(); i < tSize; i++) {
            Table t = (Table) allTables.get(i);
            if (t.getTableType() == TableBase.CACHED_TABLE) {
                int[] rootsArray = writeTableToDataFile(t);
                rootsList[i] = rootsArray;
            } else {
                rootsList[i] = null;
            }
            Error.printSystemOut(t.getName().name + " complete");
        }
        writeTransactionRows();
        fileStreamOut.flush();
        fileStreamOut.close();
        fileStreamOut = null;
        // write out the end of file position
        dest = ScaledRAFile.newScaledRAFile(database, filename + ".new", false, ScaledRAFile.DATA_FILE_RAF, database.getURLProperties().getProperty("storage_class_name"), database.getURLProperties().getProperty("storage_key"));
        dest.seek(DataFileCache.LONG_FREE_POS_POS);
        dest.writeLong(fileOffset);
        dest.close();
        dest = null;
        for (int i = 0, size = rootsList.length; i < size; i++) {
            int[] roots = rootsList[i];
            if (roots != null) {
                Error.printSystemOut(org.hsqldb_voltpatches.lib.StringUtil.getList(roots, ",", ""));
            }
        }
        complete = true;
    } catch (IOException e) {
        throw Error.error(ErrorCode.FILE_IO_ERROR, filename + ".new");
    } catch (OutOfMemoryError e) {
        throw Error.error(ErrorCode.OUT_OF_MEMORY);
    } finally {
        if (fileStreamOut != null) {
            fileStreamOut.close();
        }
        if (dest != null) {
            dest.close();
        }
        if (!complete) {
            database.getFileAccess().removeElement(filename + ".new");
        }
    }
//Error.printSystemOut("Transfer complete: ", stopw.elapsedTime());
}
Also used : Storage(org.hsqldb_voltpatches.lib.Storage) Table(org.hsqldb_voltpatches.Table) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 78 with Table

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

the class Grantee method getRightsSQL.

public HsqlArrayList getRightsSQL() {
    HsqlArrayList list = new HsqlArrayList();
    String roleString = getDirectRolesAsString();
    if (roleString.length() != 0) {
        list.add("GRANT " + roleString + " TO " + getStatementName());
    }
    MultiValueHashMap rightsMap = getRights();
    Iterator dbObjects = rightsMap.keySet().iterator();
    while (dbObjects.hasNext()) {
        Object nameObject = dbObjects.next();
        Iterator rights = rightsMap.get(nameObject);
        while (rights.hasNext()) {
            Right right = (Right) rights.next();
            StringBuffer sb = new StringBuffer(128);
            HsqlName hsqlname = (HsqlName) nameObject;
            switch(hsqlname.type) {
                case SchemaObject.TABLE:
                case SchemaObject.VIEW:
                    Table table = granteeManager.database.schemaManager.findUserTable(null, hsqlname.name, hsqlname.schema.name);
                    if (table != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(right.getTableRightsSQL(table));
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("TABLE ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
                case SchemaObject.SEQUENCE:
                    NumberSequence sequence = (NumberSequence) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.SEQUENCE);
                    if (sequence != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(Tokens.T_USAGE);
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("SEQUENCE ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
                case SchemaObject.DOMAIN:
                    Type domain = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
                    if (domain != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(Tokens.T_USAGE);
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("DOMAIN ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
                case SchemaObject.TYPE:
                    Type type = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
                    if (type != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(Tokens.T_USAGE);
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("TYPE ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
            }
            if (sb.length() == 0) {
                continue;
            }
            sb.append(' ').append(Tokens.T_TO).append(' ');
            sb.append(getStatementName());
            list.add(sb.toString());
        }
    }
    return list;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Table(org.hsqldb_voltpatches.Table) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) NumberSequence(org.hsqldb_voltpatches.NumberSequence) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) MultiValueHashMap(org.hsqldb_voltpatches.lib.MultiValueHashMap)

Example 79 with Table

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

the class ScriptWriterBase method writeExistingData.

protected void writeExistingData() throws IOException {
    // start with blank schema - SET SCHEMA to log
    currentSession.loggedSchema = null;
    Iterator schemas = database.schemaManager.allSchemaNameIterator();
    while (schemas.hasNext()) {
        String schema = (String) schemas.next();
        Iterator tables = database.schemaManager.databaseObjectIterator(schema, SchemaObject.TABLE);
        while (tables.hasNext()) {
            Table t = (Table) tables.next();
            // write all memory table data
            // write cached table data unless index roots have been written
            // write all text table data apart from readonly text tables
            // unless index roots have been written
            boolean script = false;
            switch(t.getTableType()) {
                case TableBase.MEMORY_TABLE:
                    script = true;
                    break;
                case TableBase.CACHED_TABLE:
                    script = includeCachedData;
                    break;
                case TableBase.TEXT_TABLE:
                    script = includeCachedData && !t.isReadOnly();
                    break;
            }
            try {
                if (script) {
                    schemaToLog = t.getName().schema;
                    writeTableInit(t);
                    RowIterator it = t.rowIterator(currentSession);
                    while (it.hasNext()) {
                        writeRow(currentSession, t, it.getNextRow().getData());
                    }
                    writeTableTerm(t);
                }
            } catch (Exception e) {
                throw Error.error(ErrorCode.FILE_IO_ERROR, e.toString());
            }
        }
    }
    writeDataTerm();
}
Also used : Table(org.hsqldb_voltpatches.Table) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Iterator(org.hsqldb_voltpatches.lib.Iterator) IOException(java.io.IOException)

Example 80 with Table

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

the class ScriptReaderBinary method readExistingData.

protected void readExistingData(Session session) throws IOException {
    for (; ; ) {
        String s = readTableInit();
        if (s == null) {
            break;
        }
        String schema = session.getSchemaName(currentSchema);
        Table t = db.schemaManager.getUserTable(session, s, schema);
        PersistentStore store = db.persistentStoreCollection.getStore(t);
        int j = 0;
        for (j = 0; ; j++) {
            if (!readRow(store, t)) {
                break;
            }
        }
        int checkCount = readTableTerm();
        if (j != checkCount) {
            throw Error.error(ErrorCode.ERROR_IN_SCRIPT_FILE, ErrorCode.M_ERROR_IN_BINARY_SCRIPT_1, new Object[] { s, new Integer(j), new Integer(checkCount) });
        }
    }
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Aggregations

Table (org.hsqldb_voltpatches.Table)94 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)74 TextTable (org.hsqldb_voltpatches.TextTable)65 Constraint (org.hsqldb_voltpatches.Constraint)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Iterator (org.hsqldb_voltpatches.lib.Iterator)55 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)54 HsqlException (org.hsqldb_voltpatches.HsqlException)20 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)19 Session (org.hsqldb_voltpatches.Session)17 Result (org.hsqldb_voltpatches.result.Result)14 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Type (org.hsqldb_voltpatches.types.Type)9 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6