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

📄 diprocedureinfo.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2001-2005, The HSQL Development Group * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the HSQL Development Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.hsqldb;import java.io.Serializable;import java.lang.reflect.Method;import org.hsqldb.lib.HashMap;import org.hsqldb.lib.HsqlArrayList;import org.hsqldb.resources.BundleHandler;import org.hsqldb.store.ValuePool;import org.hsqldb.types.Binary;/**@todo fredt - move Trace.doAssert() literals to Trace*//** * Provides information about HSQLDB SQL-invoked routines and SQL functions. <p> * * In particular, this class provides information about Java Methods in a form * compatible with presentation via the related HSQLDB system tables, * SYSTEM_PROCEDURES and SYSTEM_PROCEDURECOLUMNS, involved in the production of * the DatabaseMetaData getProcedures and getProcedureColumns result sets. * * @author  boucherb@users * @version 1.7.2 * @since 1.7.2 */final class DIProcedureInfo {    // java.sql dependencies mostly removed    static final String   conClsName               = "java.sql.Connection";    static final int      procedureResultUnknown   = 0;    static final int      procedureNoResult        = 1;    static final int      procedureReturnsResult   = 2;    static final int      procedureColumnUnknown   = 0;    static final int      procedureColumnIn        = 1;    static final int      procedureColumnInOut     = 2;    static final int      procedureColumnResult    = 3;    static final int      procedureColumnOut       = 4;    static final int      procedureColumnReturn    = 5;    static final int      procedureNoNulls         = 0;    static final int      procedureNullable        = 1;    static final int      procedureNullableUnknown = 2;    private Class         clazz;    private Class[]       colClasses;    private int[]         colTypes;    private int           colOffset;    private int           colCount;    private boolean       colsResolved;    private String        fqn;    private String        specificName;    private int           hnd_remarks;    private Method        method;    private String        sig;    private DINameSpace   nameSpace;    private final HashMap typeMap = new HashMap();    public DIProcedureInfo(DINameSpace ns) throws HsqlException {        setNameSpace(ns);    }    private int colOffset() {        if (!colsResolved) {            resolveCols();        }        return colOffset;    }    HsqlArrayList getAliases() {        return (HsqlArrayList) nameSpace.getInverseAliasMap().get(getFQN());    }    Class getColClass(int i) {        return colClasses[i + colOffset()];    }    int getColCount() {        if (!colsResolved) {            resolveCols();        }        return colCount;    }    Integer getColDataType(int i) {        return ValuePool.getInt(getColTypeCode(i));    }    Integer getColLen(int i) {        int size;        int type;        type = getColTypeCode(i);        switch (type) {            case Types.BINARY :            case Types.LONGVARBINARY :            case Types.VARBINARY : {                size = Integer.MAX_VALUE;                break;            }            case Types.BIGINT :            case Types.DOUBLE :            case Types.DATE :            case Types.FLOAT :            case Types.TIME : {                size = 8;                break;            }            case Types.TIMESTAMP : {                size = 12;                break;            }            case Types.REAL :            case Types.INTEGER : {                size = 4;                break;            }            case Types.SMALLINT : {                size = 2;                break;            }            case Types.TINYINT :            case Types.BOOLEAN : {                size = 1;                break;            }            default :                size = 0;        }        return (size == 0) ? null                           : ValuePool.getInt(size);    }    String getColName(int i) {        return CompiledStatement.PCOL_PREFIX + (i + colOffset());    }    Integer getColNullability(int i) {        int cn;        cn = getColClass(i).isPrimitive() ? procedureNoNulls                                          : procedureNullable;        return ValuePool.getInt(cn);    }    String getColRemark(int i) {        String       key;        StringBuffer sb;        sb  = new StringBuffer(getSignature());        key = sb.append('@').append(i + colOffset()).toString();        return BundleHandler.getString(hnd_remarks, key);    }    // JDBC sort-contract:    // out return value column, then in/in out/out parameter columns    // in formal order, then result columns in column order    //    // Currently, we materialize the java method return value, if    // any, as a result column, not as an OUT return value column, so    // it should actually appear _after_ the other procedure columns    // in the row order returned by the JDBC getProcedureColumns() method    int getColSequence(int i) {        // colOffset has the side-effect of setting colCount properly        return (i + colOffset() == 0) ? colCount                                      : i;    }    int getColTypeCode(int i) {        i += colOffset();        return colTypes[i];    }    Integer getColUsage(int i) {        switch (i + colOffset()) {            case 0 : {                // Currently, we materialize the java method return value, if                // any, as a result column, not as an OUT return column                return ValuePool.getInt(procedureColumnResult);            }            // todo: registration and reporting on result columns for routines            //       that generate real" result sets            default : {                // We could get religious here and maybe report IN OUT                // for newRow of before update for each row trigger methods,                // but there's not really any added value                return ValuePool.getInt(procedureColumnIn);            }        }    }    Class getDeclaringClass() {        return this.clazz;    }    String getFQN() {        StringBuffer sb;        if (fqn == null) {            sb = new StringBuffer();            fqn = sb.append(clazz.getName()).append('.').append(                method.getName()).toString();        }        return fqn;    }    String getSpecificName() {        if (specificName == null) {            specificName = clazz.getName() + "." + getSignature();        }        return specificName;    }    Integer getInputParmCount() {        return ValuePool.getInt(method.getParameterTypes().length);    }    Method getMethod() {        return this.method;    }    String getOrigin(String srcType) {        return (nameSpace.isBuiltin(clazz) ? "BUILTIN "                                           : "USER DEFINED ") + srcType;    }    Integer getOutputParmCount() {        // no support for IN OUT or OUT columns yet        return ValuePool.getInt(0);    }    String getRemark() {        return BundleHandler.getString(hnd_remarks, getSignature());    }    Integer getResultSetCount() {        return (method.getReturnType() == Void.TYPE) ? ValuePool.getInt(0)                                                     : ValuePool.getInt(1);    }    Integer getResultType(String origin) {        int type;        type = !"ROUTINE".equals(origin) ? procedureResultUnknown                                         : method.getReturnType()                                           == Void.TYPE ? procedureNoResult                                                        : procedureReturnsResult;        return ValuePool.getInt(type);    }    String getSignature() {        if (sig == null) {            sig = DINameSpace.getSignature(method);        }        return sig;    }    /**     * Retrieves the specific name of the given Method object. <p>     *     * @param m The Method object for which to retreive the specific name     * @return the specific name of the specified Method object.     */    static String getMethodSpecificName(Method m) {        return m == null ? null                         : m.getDeclaringClass().getName() + '.'                           + DINameSpace.getSignature(m);    }    DINameSpace getNameSpace() {        return nameSpace;    }    void setNameSpace(DINameSpace ns) throws HsqlException {        nameSpace = ns;        Class   c;        Integer type;        // can only speed up test significantly for java.lang.Object,        // final classes, primitive types and hierachy parents.        // Must still check later if assignable from candidate classes, where        // hierarchy parent is not final.

⌨️ 快捷键说明

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