⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rowutil.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * <p>     *	 * @return The new row.     *     * @param format_ids an array of format id's, one per column in row.     *	 * @exception  StandardException  Standard exception policy.     **/    public static InstanceGetter[] newClassInfoTemplate(    FormatableBitSet column_list,    int[]    format_ids)         throws StandardException    {        int         num_cols = format_ids.length;        InstanceGetter[] ret_row  = new InstanceGetter[num_cols];		int column_listSize =             (column_list == null) ? 0 : column_list.getLength();        for (int i = 0; i < num_cols; i++)        {            // does caller want this column?            if ((column_list != null)   &&                 !((column_listSize > i) &&                 (column_list.isSet(i))))            {                // no - column should be skipped.            }            else            {                // yes - create the column                 // get empty instance of object identified by the format id.                ret_row[i] = Monitor.classFromIdentifier(format_ids[i]);            }        }        return(ret_row);    }    private static void newRowFromClassInfoTemplateError()    {        if (SanityManager.DEBUG)            SanityManager.THROWASSERT(                "unexpected error in newRowFromClassInfoTemplate()");    }    /**     * Generate an "empty" row from an array of classInfo objects.     * <p>     * Generate an array of new'd objects by using the getNewInstance()     * method on each of the InstanceGetter objects.  It is more     * efficient to allocate new objects based on this "cache'd"     * InstanceGetter object than to call the Monitor to generate a new class     * from a format id.     * <p>     *	 * @return The new row.     *     * @param classinfo_template   An array of InstanceGetter objects each of      *                             which can be used to create a new instance      *                             of the appropriate type to build a new empty     *                             template row.     *	 * @exception  StandardException  Standard exception policy.     **/    public static DataValueDescriptor[] newRowFromClassInfoTemplate(    InstanceGetter[]    classinfo_template)         throws StandardException    {        DataValueDescriptor[] columns =             new DataValueDescriptor[classinfo_template.length];        try        {            for (int column_index = classinfo_template.length;                  column_index-- > 0;)            {                if (classinfo_template[column_index] != null)                {                    // get empty instance of DataValueDescriptor identified by                     // the format id.                    columns[column_index] = (DataValueDescriptor)                         classinfo_template[column_index].getNewInstance();                }            }        }        catch (InstantiationException ie)        {            newRowFromClassInfoTemplateError();        }        catch (IllegalAccessException iae)        {            newRowFromClassInfoTemplateError();        }        catch (InvocationTargetException ite)        {            newRowFromClassInfoTemplateError();        }		return columns;    }    /**     * return string version of row.     * <p>     * For debugging only.      *	 * @return The string version of row.     *     * @param row The row.     *     **/    public static String toString(Object[] row)    {        if (SanityManager.DEBUG)        {            String str = new String();            if (row != null)            {                if (row.length == 0)                {                    str = "empty row";                }                else                {                    for (int i = 0; i < row.length; i++)                        str += "col[" + i + "]=" + row[i];                }            }            else            {                str = "row is null";            }            return(str);        }        else        {            return(null);        }    }    /**     * return string version of a HashTable returned from a FetchSet.     * <p>     *	 * @return The string version of row.     *     *     **/    // For debugging only.     public static String toString(Hashtable hash_table)    {        if (SanityManager.DEBUG)        {            String str = new String();            Object  row_or_vector;            for (Enumeration e = hash_table.elements(); e.hasMoreElements();)            {                row_or_vector = e.nextElement();                if (row_or_vector instanceof Object[])                {                    // it's a row                    str += RowUtil.toString((Object[]) row_or_vector);                    str += "\n";                }                else if (row_or_vector instanceof Vector)                {                    // it's a vector                    Vector vec = (Vector) row_or_vector;                    for (int i = 0; i < vec.size(); i++)                    {                        str +=                             "vec[" + i + "]:" +                             RowUtil.toString((Object[]) vec.elementAt(i));                        str += "\n";                    }                }                else                {                    str += "BAD ENTRY\n";                }            }            return(str);        }        else        {            return(null);        }    }    /**     * Process the qualifier list on the row, return true if it qualifies.     * <p>     * A two dimensional array is to be used to pass around a AND's and OR's in     * conjunctive normal form.  The top slot of the 2 dimensional array is      * optimized for the more frequent where no OR's are present.  The first      * array slot is always a list of AND's to be treated as described above      * for single dimensional AND qualifier arrays.  The subsequent slots are      * to be treated as AND'd arrays or OR's.  Thus the 2 dimensional array      * qual[][] argument is to be treated as the following, note if      * qual.length = 1 then only the first array is valid and it is and an      * array of and clauses:     *     * (qual[0][0] and qual[0][0] ... and qual[0][qual[0].length - 1])     * and     * (qual[1][0] or  qual[1][1] ... or  qual[1][qual[1].length - 1])     * and     * (qual[2][0] or  qual[2][1] ... or  qual[2][qual[2].length - 1])     * ...     * and     * (qual[qual.length - 1][0] or  qual[1][1] ... or  qual[1][2])     *     * 	 * @return true if the row qualifies.     *     * @param row               The row being qualified.     * @param qual_list         2 dimensional array representing conjunctive     *                          normal form of simple qualifiers.     *	 * @exception  StandardException  Standard exception policy.     **/	public static final boolean qualifyRow(    Object[]        row,     Qualifier[][]   qual_list)		 throws StandardException	{        boolean     row_qualifies = true;        if (SanityManager.DEBUG)        {            SanityManager.ASSERT(row != null);        }        // First do the qual[0] which is an array of qualifer terms.        if (SanityManager.DEBUG)        {            // routine should not be called if there is no qualifier            SanityManager.ASSERT(qual_list != null);            SanityManager.ASSERT(qual_list.length > 0);        }        for (int i = 0; i < qual_list[0].length; i++)        {            // process each AND clause             row_qualifies = false;            // process each OR clause.            Qualifier q = qual_list[0][i];            // Get the column from the possibly partial row, of the             // q.getColumnId()'th column in the full row.            DataValueDescriptor columnValue =                     (DataValueDescriptor) row[q.getColumnId()];            row_qualifies =                columnValue.compare(                    q.getOperator(),                    q.getOrderable(),                    q.getOrderedNulls(),                    q.getUnknownRV());            if (q.negateCompareResult())                row_qualifies = !row_qualifies;            // Once an AND fails the whole Qualification fails - do a return!            if (!row_qualifies)                return(false);        }        // all the qual[0] and terms passed, now process the OR clauses        for (int and_idx = 1; and_idx < qual_list.length; and_idx++)        {            // loop through each of the "and" clause.            row_qualifies = false;            if (SanityManager.DEBUG)            {                // Each OR clause must be non-empty.                SanityManager.ASSERT(qual_list[and_idx].length > 0);            }            for (int or_idx = 0; or_idx < qual_list[and_idx].length; or_idx++)            {                // Apply one qualifier to the row.                Qualifier q      = qual_list[and_idx][or_idx];                int       col_id = q.getColumnId();                if (SanityManager.DEBUG)                {                    SanityManager.ASSERT(                        (col_id < row.length),                        "Qualifier is referencing a column not in the row.");                }                // Get the column from the possibly partial row, of the                 // q.getColumnId()'th column in the full row.                DataValueDescriptor columnValue =                     (DataValueDescriptor) row[q.getColumnId()];                if (SanityManager.DEBUG)                {                    if (columnValue == null)                        SanityManager.THROWASSERT(                            "1:row = " + RowUtil.toString(row) +                            "row.length = " + row.length +                            ";q.getColumnId() = " + q.getColumnId());                }                // do the compare between the column value and value in the                // qualifier.                row_qualifies =                     columnValue.compare(                            q.getOperator(),                            q.getOrderable(),                            q.getOrderedNulls(),                            q.getUnknownRV());                if (q.negateCompareResult())                    row_qualifies = !row_qualifies;                // SanityManager.DEBUG_PRINT("StoredPage.qual", "processing qual[" + and_idx + "][" + or_idx + "] = " + qual_list[and_idx][or_idx] );                // SanityManager.DEBUG_PRINT("StoredPage.qual", "value = " + row_qualifies);                // processing "OR" clauses, so as soon as one is true, break                // to go and process next AND clause.                if (row_qualifies)                    break;            }            // The qualifier list represented a set of "AND'd"             // qualifications so as soon as one is false processing is done.            if (!row_qualifies)                break;        }        return(row_qualifies);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -