Search in sources :

Example 11 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_PROCEDURECOLUMNS.

/**
     * Retrieves a <code>Table</code> object describing the
     * return, parameter and result columns of the accessible
     * routines defined within this database.<p>
     *
     * Each row is a procedure column description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * PROCEDURE_CAT   VARCHAR   routine catalog
     * PROCEDURE_SCHEM VARCHAR   routine schema
     * PROCEDURE_NAME  VARCHAR   routine name
     * COLUMN_NAME     VARCHAR   column/parameter name
     * COLUMN_TYPE     SMALLINT  kind of column/parameter
     * DATA_TYPE       SMALLINT  SQL type from DITypes
     * TYPE_NAME       VARCHAR   SQL type name
     * PRECISION       INTEGER   precision (length) of type
     * LENGTH          INTEGER   transfer size, in bytes, if definitely known
     *                           (roughly equivalent to BUFFER_SIZE for table
     *                           columns)
     * SCALE           SMALLINT  scale
     * RADIX           SMALLINT  radix
     * NULLABLE        SMALLINT  can column contain NULL?
     * REMARKS         VARCHAR   explanatory comment on column
     * // JDBC 4.0
     * COLUMN_DEF        VARCHAR The default column value.
     *                           The string NULL (not enclosed in quotes)
     *                           - If NULL was specified as the default value
     *                           TRUNCATE (not enclosed in quotes)
     *                           - If the specified default value cannot be
     *                           represented without truncation
     *                           NULL
     *                           - If a default value was not specified
     * SQL_DATA_TYPE     INTEGER CLI type list from SQL 2003 Table 37,
     *                           tables 6-9 Annex A1, and/or addendums in other
     *                           documents, such as:
     *                           SQL 2003 Part 9: Management of External Data (SQL/MED) : DATALINK
     *                           SQL 2003 Part 14: XML-Related Specifications (SQL/XML) : XML
     * SQL_DATETIME_SUB  INTEGER SQL 2003 CLI datetime/interval subcode.
     * CHAR_OCTET_LENGTH INTEGER The maximum length of binary and character
     *                           based columns.  For any other datatype the
     *                           returned value is a NULL
     * ORDINAL_POSITION  INTEGER The ordinal position, starting from 1, for the
     *                           input and output parameters for a procedure.
     *                           A value of 0 is returned if this row describes
     *                           the procedure's return value.
     * IS_NULLABLE       VARCHAR ISO rules are used to determinte the nulliblity
     *                           for a column.
     *
     *                           YES (enclosed in quotes)  --- if the column can include NULLs
     *                           NO  (enclosed in quotes)  --- if the column cannot include NULLs
     *                           empty string              --- if the nullability for the column is unknown
     *
     * SPECIFIC_NAME     VARCHAR The name which uniquely identifies this
     *                           procedure within its schema.
     *                           Typically (but not restricted to) a
     *                           fully qualified Java Method name and
     *                           signature
     * // HSQLDB extension
     * JDBC_SEQ          INTEGER The JDBC-specified order within
     *                           runs of PROCEDURE_SCHEM, PROCEDURE_NAME,
     *                           SPECIFIC_NAME, which is:
     *
     *                           return value (0), if any, first, followed
     *                           by the parameter descriptions in call order
     *                           (1..n1), followed by the result column
     *                           descriptions in column number order
     *                           (n1 + 1..n1 + n2)
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the
     *        return, parameter and result columns
     *        of the accessible routines defined
     *        within this database.
     */
Table SYSTEM_PROCEDURECOLUMNS() {
    Table t = sysTables[SYSTEM_PROCEDURECOLUMNS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_PROCEDURECOLUMNS]);
        // ----------------------------------------------------------------
        // required
        // ----------------------------------------------------------------
        // 0
        addColumn(t, "PROCEDURE_CAT", SQL_IDENTIFIER);
        // 1
        addColumn(t, "PROCEDURE_SCHEM", SQL_IDENTIFIER);
        // not null
        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);
        // 7
        addColumn(t, "PRECISION", Type.SQL_INTEGER);
        // 8
        addColumn(t, "LENGTH", Type.SQL_INTEGER);
        // 9
        addColumn(t, "SCALE", Type.SQL_SMALLINT);
        // 10
        addColumn(t, "RADIX", Type.SQL_SMALLINT);
        // not null
        addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
        // 12
        addColumn(t, "REMARKS", CHARACTER_DATA);
        // ----------------------------------------------------------------
        // JDBC 4.0
        // ----------------------------------------------------------------
        // 13
        addColumn(t, "COLUMN_DEF", CHARACTER_DATA);
        // 14
        addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
        // 15
        addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
        // 16
        addColumn(t, "CHAR_OCTET_LENGTH", Type.SQL_INTEGER);
        // not null
        addColumn(t, "ORDINAL_POSITION", Type.SQL_INTEGER);
        // not null
        addColumn(t, "IS_NULLABLE", CHARACTER_DATA);
        // not null
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        // ----------------------------------------------------------------
        // just for JDBC sort contract
        // ----------------------------------------------------------------
        // not null
        addColumn(t, "JDBC_SEQ", Type.SQL_INTEGER);
        // ----------------------------------------------------------------
        // order: PROCEDURE_SCHEM, PROCEDURE_NAME, SPECIFIC_NAME, SEQ
        // added for unique: PROCEDURE_CAT
        // false PK, as PROCEDURE_SCHEM and/or PROCEDURE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PROCEDURECOLUMNS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 1, 2, 19, 20, 0 }, false);
        return t;
    }
    // calculated column values
    String procedureCatalog;
    String procedureSchema;
    String procedureName;
    String columnName;
    Integer columnType;
    Integer dataType;
    String dataTypeName;
    Integer precision;
    Integer length;
    Integer scale;
    Integer radix;
    Integer nullability;
    String remark;
    // JDBC 4.0
    String colDefault;
    Integer sqlDataType;
    Integer sqlDateTimeSub;
    Integer charOctetLength;
    Integer ordinalPosition;
    String isNullable;
    String specificName;
    // extended
    int jdbcSequence;
    // intermediate holders
    int colCount;
    HsqlArrayList aliasList;
    Object[] info;
    Method method;
    Iterator methods;
    Object[] row;
    DITypeInfo ti;
    // Initialization
    // and aliases
    methods = ns.iterateAllAccessibleMethods(session, true);
    ti = new DITypeInfo();
    // no such thing as identity or ignorecase return/parameter
    // procedure columns.  Future: may need to worry about this if
    // result columns are ever reported
    ti.setTypeSub(Types.TYPE_SUB_DEFAULT);
    // JDBC 4.0
    /**
         * @todo we do not yet support declarative p-column defaults.
         * In essence, the default value for a procedure column is NULL
         */
    colDefault = null;
    procedureCatalog = database.getCatalogName().name;
    procedureSchema = database.schemaManager.getDefaultSchemaHsqlName().name;
    // Do it.
    while (methods.hasNext()) {
        info = (Object[]) methods.next();
        method = (Method) info[0];
        aliasList = (HsqlArrayList) info[1];
        pi.setMethod(method);
        specificName = pi.getSpecificName();
        procedureName = pi.getFQN();
        colCount = pi.getColCount();
        for (int i = 0; i < colCount; i++) {
            ti.setTypeCode(pi.getColTypeCode(i));
            columnName = pi.getColName(i);
            columnType = pi.getColUsage(i);
            dataType = pi.getColJDBCDataType(i);
            dataTypeName = ti.getTypeName();
            precision = ti.getPrecision();
            length = pi.getColLen(i);
            scale = ti.getDefaultScale();
            radix = ti.getNumPrecRadix();
            nullability = pi.getColNullability(i);
            remark = pi.getColRemark(i);
            // JDBC 4.0
            //colDefault    = null;
            sqlDataType = ti.getSqlDataType();
            sqlDateTimeSub = ti.getSqlDateTimeSub();
            charOctetLength = ti.getCharOctLen();
            ordinalPosition = pi.getColOrdinalPosition(i);
            isNullable = pi.getColIsNullable(i);
            // extended
            jdbcSequence = pi.getColSequence(i);
            addPColRows(t, aliasList, procedureCatalog, procedureSchema, procedureName, columnName, columnType, dataType, dataTypeName, precision, length, scale, radix, nullability, remark, colDefault, sqlDataType, sqlDateTimeSub, charOctetLength, ordinalPosition, isNullable, specificName, jdbcSequence);
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Method(java.lang.reflect.Method) Constraint(org.hsqldb_voltpatches.Constraint)

Example 12 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class UserManager method getInitialSchemaSQL.

public String[] getInitialSchemaSQL() {
    HsqlArrayList list = new HsqlArrayList(userList.size());
    for (int i = 0; i < userList.size(); i++) {
        User user = (User) userList.get(i);
        if (user.isSystem) {
            continue;
        }
        HsqlName name = user.getInitialSchema();
        if (name == null) {
            continue;
        }
        list.add(user.getInitialSchemaSQL());
    }
    String[] array = new String[list.size()];
    list.toArray(array);
    return array;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 13 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class UserManager method listVisibleUsers.

/**
     * Retrieves the <code>User</code> objects representing the database
     * users that are visible to the <code>User</code> object
     * represented by the <code>session</code> argument. <p>
     *
     * If the <code>session</code> argument's <code>User</code> object
     * attribute has isAdmin() true (directly or by virtue of a Role),
     * then all of the
     * <code>User</code> objects in this collection are considered visible.
     * Otherwise, only this object's special <code>PUBLIC</code>
     * <code>User</code> object attribute and the session <code>User</code>
     * object, if it exists in this collection, are considered visible. <p>
     *
     * @param session The <code>Session</code> object used to determine
     *          visibility
     * @return a list of <code>User</code> objects visible to
     *          the <code>User</code> object contained by the
     *         <code>session</code> argument.
     *
     */
public HsqlArrayList listVisibleUsers(Session session) {
    HsqlArrayList list;
    User user;
    boolean isAdmin;
    String sessionName;
    String userName;
    list = new HsqlArrayList();
    isAdmin = session.isAdmin();
    sessionName = session.getUsername();
    if (userList == null || userList.size() == 0) {
        return list;
    }
    for (int i = 0; i < userList.size(); i++) {
        user = (User) userList.get(i);
        if (user == null) {
            continue;
        }
        userName = user.getNameString();
        if (isAdmin) {
            list.add(user);
        } else if (sessionName.equals(userName)) {
            list.add(user);
        }
    }
    return list;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList)

Example 14 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class Right method getTableRightsArray.

/**
     * Used solely by org.hsqldb_voltpatches.dbinfo in existing system tables lacking column
     * level reporting.<p>
     *
     * Returns names of individual rights instead of ALL
     */
String[] getTableRightsArray() {
    if (isFull) {
        return new String[] { Tokens.T_SELECT, Tokens.T_INSERT, Tokens.T_UPDATE, Tokens.T_DELETE, Tokens.T_REFERENCES };
    }
    HsqlArrayList list = new HsqlArrayList();
    String[] array = new String[list.size()];
    if (isFullSelect) {
        list.add(Tokens.T_SELECT);
    }
    if (isFullInsert) {
        list.add(Tokens.T_INSERT);
    }
    if (isFullUpdate) {
        list.add(Tokens.T_UPDATE);
    }
    if (isFullDelete) {
        list.add(Tokens.T_DELETE);
    }
    if (isFullReferences) {
        list.add(Tokens.T_REFERENCES);
    }
    if (isFullTrigger) {
        list.add(Tokens.T_TRIGGER);
    }
    list.toArray(array);
    return array;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList)

Example 15 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.

the class Expression method resolveTableColumns.

// A VoltDB extension to support indexed expressions
private void resolveTableColumns(Table table) {
    HsqlList set = new HsqlArrayList();
    collectAllColumnExpressions(set);
    for (int i = 0; i < set.size(); i++) {
        ExpressionColumn array_element = (ExpressionColumn) set.get(i);
        ColumnSchema column = table.getColumn(table.getColumnIndex(array_element.getAlias()));
        array_element.setAttributesAsColumn(column, false);
    }
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Aggregations

HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)69 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)21 Iterator (org.hsqldb_voltpatches.lib.Iterator)14 HsqlList (org.hsqldb_voltpatches.lib.HsqlList)11 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)10 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)10 Table (org.hsqldb_voltpatches.Table)7 Type (org.hsqldb_voltpatches.types.Type)6 SchemaObject (org.hsqldb_voltpatches.SchemaObject)5 Method (java.lang.reflect.Method)4 Constraint (org.hsqldb_voltpatches.Constraint)3 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)3 Grantee (org.hsqldb_voltpatches.rights.Grantee)3 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)2 Result (org.hsqldb_voltpatches.result.Result)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)1 NumberSequence (org.hsqldb_voltpatches.NumberSequence)1