Package org.hsqldb

Examples of org.hsqldb.Table$RowStore


     *        primary key columns of each accessible table
     *        defined within this database.
     */
    final Table SYSTEM_PRIMARYKEYS(Session session) {

        Table t = sysTables[SYSTEM_PRIMARYKEYS];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_PRIMARYKEYS]);

            addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
            addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
            addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);     // not null
            addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);    // not null
            addColumn(t, "KEY_SEQ", Type.SQL_SMALLINT);     // not null
            addColumn(t, "PK_NAME", SQL_IDENTIFIER);

            // order: COLUMN_NAME
            // added for unique: TABLE_NAME, TABLE_SCHEM, TABLE_CAT
            // false PK, as  TABLE_SCHEM and/or TABLE_CAT may be null
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_PRIMARYKEYS].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[] {
                3, 2, 1, 0
            }, false);

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);

        // calculated column values
        String tableCatalog;
        String tableSchema;
        String tableName;

        //String  columnName;
        //Integer keySequence;
        String primaryKeyName;

        // Intermediate holders
        Iterator       tables;
        Table          table;
        Object[]       row;
        Constraint     constraint;
        int[]          cols;
        int            colCount;
        HsqlProperties p;

        // column number mappings
        final int itable_cat   = 0;
        final int itable_schem = 1;
        final int itable_name  = 2;
        final int icolumn_name = 3;
        final int ikey_seq     = 4;
        final int ipk_name     = 5;

        // Initialization
        p = database.getProperties();
        tables =
            database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);

        while (tables.hasNext()) {
            table = (Table) tables.next();

            if (table.isView() || !isAccessibleTable(session, table)
                    || !table.hasPrimaryKey()) {
                continue;
            }

            constraint     = table.getPrimaryConstraint();
            tableCatalog   = table.getCatalogName().name;
            tableSchema    = table.getSchemaName().name;
            tableName      = table.getName().name;
            primaryKeyName = constraint.getName().name;
            cols           = constraint.getMainColumns();
            colCount       = cols.length;

            for (int j = 0; j < colCount; j++) {
                row               = t.getEmptyRowData();
                row[itable_cat]   = tableCatalog;
                row[itable_schem] = tableSchema;
                row[itable_name= tableName;
                row[icolumn_name] = table.getColumn(cols[j]).getName().name;
                row[ikey_seq]     = ValuePool.getInt(j + 1);
                row[ipk_name]     = primaryKeyName;

                t.insertSys(store, row);
            }
View Full Code Here


     *        of the accessible routines defined
     *        within this database.
     */
    Table SYSTEM_PROCEDURECOLUMNS(Session session) {

        Table t = sysTables[SYSTEM_PROCEDURECOLUMNS];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_PROCEDURECOLUMNS]);

            // ----------------------------------------------------------------
            // required
            // ----------------------------------------------------------------
            addColumn(t, "PROCEDURE_CAT", SQL_IDENTIFIER);          // 0
            addColumn(t, "PROCEDURE_SCHEM", SQL_IDENTIFIER);        // 1
            addColumn(t, "PROCEDURE_NAME", SQL_IDENTIFIER);         // not null
            addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);            // not null
            addColumn(t, "COLUMN_TYPE", Type.SQL_SMALLINT);         // not null
            addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);           // not null
            addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);              // not null
            addColumn(t, "PRECISION", Type.SQL_INTEGER);            // 7
            addColumn(t, "LENGTH", Type.SQL_INTEGER);               // 8
            addColumn(t, "SCALE", Type.SQL_SMALLINT);               // 9
            addColumn(t, "RADIX", Type.SQL_SMALLINT);               // 10
            addColumn(t, "NULLABLE", Type.SQL_SMALLINT);            // not null
            addColumn(t, "REMARKS", CHARACTER_DATA);                // 12

            // ----------------------------------------------------------------
            // JDBC 4.0
            // ----------------------------------------------------------------
            addColumn(t, "COLUMN_DEF", CHARACTER_DATA);             // 13
            addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);        // 14
            addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);     // 15
            addColumn(t, "CHAR_OCTET_LENGTH", Type.SQL_INTEGER);    // 16
            addColumn(t, "ORDINAL_POSITION", Type.SQL_INTEGER);     // 17
            addColumn(t, "IS_NULLABLE", CHARACTER_DATA);            // 18
            addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);          // 19

            // order: PROCEDURE_SCHEM, PROCEDURE_NAME, SPECIFIC_NAME, ORDINAL_POSITION
            //
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_PROCEDURECOLUMNS].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[] {
                0, 1, 2, 19, 17
            }, false);

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);

        // column number mappings
        final int specific_cat            = 0;
        final int specific_schem          = 1;
        final int procedure_name          = 2;
        final int parameter_name          = 3;
        final int parameter_mode          = 4;
        final int data_type_sql_id        = 5;
        final int data_type               = 6;
        final int numeric_precision       = 7;
        final int byte_length             = 8;
        final int numeric_scale           = 9;
        final int numeric_precision_radix = 10;
        final int nullable                = 11;
        final int remark                  = 12;
        final int default_val             = 13;
        final int sql_data_type           = 14;
        final int sql_datetime_sub        = 15;
        final int character_octet_length  = 16;
        final int ordinal_position        = 17;
        final int is_nullable             = 18;
        final int specific_name           = 19;

        // intermediate holders
        int           columnCount;
        Iterator      routines;
        RoutineSchema routineSchema;
        Routine       routine;
        Object[]      row;
        Type          type;

        // Initialization
        boolean translateDTI = database.getProperties().isPropertyTrue(
            HsqlDatabaseProperties.jdbc_translate_dti_types);

        routines = database.schemaManager.databaseObjectIterator(
            SchemaObject.ROUTINE);

        while (routines.hasNext()) {
            routineSchema = (RoutineSchema) routines.next();

            if (!session.getGrantee().isAccessible(routineSchema)) {
                continue;
            }

            Routine[] specifics = routineSchema.getSpecificRoutines();

            for (int i = 0; i < specifics.length; i++) {
                routine     = specifics[i];
                columnCount = routine.getParameterCount();

                for (int j = 0; j < columnCount; j++) {
                    ColumnSchema column = routine.getParameter(j);

                    row  = t.getEmptyRowData();
                    type = column.getDataType();

                    if (translateDTI) {
                        if (type.isIntervalType()) {
                            type = CharacterType.getCharacterType(
                                Types.SQL_VARCHAR, type.displaySize());
                        } else if (type.isDateTimeTypeWithZone()) {
                            type = ((DateTimeType) type)
                                .getDateTimeTypeWithoutZone();
                        }
                    }

                    row[specific_cat]     = database.getCatalogName().name;
                    row[specific_schem]   = routine.getSchemaName().name;
                    row[specific_name]    = routine.getSpecificName().name;
                    row[procedure_name]   = routine.getName().name;
                    row[parameter_name]   = column.getName().name;
                    row[ordinal_position] = ValuePool.getInt(j + 1);
                    row[parameter_mode] =
                        ValuePool.getInt(column.getParameterMode());
                    row[data_type] = type.getFullNameString();
                    row[data_type_sql_id] =
                        ValuePool.getInt(type.getJDBCTypeCode());
                    row[numeric_precision]      = ValuePool.INTEGER_0;
                    row[character_octet_length] = ValuePool.INTEGER_0;

                    if (type.isCharacterType()) {
                        row[numeric_precision] =
                            ValuePool.getInt(type.getJDBCPrecision());

                        // this is length not octet_length, for character columns
                        row[character_octet_length] =
                            ValuePool.getInt(type.getJDBCPrecision());
                    }

                    if (type.isBinaryType()) {
                        row[numeric_precision] =
                            ValuePool.getInt(type.getJDBCPrecision());
                        row[character_octet_length] =
                            ValuePool.getInt(type.getJDBCPrecision());
                    }

                    if (type.isNumberType()) {
                        row[numeric_precision] = ValuePool.getInt(
                            ((NumberType) type).getNumericPrecisionInRadix());
                        row[numeric_precision_radix] =
                            ValuePool.getLong(type.getPrecisionRadix());

                        if (type.isExactNumberType()) {
                            row[numeric_scale] = ValuePool.getLong(type.scale);
                        }
                    }

                    if (type.isDateTimeType()) {
                        int size = (int) column.getDataType().displaySize();

                        row[numeric_precision] = ValuePool.getInt(size);
                    }

                    row[sql_data_type] =
                        ValuePool.getInt(column.getDataType().typeCode);
                    row[nullable] = ValuePool.getInt(column.getNullability());
                    row[is_nullable] = column.isNullable() ? "YES"
                                                           : "NO";

                    t.insertSys(store, row);
                }
            }
        }

        return t;
View Full Code Here

     * @return a <code>Table</code> object describing the accessible
     *        routines defined within the this database
     */
    Table SYSTEM_PROCEDURES(Session session) {

        Table t = sysTables[SYSTEM_PROCEDURES];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_PROCEDURES]);

            // ----------------------------------------------------------------
            // required
            // ----------------------------------------------------------------
            addColumn(t, "PROCEDURE_CAT", SQL_IDENTIFIER);        // 0
            addColumn(t, "PROCEDURE_SCHEM", SQL_IDENTIFIER);      // 1
            addColumn(t, "PROCEDURE_NAME", SQL_IDENTIFIER);       // 2
            addColumn(t, "COL_4", Type.SQL_INTEGER);              // 3
            addColumn(t, "COL_5", Type.SQL_INTEGER);              // 4
            addColumn(t, "COL_6", Type.SQL_INTEGER);              // 5
            addColumn(t, "REMARKS", CHARACTER_DATA);              // 6

            // basically: function (returns result), procedure (no return value)
            // or unknown (say, a trigger callout routine)
            addColumn(t, "PROCEDURE_TYPE", Type.SQL_SMALLINT);    // 7

            // ----------------------------------------------------------------
            // JDBC 4.0
            // ----------------------------------------------------------------
            addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);        // 8

            // ----------------------------------------------------------------
            // order: PROCEDURE_CAT, PROCEDURE_SCHEM, PROCEDURE_NAME, SPECIFIC_NAME
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_PROCEDURES].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[] {
                0, 1, 2, 8
            }, false);

            return t;
        }

        //
        final int procedure_catalog = 0;
        final int procedure_schema  = 1;
        final int procedure_name    = 2;
        final int col_4             = 3;
        final int col_5             = 4;
        final int col_6             = 5;
        final int remarks           = 6;
        final int procedure_type    = 7;
        final int specific_name     = 8;

        //
        PersistentStore store = session.sessionData.getRowStore(t);

        //
        Iterator it = database.schemaManager.databaseObjectIterator(
            SchemaObject.SPECIFIC_ROUTINE);

        while (it.hasNext()) {
            Routine  routine = (Routine) it.next();
            Object[] row     = t.getEmptyRowData();

            row[procedure_catalog] = row[procedure_catalog] =
                database.getCatalogName().name;
            row[procedure_schema] = routine.getSchemaName().name;
            row[procedure_name]   = routine.getName().name;
            row[procedure_type] = routine.isProcedure() ? ValuePool.INTEGER_1
                                                        : ValuePool.INTEGER_2;
            row[specific_name]    = routine.getSpecificName().name;

            t.insertSys(store, row);
        }

        return t;
    }
View Full Code Here

     *                                                  contain information as to where this property is
     *                                                  stored in the database.
     */
    final Table SYSTEM_CONNECTION_PROPERTIES(Session session) {

        Table t = sysTables[SYSTEM_CONNECTION_PROPERTIES];

        if (t == null) {
            t = createBlankTable(
                sysTableHsqlNames[SYSTEM_CONNECTION_PROPERTIES]);

            addColumn(t, "NAME", SQL_IDENTIFIER);
            addColumn(t, "MAX_LEN", Type.SQL_INTEGER);
            addColumn(t, "DEFAULT_VALUE", SQL_IDENTIFIER);    // not null
            addColumn(t, "DESCRIPTION", SQL_IDENTIFIER);      // not null

            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_PRIMARYKEYS].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[]{ 0 }, true);

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);
        Object[]        row;

        // column number mappings
        final int iname          = 0;
        final int imax_len       = 1;
        final int idefault_value = 2;
        final int idescription   = 3;
        Iterator  it = HsqlDatabaseProperties.getPropertiesMetaIterator();

        while (it.hasNext()) {
            Object[] meta = (Object[]) it.next();
            int propType =
                ((Integer) meta[HsqlProperties.indexType]).intValue();

            if (propType == HsqlDatabaseProperties.FILE_PROPERTY) {
                if (HsqlDatabaseProperties.hsqldb_readonly.equals(
                        meta[HsqlProperties.indexName]) || HsqlDatabaseProperties
                            .hsqldb_files_readonly.equals(
                                meta[HsqlProperties.indexName])) {}
                else {
                    continue;
                }
            } else if (propType != HsqlDatabaseProperties.SQL_PROPERTY) {
                continue;
            }

            row = t.getEmptyRowData();

            Object def = meta[HsqlProperties.indexDefaultValue];

            row[iname]          = meta[HsqlProperties.indexName];
            row[imax_len]       = ValuePool.getInt(8);
            row[idefault_value] = def == null ? null
                                              : def.toString();
            row[idescription]   = "see HyperSQL guide";

            t.insertSys(store, row);
        }

        return t;
    }
View Full Code Here

     * @return table containing information about schemas defined
     *      within this database
     */
    final Table SYSTEM_SCHEMAS(Session session) {

        Table t = sysTables[SYSTEM_SCHEMAS];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_SCHEMAS]);

            addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);    // not null
            addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
            addColumn(t, "IS_DEFAULT", Type.SQL_BOOLEAN);

            // order: TABLE_SCHEM
            // true PK, as rows never have null TABLE_SCHEM
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_SCHEMAS].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[]{ 0 }, true);

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);
        Iterator        schemas;
        Object[]        row;

        // Initialization
        schemas = database.schemaManager.fullSchemaNamesIterator();

        String defschema =
            database.schemaManager.getDefaultSchemaHsqlName().name;

        // Do it.
        while (schemas.hasNext()) {
            row = t.getEmptyRowData();

            String schema = (String) schemas.next();

            row[0] = schema;
            row[1] = database.getCatalogName().name;
            row[2] = schema.equals(defschema) ? Boolean.TRUE
                                              : Boolean.FALSE;

            t.insertSys(store, row);
        }

        return t;
    }
View Full Code Here

     * @return a <code>Table</code> object describing the accessible
     *      tables defined within this database
     */
    final Table SYSTEM_TABLES(Session session) {

        Table t = sysTables[SYSTEM_TABLES];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_TABLES]);

            // -------------------------------------------------------------
            // required
            // -------------------------------------------------------------
            addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
            addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
            addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);       // not null
            addColumn(t, "TABLE_TYPE", CHARACTER_DATA);       // not null
            addColumn(t, "REMARKS", CHARACTER_DATA);

            // -------------------------------------------------------------
            // JDBC 3.0
            // -------------------------------------------------------------
            addColumn(t, "TYPE_CAT", SQL_IDENTIFIER);
            addColumn(t, "TYPE_SCHEM", SQL_IDENTIFIER);
            addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
            addColumn(t, "SELF_REFERENCING_COL_NAME", SQL_IDENTIFIER);
            addColumn(t, "REF_GENERATION", CHARACTER_DATA);

            // -------------------------------------------------------------
            // extended
            // ------------------------------------------------------------
            addColumn(t, "HSQLDB_TYPE", SQL_IDENTIFIER);
            addColumn(t, "READ_ONLY", Type.SQL_BOOLEAN);      // not null
            addColumn(t, "COMMIT_ACTION", CHARACTER_DATA);    // not null

            // ------------------------------------------------------------
            // order TABLE_TYPE, TABLE_SCHEM and TABLE_NAME
            // added for unique: TABLE_CAT
            // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_TABLES].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[] {
                3, 1, 2, 0
            }, false);

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);

        // intermediate holders
        Iterator    tables;
        Table       table;
        Object[]    row;
        HsqlName    accessKey;
        DITableInfo ti;

        // column number mappings
        // JDBC 1
        final int itable_cat   = 0;
        final int itable_schem = 1;
        final int itable_name  = 2;
        final int itable_type  = 3;
        final int iremark      = 4;

        // JDBC 3.0
        final int itype_cat   = 5;
        final int itype_schem = 6;
        final int itype_name  = 7;
        final int isref_cname = 8;
        final int iref_gen    = 9;

        // hsqldb ext
        final int ihsqldb_type   = 10;
        final int iread_only     = 11;
        final int icommit_action = 12;

        // Initialization
        tables = allTables();
        ti     = new DITableInfo();

        // Do it.
        while (tables.hasNext()) {
            table = (Table) tables.next();

            if (!isAccessibleTable(session, table)) {
                continue;
            }

            ti.setTable(table);

            row               = t.getEmptyRowData();
            row[itable_cat]   = database.getCatalogName().name;
            row[itable_schem] = table.getSchemaName().name;
            row[itable_name= table.getName().name;
            row[itable_type= ti.getJDBCStandardType();
            row[iremark]      = ti.getRemark();
            row[ihsqldb_type] = ti.getHsqlType();
            row[iread_only]   = table.isDataReadOnly() ? Boolean.TRUE
                                                       : Boolean.FALSE;
            row[icommit_action] = table.isTemp()
                                  ? (table.onCommitPreserve() ? "PRESERVE"
                                                              : "DELETE")
                                  : null;

            t.insertSys(store, row);
        }
View Full Code Here

     * @return a <code>Table</code> object describing the table types
     *        available in this database
     */
    Table SYSTEM_TABLETYPES(Session session) {

        Table t = sysTables[SYSTEM_TABLETYPES];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_TABLETYPES]);

            addColumn(t, "TABLE_TYPE", SQL_IDENTIFIER);    // not null

            // order: TABLE_TYPE
            // true PK
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_TABLETYPES].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[]{ 0 }, true);

            return t;
        }

        PersistentStore store = session.sessionData.getRowStore(t);
        Object[]        row;

        for (int i = 0; i < tableTypes.length; i++) {
            row    = t.getEmptyRowData();
            row[0] = tableTypes[i];

            t.insertSys(store, row);
        }

        return t;
    }
View Full Code Here

     * @return a <code>Table</code> object describing the
     *      system-defined SQL types supported as table columns
     */
    final Table SYSTEM_TYPEINFO(Session session) {

        Table t = sysTables[SYSTEM_TYPEINFO];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_TYPEINFO]);

            //-------------------------------------------
            // required by JDBC:
            // ------------------------------------------
            addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
            addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
            addColumn(t, "PRECISION", Type.SQL_INTEGER);
            addColumn(t, "LITERAL_PREFIX", CHARACTER_DATA);
            addColumn(t, "LITERAL_SUFFIX", CHARACTER_DATA);
            addColumn(t, "CREATE_PARAMS", CHARACTER_DATA);
            addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
            addColumn(t, "CASE_SENSITIVE", Type.SQL_BOOLEAN);
            addColumn(t, "SEARCHABLE", Type.SQL_INTEGER);
            addColumn(t, "UNSIGNED_ATTRIBUTE", Type.SQL_BOOLEAN);
            addColumn(t, "FIXED_PREC_SCALE", Type.SQL_BOOLEAN);
            addColumn(t, "AUTO_INCREMENT", Type.SQL_BOOLEAN);
            addColumn(t, "LOCAL_TYPE_NAME", SQL_IDENTIFIER);
            addColumn(t, "MINIMUM_SCALE", Type.SQL_SMALLINT);
            addColumn(t, "MAXIMUM_SCALE", Type.SQL_SMALLINT);
            addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
            addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
            addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);

            //-------------------------------------------
            // SQL CLI / ODBC - not in JDBC spec
            // ------------------------------------------
            addColumn(t, "INTERVAL_PRECISION", Type.SQL_INTEGER);

            // order:  DATA_TYPE, TYPE_NAME
            // true primary key
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_TYPEINFO].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, new int[] {
                1, 0
            }, true);

            return t;
        }

        //-----------------------------------------
        // Same as SYSTEM_TYPEINFO
        //-----------------------------------------
        final int itype_name          = 0;
        final int idata_type          = 1;
        final int iprecision          = 2;
        final int iliteral_prefix     = 3;
        final int iliteral_suffix     = 4;
        final int icreate_params      = 5;
        final int inullable           = 6;
        final int icase_sensitive     = 7;
        final int isearchable         = 8;
        final int iunsigned_attribute = 9;
        final int ifixed_prec_scale   = 10;
        final int iauto_increment     = 11;
        final int ilocal_type_name    = 12;
        final int iminimum_scale      = 13;
        final int imaximum_scale      = 14;
        final int isql_data_type      = 15;
        final int isql_datetime_sub   = 16;
        final int inum_prec_radix     = 17;

        //------------------------------------------
        // Extensions
        //------------------------------------------
        // not in JDBC, but in SQL CLI SQLDA / ODBC
        //------------------------------------------
        final int       iinterval_precision = 18;
        PersistentStore store = session.sessionData.getRowStore(t);
        Object[]        row;
        Iterator        it = Type.typeNames.keySet().iterator();
        boolean translateDTI = database.getProperties().isPropertyTrue(
            HsqlDatabaseProperties.jdbc_translate_dti_types);

        while (it.hasNext()) {
            String typeName = (String) it.next();
            int    typeCode = Type.typeNames.get(typeName);
            Type   type     = Type.getDefaultType(typeCode);

            if (type == null) {
                continue;
            }

            if (translateDTI) {
                if (type.isIntervalType()) {
                    type = CharacterType.getCharacterType(Types.SQL_VARCHAR,
                                                          type.displaySize());
                } else if (type.isDateTimeTypeWithZone()) {
                    type = ((DateTimeType) type).getDateTimeTypeWithoutZone();
                }
            }

            row             = t.getEmptyRowData();
            row[itype_name] = typeName;
            row[idata_type] = ValuePool.getInt(type.getJDBCTypeCode());

            long maxPrecision = type.getMaxPrecision();

            row[iprecision] = maxPrecision > Integer.MAX_VALUE
                              ? ValuePool.INTEGER_MAX
                              : ValuePool.getInt((int) maxPrecision);

            if (type.isBinaryType() || type.isCharacterType()
                    || type.isDateTimeType() || type.isIntervalType()) {
                row[iliteral_prefix] = "\'";
                row[iliteral_suffix] = "\'";
            }

            if (type.acceptsPrecision() && type.acceptsScale()) {
                row[icreate_params] = "PRECISION,SCALE";
            } else if (type.acceptsPrecision()) {
                row[icreate_params] = type.isNumberType() ? "PRECISION"
                                                          : "LENGTH";
            } else if (type.acceptsScale()) {
                row[icreate_params] = "SCALE";
            }

            row[inullable] = ValuePool.INTEGER_1;
            row[icase_sensitive] =
                type.isCharacterType()
                && type.typeCode != Types.VARCHAR_IGNORECASE ? Boolean.TRUE
                                                             : Boolean.FALSE;

            if (type.isLobType()) {
                row[isearchable] = ValuePool.INTEGER_0;
            } else if (type.isCharacterType()
                       || (type.isBinaryType() && !type.isBitType())) {
                row[isearchable] = ValuePool.getInt(3);
            } else {
                row[isearchable] = ValuePool.getInt(2);
            }

            row[iunsigned_attribute] = Boolean.FALSE;
            row[ifixed_prec_scale] =
                type.typeCode == Types.SQL_NUMERIC
                || type.typeCode == Types.SQL_DECIMAL ? Boolean.TRUE
                                                      : Boolean.FALSE;
            row[iauto_increment]   = type.isIntegralType() ? Boolean.TRUE
                                                           : Boolean.FALSE;
            row[ilocal_type_name= null;
            row[iminimum_scale]    = ValuePool.INTEGER_0;
            row[imaximum_scale]    = ValuePool.getInt(type.getMaxScale());
            row[isql_data_type]    = null;
            row[isql_datetime_sub] = null;
            row[inum_prec_radix] = ValuePool.getInt(type.getPrecisionRadix());

            //------------------------------------------
            if (type.isIntervalType()) {
                row[iinterval_precision] = null;
            }

            t.insertSys(store, row);
        }

        row             = t.getEmptyRowData();
        row[itype_name] = "DISTINCT";
        row[idata_type] = ValuePool.getInt(Types.DISTINCT);

        return t;
    }
View Full Code Here

     * @return a <code>Table</code> object describing the accessible
     *      user-defined types defined in this database
     */
    Table SYSTEM_UDTS(Session session) {

        Table t = sysTables[SYSTEM_UDTS];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_UDTS]);

            addColumn(t, "TYPE_CAT", SQL_IDENTIFIER);
            addColumn(t, "TYPE_SCHEM", SQL_IDENTIFIER);
            addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
            addColumn(t, "CLASS_NAME", CHARACTER_DATA);
            addColumn(t, "DATA_TYPE", Type.SQL_INTEGER);
            addColumn(t, "REMARKS", CHARACTER_DATA);
            addColumn(t, "BASE_TYPE", Type.SQL_SMALLINT);

            //
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_UDTS].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, null, false);

            return t;
        }

        boolean translateDTI = database.getProperties().isPropertyTrue(
            HsqlDatabaseProperties.jdbc_translate_dti_types);
        PersistentStore store = session.sessionData.getRowStore(t);

        // column number mappings
        final int type_catalog = 0;
        final int type_schema  = 1;
        final int type_name    = 2;
        final int class_name   = 3;
        final int data_type    = 4;
        final int remarks      = 5;
        final int base_type    = 6;
        Iterator it =
            database.schemaManager.databaseObjectIterator(SchemaObject.TYPE);

        while (it.hasNext()) {
            Type distinct = (Type) it.next();

            if (!distinct.isDistinctType()) {
                continue;
            }

            Object[] data = t.getEmptyRowData();
            Type     type = distinct;

            if (translateDTI) {
                if (type.isIntervalType()) {
                    type = CharacterType.getCharacterType(Types.SQL_VARCHAR,
                                                          type.displaySize());
                } else if (type.isDateTimeTypeWithZone()) {
                    type = ((DateTimeType) type).getDateTimeTypeWithoutZone();
                }
            }

            data[type_catalog] = database.getCatalogName().name;
            data[type_schema= distinct.getSchemaName().name;
            data[type_name]    = distinct.getName().name;
            data[class_name]   = type.getJDBCClassName();
            data[data_type]    = ValuePool.getInt(Types.DISTINCT);
            data[remarks]      = null;
            data[base_type]    = ValuePool.getInt(type.getJDBCTypeCode());

            t.insertSys(store, data);
        }

        return t;
    }
View Full Code Here

     *        that are automatically updated when any value
     *        in a row is updated
     */
    Table SYSTEM_VERSIONCOLUMNS(Session session) {

        Table t = sysTables[SYSTEM_VERSIONCOLUMNS];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[SYSTEM_VERSIONCOLUMNS]);

            // ----------------------------------------------------------------
            // required by DatabaseMetaData.getVersionColumns result set
            // ----------------------------------------------------------------
            addColumn(t, "SCOPE", Type.SQL_INTEGER);
            addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);         // not null
            addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);        // not null
            addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);           // not null
            addColumn(t, "COLUMN_SIZE", Type.SQL_SMALLINT);
            addColumn(t, "BUFFER_LENGTH", Type.SQL_INTEGER);
            addColumn(t, "DECIMAL_DIGITS", Type.SQL_SMALLINT);
            addColumn(t, "PSEUDO_COLUMN", Type.SQL_SMALLINT);    // not null

            // -----------------------------------------------------------------
            // required by DatabaseMetaData.getVersionColumns filter parameters
            // -----------------------------------------------------------------
            addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
            addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
            addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);          // not null

            // -----------------------------------------------------------------
            HsqlName name = HsqlNameManager.newInfoSchemaObjectName(
                sysTableHsqlNames[SYSTEM_VERSIONCOLUMNS].name, false,
                SchemaObject.INDEX);

            t.createPrimaryKeyConstraint(name, null, false);

            return t;
        }

        return t;
View Full Code Here

TOP

Related Classes of org.hsqldb.Table$RowStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.