Search in sources :

Example 1 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class ExpressionLogical method getAllAnyValue.

/** @todo - null value in rows */
private Boolean getAllAnyValue(Session session, Object[] data, SubQuery subquery) {
    Table table = subquery.getTable();
    boolean empty = table.isEmpty(session);
    Index index = table.getFullIndex();
    RowIterator it;
    Row firstrow;
    PersistentStore store = session.sessionData.getRowStore(table);
    Row lastrow = index.lastRow(session, store);
    Object[] lastdata;
    Object[] firstdata;
    switch(exprSubType) {
        case OpTypes.ANY_QUANTIFIED:
            {
                if (empty) {
                    return Boolean.FALSE;
                }
                if (countNulls(data) == data.length) {
                    return null;
                }
                lastdata = lastrow.getData();
                if (countNulls(lastdata) == data.length) {
                    return null;
                }
                convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
                if (opType == OpTypes.EQUAL) {
                    it = index.findFirstRow(session, store, data);
                    return it.hasNext() ? Boolean.TRUE : Boolean.FALSE;
                }
                it = index.findFirstRowNotNull(session, store);
                firstrow = it.getNextRow();
                firstdata = firstrow.getData();
                Boolean comparefirst = compareValues(session, data, firstdata);
                Boolean comparelast = compareValues(session, data, lastdata);
                switch(opType) {
                    case OpTypes.NOT_EQUAL:
                        return Boolean.TRUE.equals(comparefirst) || Boolean.TRUE.equals(comparelast) ? Boolean.TRUE : Boolean.FALSE;
                    case OpTypes.GREATER:
                        return comparefirst;
                    case OpTypes.GREATER_EQUAL:
                        return comparefirst;
                    case OpTypes.SMALLER:
                        return comparelast;
                    case OpTypes.SMALLER_EQUAL:
                        return comparelast;
                }
                break;
            }
        case OpTypes.ALL_QUANTIFIED:
            {
                if (empty) {
                    return Boolean.TRUE;
                }
                if (countNulls(data) == data.length) {
                    return null;
                }
                it = index.firstRow(session, store);
                firstrow = it.getNextRow();
                firstdata = firstrow.getData();
                if (countNulls(firstdata) == data.length) {
                    return null;
                }
                convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
                it = index.findFirstRow(session, store, data);
                if (opType == OpTypes.EQUAL) {
                    if (it.hasNext()) {
                        return subquery.getTable().getRowCount(store) == 1 ? Boolean.TRUE : Boolean.FALSE;
                    } else {
                        return Boolean.FALSE;
                    }
                }
                if (opType == OpTypes.NOT_EQUAL) {
                    return it.hasNext() ? Boolean.FALSE : Boolean.TRUE;
                }
                lastdata = lastrow.getData();
                Boolean comparefirst = compareValues(session, data, firstdata);
                Boolean comparelast = compareValues(session, data, lastdata);
                switch(opType) {
                    case OpTypes.GREATER:
                        return comparelast;
                    case OpTypes.GREATER_EQUAL:
                        return comparelast;
                    case OpTypes.SMALLER:
                        return comparefirst;
                    case OpTypes.SMALLER_EQUAL:
                        return comparefirst;
                }
                break;
            }
    }
    return null;
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Index(org.hsqldb_voltpatches.index.Index)

Example 2 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore 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 3 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method SCHEMATA.

/**
     * SCHEMATA<p>
     *
     * <b>Function</b><p>
     *
     * The SCHEMATA view has one row for each accessible schema. <p>
     *
     * <b>Definition</b><p>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE SCHEMATA (
     *      CATALOG_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
     *      SCHEMA_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
     *      SCHEMA_OWNER INFORMATION_SCHEMA.SQL_IDENTIFIER
     *          CONSTRAINT SCHEMA_OWNER_NOT_NULL
     *              NOT NULL,
     *      DEFAULT_CHARACTER_SET_CATALOG INFORMATION_SCHEMA.SQL_IDENTIFIER
     *          CONSTRAINT DEFAULT_CHARACTER_SET_CATALOG_NOT_NULL
     *              NOT NULL,
     *      DEFAULT_CHARACTER_SET_SCHEMA INFORMATION_SCHEMA.SQL_IDENTIFIER
     *          CONSTRAINT DEFAULT_CHARACTER_SET_SCHEMA_NOT_NULL
     *              NOT NULL,
     *      DEFAULT_CHARACTER_SET_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER
     *          CONSTRAINT DEFAULT_CHARACTER_SET_NAME_NOT_NULL
     *              NOT NULL,
     *      SQL_PATH INFORMATION_SCHEMA.CHARACTER_DATA,
     *
     *      CONSTRAINT SCHEMATA_PRIMARY_KEY
     *          PRIMARY KEY ( CATALOG_NAME, SCHEMA_NAME ),
     *      CONSTRAINT SCHEMATA_FOREIGN_KEY_AUTHORIZATIONS
     *          FOREIGN KEY ( SCHEMA_OWNER )
     *              REFERENCES AUTHORIZATIONS,
     *      CONSTRAINT SCHEMATA_FOREIGN_KEY_CATALOG_NAMES
     *          FOREIGN KEY ( CATALOG_NAME )
     *              REFERENCES CATALOG_NAMES
     *      )
     * </pre>
     *
     * <b>Description</b><p>
     *
     * <ol>
     *      <li>The value of CATALOG_NAME is the name of the catalog of the
     *          schema described by this row.<p>
     *
     *      <li>The value of SCHEMA_NAME is the unqualified schema name of
     *          the schema described by this row.<p>
     *
     *      <li>The values of SCHEMA_OWNER are the authorization identifiers
     *          that own the schemata.<p>
     *
     *      <li>The values of DEFAULT_CHARACTER_SET_CATALOG,
     *          DEFAULT_CHARACTER_SET_SCHEMA, and DEFAULT_CHARACTER_SET_NAME
     *          are the catalog name, unqualified schema name, and qualified
     *          identifier, respectively, of the default character set for
     *          columns and domains in the schemata.<p>
     *
     *      <li>Case:<p>
     *          <ul>
     *              <li>If &lt;schema path specification&gt; was specified in
     *                  the &lt;schema definition&gt; that defined the schema
     *                  described by this row and the character representation
     *                  of the &lt;schema path specification&gt; can be
     *                  represented without truncation, then the value of
     *                  SQL_PATH is that character representation.<p>
     *
     *              <li>Otherwise, the value of SQL_PATH is the null value.
     *         </ul>
     * </ol>
     *
     * @return Table
     */
Table SCHEMATA() {
    Table t = sysTables[SCHEMATA];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SCHEMATA]);
        addColumn(t, "CATALOG_NAME", SQL_IDENTIFIER);
        addColumn(t, "SCHEMA_NAME", SQL_IDENTIFIER);
        addColumn(t, "SCHEMA_OWNER", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "SQL_PATH", CHARACTER_DATA);
        // order: CATALOG_NAME, SCHEMA_NAME
        // false PK, as rows may have NULL CATALOG_NAME
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SCHEMATA].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // Intermediate holders
    Iterator schemas;
    String schema;
    String dcsSchema = SqlInvariants.INFORMATION_SCHEMA;
    String dcsName = ValuePool.getString("UTF16");
    String sqlPath = null;
    Grantee user = session.getGrantee();
    Object[] row;
    // column number mappings
    final int schema_catalog = 0;
    final int schema_name = 1;
    final int schema_owner = 2;
    final int default_character_set_catalog = 3;
    final int default_character_set_schema = 4;
    final int default_character_set_name = 5;
    final int sql_path = 6;
    // Initialization
    schemas = database.schemaManager.fullSchemaNamesIterator();
    // Do it.
    while (schemas.hasNext()) {
        schema = (String) schemas.next();
        if (!user.hasSchemaUpdateOrGrantRights(schema)) {
            continue;
        }
        row = t.getEmptyRowData();
        row[schema_catalog] = database.getCatalogName().name;
        row[schema_name] = schema;
        row[schema_owner] = database.schemaManager.toSchemaOwner(schema).getNameString();
        row[default_character_set_catalog] = database.getCatalogName().name;
        row[default_character_set_schema] = dcsSchema;
        row[default_character_set_name] = dcsName;
        row[sql_path] = sqlPath;
        t.insertSys(store, row);
    }
    return t;
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) 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)

Example 4 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method ROLE_AUTHORIZATION_DESCRIPTORS.

//------------------------------------------------------------------------------
// SQL SCHEMATA BASE TABLES
/**
     * ROLE_AUTHORIZATION_DESCRIPTORS<p>
     *
     * <b>Function</b><p>
     *
     * Contains a representation of the role authorization descriptors.<p>
     * <b>Definition</b>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE ROLE_AUTHORIZATION_DESCRIPTORS (
     *      ROLE_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
     *      GRANTEE INFORMATION_SCHEMA.SQL_IDENTIFIER,
     *      GRANTOR INFORMATION_SCHEMA.SQL_IDENTIFIER,
     *      IS_GRANTABLE INFORMATION_SCHEMA.CHARACTER_DATA
     *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_IS_GRANTABLE_CHECK
     *              CHECK ( IS_GRANTABLE IN
     *                  ( 'YES', 'NO' ) ),
     *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_PRIMARY_KEY
     *              PRIMARY KEY ( ROLE_NAME, GRANTEE ),
     *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_CHECK_ROLE_NAME
     *              CHECK ( ROLE_NAME IN
     *                  ( SELECT AUTHORIZATION_NAME
     *                      FROM AUTHORIZATIONS
     *                     WHERE AUTHORIZATION_TYPE = 'ROLE' ) ),
     *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTOR
     *              FOREIGN KEY ( GRANTOR )
     *                  REFERENCES AUTHORIZATIONS,
     *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTEE
     *              FOREIGN KEY ( GRANTEE )
     *                  REFERENCES AUTHORIZATIONS
     *      )
     * </pre>
     *
     * <b>Description</b><p>
     *
     * <ol>
     *      <li>The value of ROLE_NAME is the &lt;role name&gt; of some
     *          &lt;role granted&gt; by the &lt;grant role statement&gt; or
     *          the &lt;role name&gt; of a &lt;role definition&gt;. <p>
     *
     *      <li>The value of GRANTEE is an &lt;authorization identifier&gt;,
     *          possibly PUBLIC, or &lt;role name&gt; specified as a
     *          &lt;grantee&gt; contained in a &lt;grant role statement&gt;,
     *          or the &lt;authorization identifier&gt; of the current
     *          SQLsession when the &lt;role definition&gt; is executed. <p>
     *
     *      <li>The value of GRANTOR is the &lt;authorization identifier&gt;
     *          of the user or role who granted the role identified by
     *          ROLE_NAME to the user or role identified by the value of
     *          GRANTEE. <p>
     *
     *      <li>The values of IS_GRANTABLE have the following meanings:<p>
     *
     *      <table border cellpadding="3">
     *          <tr>
     *              <td nowrap>YES</td>
     *              <td nowrap>The described role is grantable.</td>
     *          <tr>
     *          <tr>
     *              <td nowrap>NO</td>
     *              <td nowrap>The described role is not grantable.</td>
     *          <tr>
     *      </table> <p>
     * </ol>
     *
     * @return Table
     */
Table ROLE_AUTHORIZATION_DESCRIPTORS() {
    Table t = sysTables[ROLE_AUTHORIZATION_DESCRIPTORS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROLE_AUTHORIZATION_DESCRIPTORS]);
        // not null
        addColumn(t, "ROLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_AUTHORIZATION_DESCRIPTORS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // Intermediate holders
    String grantorName = SqlInvariants.SYSTEM_AUTHORIZATION_NAME;
    Iterator grantees;
    Grantee granteeObject;
    String granteeName;
    Iterator roles;
    String roleName;
    String isGrantable;
    Object[] row;
    // Column number mappings
    final int role_name = 0;
    final int grantee = 1;
    final int grantor = 2;
    final int is_grantable = 3;
    // Initialization
    grantees = session.getGrantee().visibleGrantees().iterator();
    //
    while (grantees.hasNext()) {
        granteeObject = (Grantee) grantees.next();
        granteeName = granteeObject.getNameString();
        roles = granteeObject.getDirectRoles().iterator();
        isGrantable = granteeObject.isAdmin() ? Tokens.T_YES : Tokens.T_NO;
        ;
        while (roles.hasNext()) {
            Grantee role = (Grantee) roles.next();
            row = t.getEmptyRowData();
            row[role_name] = role.getNameString();
            row[grantee] = granteeName;
            row[grantor] = grantorName;
            row[is_grantable] = isGrantable;
            t.insertSys(store, row);
        }
    }
    return t;
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) 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)

Example 5 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method CONSTRAINT_COLUMN_USAGE.

/**
     * The CONSTRAINT_COLUMN_USAGE view has one row for each column identified by
     * a table constraint or assertion.<p>
     *
     * <b>Definition:</b><p>
     *
     *      TABLE_CATALOG       VARCHAR
     *      TABLE_SCHEMA        VARCHAR
     *      TABLE_NAME          VARCHAR
     *      COLUMN_NAME         VARCHAR
     *      CONSTRAINT_CATALOG  VARCHAR
     *      CONSTRAINT_SCHEMA   VARCHAR
     *      CONSTRAINT_NAME     VARCHAR
     *
     * </pre>
     *
     * <b>Description:</b> <p>
     *
     * <ol>
     * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
     *      COLUMN_NAME are the catalog name, unqualified schema name,
     *      qualified identifier, and column name, respectively, of a column
     *      identified by a &lt;column reference&gt; explicitly or implicitly
     *      contained in the &lt;search condition&gt; of the constraint
     *      being described.
     *
     * <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>
     *
     * </ol>
     *
     * @return Table
     */
Table CONSTRAINT_COLUMN_USAGE() {
    Table t = sysTables[CONSTRAINT_COLUMN_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[CONSTRAINT_COLUMN_USAGE]);
        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);
        addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CONSTRAINT_COLUMN_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6 }, false);
        return t;
    }
    // column number mappings
    final int table_catalog = 0;
    final int table_schems = 1;
    final int table_name = 2;
    final int column_name = 3;
    final int constraint_catalog = 4;
    final int constraint_schema = 5;
    final int constraint_name = 6;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String constraintCatalog;
    String constraintSchema;
    String constraintName;
    // Intermediate holders
    Iterator tables;
    Table table;
    Constraint[] constraints;
    int constraintCount;
    Constraint constraint;
    Iterator iterator;
    Object[] row;
    // Initialization
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (table.isView() || !session.getGrantee().isFullyAccessibleByRole(table)) {
            continue;
        }
        constraints = table.getConstraints();
        constraintCount = constraints.length;
        constraintCatalog = database.getCatalogName().name;
        constraintSchema = table.getSchemaName().name;
        // process constraints
        for (int i = 0; i < constraintCount; i++) {
            constraint = constraints[i];
            constraintName = constraint.getName().name;
            switch(constraint.getConstraintType()) {
                case Constraint.CHECK:
                    {
                        OrderedHashSet expressions = constraint.getCheckColumnExpressions();
                        if (expressions == null) {
                            break;
                        }
                        iterator = expressions.iterator();
                        // calculate distinct column references
                        while (iterator.hasNext()) {
                            ExpressionColumn expr = (ExpressionColumn) iterator.next();
                            HsqlName name = expr.getBaseColumnHsqlName();
                            if (name.type != SchemaObject.COLUMN) {
                                continue;
                            }
                            row = t.getEmptyRowData();
                            row[table_catalog] = database.getCatalogName().name;
                            row[table_schems] = name.schema.name;
                            row[table_name] = name.parent.name;
                            row[column_name] = name.name;
                            row[constraint_catalog] = constraintCatalog;
                            row[constraint_schema] = constraintSchema;
                            row[constraint_name] = constraintName;
                            try {
                                t.insertSys(store, row);
                            } catch (HsqlException e) {
                            }
                        }
                        break;
                    }
                case Constraint.UNIQUE:
                case Constraint.PRIMARY_KEY:
                case Constraint.FOREIGN_KEY:
                    {
                        Table target = table;
                        int[] cols = constraint.getMainColumns();
                        if (constraint.getConstraintType() == Constraint.FOREIGN_KEY) {
                            target = constraint.getMain();
                        }
                        /*
                       checkme - it seems foreign key columns are not included
                       but columns of the referenced unique constraint are included

                        if (constraint.getType() == Constraint.FOREIGN_KEY) {
                            for (int j = 0; j < cols.length; j++) {
                                row = t.getEmptyRowData();

                                Table mainTable = constraint.getMain();

                                row[table_catalog] = database.getCatalog();
                                row[table_schems] =
                                    mainTable.getSchemaName().name;
                                row[table_name] = mainTable.getName().name;
                                row[column_name] = mainTable.getColumn(
                                    cols[j]).columnName.name;
                                row[constraint_catalog] = constraintCatalog;
                                row[constraint_schema]  = constraintSchema;
                                row[constraint_name]    = constraintName;

                                try {
                                    t.insertSys(row);
                                } catch (HsqlException e) {}
                            }

                            cols = constraint.getRefColumns();
                        }
*/
                        for (int j = 0; j < cols.length; j++) {
                            row = t.getEmptyRowData();
                            row[table_catalog] = database.getCatalogName().name;
                            row[table_schems] = constraintSchema;
                            row[table_name] = target.getName().name;
                            row[column_name] = target.getColumn(cols[j]).getName().name;
                            row[constraint_catalog] = constraintCatalog;
                            row[constraint_schema] = constraintSchema;
                            row[constraint_name] = constraintName;
                            try {
                                t.insertSys(store, row);
                            } catch (HsqlException e) {
                            }
                        }
                    //
                    }
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Constraint(org.hsqldb_voltpatches.Constraint) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Constraint(org.hsqldb_voltpatches.Constraint) ExpressionColumn(org.hsqldb_voltpatches.ExpressionColumn) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlException(org.hsqldb_voltpatches.HsqlException)

Aggregations

PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)103 Table (org.hsqldb_voltpatches.Table)74 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)73 SchemaObject (org.hsqldb_voltpatches.SchemaObject)59 Constraint (org.hsqldb_voltpatches.Constraint)57 TextTable (org.hsqldb_voltpatches.TextTable)56 Iterator (org.hsqldb_voltpatches.lib.Iterator)51 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)51 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)20 HsqlException (org.hsqldb_voltpatches.HsqlException)19 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)16 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Type (org.hsqldb_voltpatches.types.Type)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 CachedObject (org.hsqldb_voltpatches.persist.CachedObject)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6