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

📄 result.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                            .data, order, way) > 0) {                        n       = source1;                        source1 = source1.next;                        n1--;                    } else {                        n       = source0;                        source0 = source0.next;                        n0--;                    }                    if (target[dest] == null) {                        target[dest] = n;                    } else {                        targetlast[dest].next = n;                    }                    targetlast[dest] = n;                    n.next           = null;                }            }        }        rRoot = target[0];        rTail = targetlast[0];    }    /**     *  Method declaration     *     * @param  a     * @param  b     * @param  order     * @param  way     * @return -1, 0, +1     * @throws  HsqlException     */    private int compareRecord(Session session, Object[] a, final Object[] b,                              final int[] order,                              int[] way) throws HsqlException {        int i = Column.compare(session.database.collation, a[order[0]],                               b[order[0]], metaData.colTypes[order[0]]);        if (i == 0) {            for (int j = 1; j < order.length; j++) {                i = Column.compare(session.database.collation, a[order[j]],                                   b[order[j]], metaData.colTypes[order[j]]);                if (i != 0) {                    return i * way[j];                }            }        }        return i * way[0];    }    /**     *  Method declaration     *     * @param  a     * @param  b     * @param  len     * @return -1, 0, +1     * @throws  HsqlException     */    private int compareRecord(Session session, Object[] a, Object[] b,                              int len) throws HsqlException {        for (int j = 0; j < len; j++) {            int i = Column.compare(session.database.collation, a[j], b[j],                                   metaData.colTypes[j]);            if (i != 0) {                return i;            }        }        return 0;    }    /**     * Result structure used for set/get session attributes     */    static Result newSessionAttributesResult() {        Result r = new Result(ResultConstants.DATA, 7);        r.metaData.colNames = r.metaData.colLabels = r.metaData.tableNames =            new String[] {            "", "", "", "", "", "", ""        };        r.metaData.colTypes = new int[] {            Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,            Types.BOOLEAN, Types.BOOLEAN, Types.BOOLEAN        };        return r;    }    void write(RowOutputBinary out) throws IOException, HsqlException {        if (mode == ResultConstants.MULTI) {            writeMulti(out);            return;        }        int startPos = out.size();        out.writeSize(0);        out.writeIntData(mode);        out.writeIntData(databaseID);        out.writeIntData(sessionID);        switch (mode) {            case ResultConstants.GETSESSIONATTR :            case ResultConstants.SQLDISCONNECT :            case ResultConstants.SQLSTARTTRAN :            case ResultConstants.HSQLRESETSESSION :                break;            case ResultConstants.SQLPREPARE :                // Allows the engine side to fast-fail prepare of non-CALL                // statement against a CallableStatement object and CALL                // statement against PreparedStatement.                //                // May be useful in the future for other things                out.writeIntData(getStatementType());                out.writeString(mainString);                break;            case ResultConstants.PREPARE_ACK :            case ResultConstants.SQLFREESTMT :                out.writeIntData(statementID);                break;            case ResultConstants.SQLEXECDIRECT :                out.writeIntData(updateCount);                out.writeIntData(statementID);          // currently unused                out.writeString(mainString);                break;            case ResultConstants.ERROR :            case ResultConstants.SQLCONNECT :                out.writeString(mainString);                out.writeString(subString);                out.writeString(subSubString);                out.writeIntData(statementID);                break;            case ResultConstants.UPDATECOUNT :                out.writeIntData(updateCount);                break;            case ResultConstants.SQLENDTRAN : {                int type = getEndTranType();                out.writeIntData(type);                 // endtran type                switch (type) {                    case ResultConstants.SAVEPOINT_NAME_RELEASE :                    case ResultConstants.SAVEPOINT_NAME_ROLLBACK :                        out.writeString(mainString);    // savepoint name                    // default; // do nothing                }                break;            }            case ResultConstants.BATCHEXECUTE :            case ResultConstants.BATCHEXECDIRECT :            case ResultConstants.SQLEXECUTE :            case ResultConstants.SETSESSIONATTR : {                out.writeIntData(updateCount);                out.writeIntData(statementID);                int l = significantColumns;                out.writeIntData(l);                for (int i = 0; i < l; i++) {                    out.writeType(metaData.colTypes[i]);                }                out.writeIntData(size);                Record n = rRoot;                while (n != null) {                    out.writeData(l, metaData.colTypes, n.data, null, null);                    n = n.next;                }                break;            }            case ResultConstants.DATA :            case ResultConstants.PARAM_META_DATA : {                metaData.write(out, significantColumns);                out.writeIntData(size);                Record n = rRoot;                while (n != null) {                    out.writeData(significantColumns, metaData.colTypes,                                  n.data, null, null);                    n = n.next;                }                break;            }            case ResultConstants.SQLSETCONNECTATTR : {                int type = getConnectionAttrType();                out.writeIntData(type);                 // attr type                switch (type) {                    case ResultConstants.SQL_ATTR_SAVEPOINT_NAME :                        out.writeString(mainString);    // savepoint name                    // case ResultConstants.SQL_ATTR_AUTO_IPD // always true                    // default: // throw, but case never happens                }                break;            }            default :                throw new HsqlException(                    Trace.getMessage(                        Trace.Result_Result, true, new Object[]{                            new Integer(mode) }), null, 0);        }        out.writeIntData(out.size(), startPos);    }    void readMultiResult(RowInputBinary in)    throws HsqlException, IOException {        mode       = ResultConstants.MULTI;        databaseID = in.readIntData();        sessionID  = in.readIntData();        int count = in.readIntData();        for (int i = 0; i < count; i++) {            // Currently required for the outer result, but can simply            // be ignored for sub-results            in.readIntData();            add(new Object[]{ new Result(in) });        }    }    private void writeMulti(RowOutputBinary out)    throws IOException, HsqlException {        int startPos = out.size();        out.writeSize(0);        out.writeIntData(mode);        out.writeIntData(databaseID);        out.writeIntData(sessionID);        out.writeIntData(size);        Record n = rRoot;        while (n != null) {            ((Result) n.data[0]).write(out);            n = n.next;        }        out.writeIntData(out.size(), startPos);    }    /**     * Convenience method for writing, shared by Server side.     */    public static void write(Result r, RowOutputBinary rowout,                             OutputStream dataout)                             throws IOException, HsqlException {        rowout.reset();        r.write(rowout);        dataout.write(rowout.getOutputStream().getBuffer(), 0,                      rowout.getOutputStream().size());        dataout.flush();    }    /**     * Convenience method for reading, shared by Server side.     */    public static Result read(RowInputBinary rowin,                              DataInput datain)                              throws IOException, HsqlException {        int length = datain.readInt();        rowin.resetRow(0, length);        byte[] byteArray = rowin.getBuffer();        int    offset    = 4;        datain.readFully(byteArray, offset, length - offset);        return new Result(rowin);    }/** @todo fredt - move the messages to Trace.java */    public Result(Throwable t, String statement) {        mode      = ResultConstants.ERROR;        exception = t;        if (t instanceof HsqlException) {            HsqlException he = (HsqlException) t;            subString  = he.getSQLState();            mainString = he.getMessage();            if (statement != null) {                mainString += " in statement [" + statement + "]";            }            statementID = he.getErrorCode();        } else if (t instanceof OutOfMemoryError) {            // At this point, we've nothing to lose by doing this            System.gc();            subString   = "S1000";            mainString  = "out of memory";            statementID = Trace.OUT_OF_MEMORY;        } else {            subString  = "S1000";            mainString = Trace.getMessage(Trace.GENERAL_ERROR) + " " + t;            if (statement != null) {                mainString += " in statement [" + statement + "]";            }            statementID = Trace.GENERAL_ERROR;        }        subSubString = "";    }    public Throwable getException() {        return exception;    }    public int getStatementID() {        return statementID;    }    void setStatementID(int id) {        statementID = id;    }    public String getMainString() {        return mainString;    }    public void setMainString(String sql) {        mainString = sql;    }    public String getSubString() {        return subString;    }    public void setMaxRows(int count) {        updateCount = count;    }    public int getUpdateCount() {        return updateCount;    }    int getConnectionAttrType() {        return updateCount;    }    void setConnectionAttrType(int type) {        updateCount = type;    }    int getEndTranType() {        return updateCount;    }    void setEndTranType(int type) {        updateCount = type;    }    /** @todo fred - check this repurposing */    public int[] getUpdateCounts() {        return metaData.colTypes;    }    Object[] getParameterData() {        return (rRoot == null) ? null                               : rRoot.data;    }    public void setParameterData(Object[] data) {        if (rRoot == null) {            rRoot = new Record();        }        rRoot.data = data;        rRoot.next = null;        rTail      = rRoot;        size       = 1;    }    public void setResultType(int type) {        mode = type;    }    public void setStatementType(int type) {        updateCount = type;    }    public int getStatementType() {        return updateCount;    }    public int getType() {        return mode;    }    public boolean isData() {        return mode == ResultConstants.DATA;    }    public boolean isError() {        return mode == ResultConstants.ERROR;    }    public boolean isUpdateCount() {        return mode == ResultConstants.UPDATECOUNT;    }    public Iterator iterator() {        return new ResultIterator();    }    private class ResultIterator implements Iterator {        boolean removed;        int     counter;        Record  current = rRoot;        Record  last;        public boolean hasNext() {            return counter < size;        }        public Object next() {            if (hasNext()) {                removed = false;                if (counter != 0) {                    last    = current;                    current = current.next;                }                counter++;                return current.data;            }            throw new NoSuchElementException();        }        public int nextInt() {            throw new NoSuchElementException();        }        public long nextLong() {            throw new NoSuchElementException();        }        public void remove() {            if (counter <= size && counter != 0 &&!removed) {                removed = true;                if (current == rTail) {                    rTail = last;                }                if (current == rRoot) {                    current = rRoot = rRoot.next;                } else {                    current      = last;                    last         = null;                    current.next = current.next.next;                }                size--;                counter--;                return;            }            throw new NoSuchElementException();        }    }}

⌨️ 快捷键说明

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