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

📄 result.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    significantColumns = metaData.colLabels.length;                    int count = in.readIntData();                    while (count-- > 0) {                        add(in.readData(metaData.colTypes));                    }                    break;                }                case ResultConstants.SQLSETCONNECTATTR : {                    int type = in.readIntData();             // attr type                    setConnectionAttrType(type);                    switch (type) {                        case ResultConstants.SQL_ATTR_SAVEPOINT_NAME :                            mainString = in.readString();    // savepoint name                        //  case ResultConstants.SQL_ATTR_AUTO_IPD :                        //      - always true                        //  default: throw - case never happens                    }                    break;                }                default :                    throw new HsqlException(                        Trace.getMessage(                            Trace.Result_Result, true, new Object[]{                                new Integer(mode) }), null, 0);            }        } catch (IOException e) {            throw Trace.error(Trace.TRANSFER_CORRUPTED);        }    }    static Result newSingleColumnResult(String colName, int colType) {        Result result = new Result(ResultConstants.DATA, 1);        result.metaData.colNames[0]   = colName;        result.metaData.colLabels[0]  = colName;        result.metaData.tableNames[0] = "";        result.metaData.colTypes[0]   = colType;        return result;    }    static Result newPrepareResponse(int csid, Result rsmd, Result pmd) {        Result out;        Result pack;        out = new Result(ResultConstants.MULTI);//        out.isMulti      = true;        pack             = new Result(ResultConstants.PREPARE_ACK);        pack.statementID = csid;        out.add(new Object[]{ pack });        out.add(new Object[]{ rsmd });        out.add(new Object[]{ pmd });        return out;    }    static Result newParameterDescriptionResult(int len) {        Result r = new Result(ResultConstants.PARAM_META_DATA, len);        r.metaData.isParameterDescription = true;        r.metaData.paramMode              = new int[len];        return r;    }    public static Result newFreeStmtRequest(int statementID) {        Result r = new Result(ResultConstants.SQLFREESTMT);        r.statementID = statementID;        return r;    }    static Result newExecuteDirectRequest(String sql) {        Result out;        out = new Result(ResultConstants.SQLEXECDIRECT);        out.setMainString(sql);        return out;    }    public static Result newReleaseSavepointRequest(String name) {        Result out;        out = new Result(ResultConstants.SQLENDTRAN);        out.setMainString(name);        out.setEndTranType(ResultConstants.SAVEPOINT_NAME_RELEASE);        return out;    }    public static Result newRollbackToSavepointRequest(String name) {        Result out;        out = new Result(ResultConstants.SQLENDTRAN);        out.setMainString(name);        out.setEndTranType(ResultConstants.SAVEPOINT_NAME_ROLLBACK);        return out;    }    public static Result newSetSavepointRequest(String name) {        Result out;        out = new Result(ResultConstants.SQLSETCONNECTATTR);        out.setConnectionAttrType(ResultConstants.SQL_ATTR_SAVEPOINT_NAME);        out.setMainString(name);        return out;    }    /**     *  Method declaration     *     * @return     */    public int getSize() {        return size;    }    /**     *  Method declaration     *     * @param  columns     */    void setColumnCount(int columns) {        significantColumns = columns;    }    /**     *  Method declaration     *     * @return     */    public int getColumnCount() {        return significantColumns;    }    /**     *  Append Result argument to this.     *     * @param  a     */    void append(Result a) {        if (a.rRoot == null) {            return;        }        if (rRoot == null) {            rRoot = a.rRoot;        } else {            rTail.next = a.rRoot;        }        rTail = a.rTail;        size  += a.size;    }    void addAll(Result r) {        if (r == null) {            return;        }        Record from = r.rRoot;        while (from != null) {            add(from.data);            from = from.next;        }    }    public void clear() {        rRoot = null;        rTail = null;        size  = 0;    }    public boolean isEmpty() {        return rRoot == null;    }    /**     *  Method declaration     *     * @param  a     */    void setRows(Result a) {        if (a == null) {            rRoot = null;            rTail = null;            size  = 0;        } else {            rRoot = a.rRoot;            rTail = a.rTail;            size  = a.size;        }    }    /**     *  Method declaration     *     * @param  d     */    public void add(Object[] d) {        Record r = new Record();        r.data = d;        if (rRoot == null) {            rRoot = r;        } else {            rTail.next = r;        }        rTail = r;        size++;    }    /**     *  Method declaration     *     * @param  limitstart  number of records to discard at the head     * @param  limitcount  number of records to keep, all the rest if 0     */// fredt@users 20020130 - patch 1.7.0 by fredt// rewritten and moved from Select.java    void trimResult(int limitstart, int limitcount) {        Record n = rRoot;        if (n == null) {            return;        }        if (limitstart >= size) {            size  = 0;            rRoot = rTail = null;            return;        }        size -= limitstart;        for (int i = 0; i < limitstart; i++) {            n = n.next;            if (n == null) {                // if iSize is consistent this block will never be reached                size  = 0;                rRoot = rTail = n;                return;            }        }        rRoot = n;        if (limitcount == 0 || limitcount >= size) {            return;        }        for (int i = 1; i < limitcount; i++) {            n = n.next;            if (n == null) {                // if iSize is consistent this block will never be reached                return;            }        }        size   = limitcount;        n.next = null;        rTail  = n;    }    /**     * Removes duplicate rows on the basis of comparing the singificant     * columns of the rows in the result.     *     * @throws  HsqlException     */    void removeDuplicates(Session session) throws HsqlException {        removeDuplicates(session, significantColumns);    }    /**     * Removes duplicate rows on the basis of comparing the first columnCount     * columns of rows in the result.     *     * @throws  HsqlException     */// fredt@users 20020130 - patch 1.7.0 by fredt// to ensure consistency of r.rTail r.iSize in all set operations    void removeDuplicates(Session session,                          int columnCount) throws HsqlException {        if (rRoot == null) {            return;        }        int[] order = new int[columnCount];        int[] way   = new int[columnCount];        for (int i = 0; i < columnCount; i++) {            order[i] = i;            way[i]   = 1;        }        sortResult(session, order, way);        Record n = rRoot;        for (;;) {            Record next = n.next;            if (next == null) {                break;            }            if (compareRecord(session, n.data, next.data, columnCount) == 0) {                n.next = next.next;                size--;            } else {                n = next;            }        }        rTail = n;    }    /**     *  Removes duplicates then removes the contents of the second result     *  from this one base on first columnCount of the rows in each result.     *     * @param  minus     * @throws  HsqlException     */    void removeSecond(Session session, Result minus,                      int columnCount) throws HsqlException {        removeDuplicates(session, columnCount);        minus.removeDuplicates(session, columnCount);        Record  n     = rRoot;        Record  last  = rRoot;        boolean rootr = true;    // checking rootrecord        Record  n2    = minus.rRoot;        int     i     = 0;        while (n != null && n2 != null) {            i = compareRecord(session, n.data, n2.data, columnCount);            if (i == 0) {                if (rootr) {                    rRoot = last = n.next;                } else {                    last.next = n.next;                }                n = n.next;                size--;            } else if (i > 0) {    // r > minus                n2 = n2.next;            } else {               // r < minus                last  = n;                rootr = false;                n     = n.next;            }        }        for (; n != null; ) {            last = n;            n    = n.next;        }        rTail = last;    }    /**     * Removes all duplicate rows then removes all rows that are not shared     * between this and the other result, based on comparing the first     * columnCount columns of each result.     *     * @param  r2     * @throws  HsqlException     */    void removeDifferent(Session session, Result r2,                         int columnCount) throws HsqlException {        removeDuplicates(session, columnCount);        r2.removeDuplicates(session, columnCount);        Record  n     = rRoot;        Record  last  = rRoot;        boolean rootr = true;    // checking rootrecord        Record  n2    = r2.rRoot;        int     i     = 0;        size = 0;        while (n != null && n2 != null) {            i = compareRecord(session, n.data, n2.data, columnCount);            if (i == 0) {             // same rows                if (rootr) {                    rRoot = n;        // make this the first record                } else {                    last.next = n;    // this is next record in resultset                }                rootr = false;                last  = n;            // this is last record in resultset                n     = n.next;                n2    = n2.next;                size++;            } else if (i > 0) {       // r > r2                n2 = n2.next;            } else {                  // r < r2                n = n.next;            }        }        if (rootr) {             // if no lines in resultset            rRoot = null;        // then return null            last  = null;        } else {            last.next = null;    // else end resultset        }        rTail = last;    }    /**     *  Method declaration     *     * @param  order     * @param  way     * @throws  HsqlException     */    void sortResult(Session session, final int[] order,                    final int[] way) throws HsqlException {        if (rRoot == null || rRoot.next == null) {            return;        }        Record   source0, source1;        Record[] target     = new Record[2];        Record[] targetlast = new Record[2];        int      dest       = 0;        Record   n          = rRoot;        while (n != null) {            Record next = n.next;            n.next       = target[dest];            target[dest] = n;            n            = next;            dest         ^= 1;        }        for (int blocksize = 1; target[1] != null; blocksize <<= 1) {            source0   = target[0];            source1   = target[1];            target[0] = target[1] = targetlast[0] = targetlast[1] = null;            for (dest = 0; source0 != null; dest ^= 1) {                int n0 = blocksize,                    n1 = blocksize;                while (true) {                    if (n0 == 0 || source0 == null) {                        if (n1 == 0 || source1 == null) {                            break;                        }                        n       = source1;                        source1 = source1.next;                        n1--;                    } else if (n1 == 0 || source1 == null) {                        n       = source0;                        source0 = source0.next;                        n0--;                    } else if (compareRecord(session, source0.data, source1

⌨️ 快捷键说明

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