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

📄 dinamespace.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.lang.reflect.Method;import java.lang.reflect.Modifier;import org.hsqldb.lib.HashMap;import org.hsqldb.lib.HashSet;import org.hsqldb.lib.HsqlArrayList;import org.hsqldb.lib.Iterator;import org.hsqldb.lib.WrapperIterator;// boucherb@users - 2004xxxx - patch 1.7.2// -- canonical database uri for catalog name reporting// -- enumXXX methods to iterateXXX// -- simple support for SEQUENCE schema reporting// -- report built-in procedures/procedure columns without dependency on user grants;/** * Provides catalog and schema related definitions and functionality. <p> * * Additional features include accessibility tests, class loading, filtered * iteration and inverted alias mapping functionality regarding Java Classes * and Methods defined within the context of this database name space support * object. <p> * * @author  boucherb@users * @version 1.8.0 * @since 1.7.2 */final class DINameSpace {    /** The Database for which the name space functionality is provided */    private Database database;    /** The catalog name reported by this namespace */    private String catalogName;    /**     * Set { <code>Class</code> FQN <code>String</code> objects }. <p>     *     * The Set contains the names of the classes providing the public static     * methods that are automatically made accessible to the PUBLIC user in     * support of the expected SQL CLI scalar functions and other core     * HSQLDB SQL functions and stored procedures. <p>     */    private static HashSet builtin = new HashSet();    // procedure columns    // make temporary ad-hoc spec a little more "official"    // until better system in place    static {        builtin.add("org.hsqldb.Library");        builtin.add("java.lang.Math");    }    /**     * Constructs a new name space support object for the     * specified Database object. <p>     *     * @param database The Database object for which to provide name     *      space support     * @throws HsqlException if a database access error occurs     */    public DINameSpace(Database database) throws HsqlException {        try {            this.database    = database;            this.catalogName = database.getURI();        } catch (Exception e) {            Trace.throwerror(Trace.GENERAL_ERROR, e.toString());        }    }    /**     * Retrieves the declaring <code>Class</code> object for the specified     * fully qualified method name, using (if possible) the classLoader     * attribute of this object's database. <p>     *     * @param fqn the fully qualified name of the method for which to     *        retrieve the declaring <code>Class</code> object.     * @return the declaring <code>Class</code> object for the     *        specified fully qualified method name     */    Class classForMethodFQN(String fqn) {        try {            return classForName(fqn.substring(0, fqn.lastIndexOf('.')));        } catch (Exception e) {            return null;        }    }    /**     * Retrieves the <code>Class</code> object specified by the     * <code>name</code> argument, using, if possible, the     * classLoader attribute of the database. <p>     *     * @param name the fully qualified name of the <code>Class</code>     *      object to retrieve.     * @throws ClassNotFoundException if the specified class object     *      cannot be found in the context of this name space     * @return the <code>Class</code> object specified by the     *      <code>name</code> argument     */    Class classForName(String name) throws ClassNotFoundException {        try {            if (database.classLoader == null) {                return Class.forName(name);            } else {                if (name != null) {                    return database.classLoader.loadClass(name);                } else {                    throw new ClassNotFoundException();                }            }        } catch (NoClassDefFoundError err) {            throw new ClassNotFoundException(err.toString());        }    }    /**     * Retrieves an <code>Iterator</code> whose elements form the set of     * distinct names of all visible catalogs, relative to this object's     * database. <p>     *     * If catalog reporting is turned off, then the empty Iterator is     * returned. <p>     *     * <b>Note:</b> in the present implementation, if catalog reporting is     * turned on, then the iteration consists of a single element that is the     * uri of this object's database; HSQLDB  currently does not support the     * concept a single engine hosting multiple catalogs. <p>     *     * @return An Iterator whose elements are <code>String</code> objects     *      naming all visible catalogs, relative to this object's database.     * @throws HsqlException never (reserved for future use)     */    Iterator iterateCatalogNames() throws HsqlException {        return isReportCatalogs() ? new WrapperIterator(catalogName)                                  : new WrapperIterator();    }    /**     * Retrieves the name of the catalog corresponding to the indicated     * object. <p>     *     * <B>Note:</B> the uri of this object's database is returned whenever     * catalog reporting is turned on. <p>     *     * This a stub that will be used until such time (if ever) that the     * engine actually supports the concept of multiple hosted     * catalogs. <p>     *     * @return the name of specified object's qualifying catalog, or null if     *      catalog reporting is turned off.     * @param o the object for which the name of its qualifying catalog     *      is to be retrieved     */    String getCatalogName(Object o) {        return isReportCatalogs() ? catalogName                                  : null;    }    /**     * Retrieves a map from each distinct value of this object's database     * SQL routine CALL alias map to the list of keys in the input map     * mapping to that value. <p>     *     * @return The requested map     */    HashMap getInverseAliasMap() {        HashMap       mapIn;        HashMap       mapOut;        Iterator      keys;        Object        key;        Object        value;        HsqlArrayList keyList;        // TODO:        // update Database to dynamically maintain its own        // inverse alias map.  This will make things *much*        // faster for our  purposes here, without appreciably        // slowing down Database        mapIn  = database.getAliasMap();        mapOut = new HashMap();        keys   = mapIn.keySet().iterator();        while (keys.hasNext()) {            key     = keys.next();            value   = mapIn.get(key);            keyList = (HsqlArrayList) mapOut.get(value);            if (keyList == null) {                keyList = new HsqlArrayList();                mapOut.put(value, keyList);            }            keyList.add(key);        }        return mapOut;    }    /**     * Retrieves the fully qualified name of the given Method object. <p>     *     * @param m The Method object for which to retreive the fully     *      qualified name     * @return the fully qualified name of the specified Method object.     */    static String getMethodFQN(Method m) {        return m == null ? null                         : m.getDeclaringClass().getName() + '.'                           + m.getName();    }    /**     * 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() + '.'                           + getSignature(m);    }    static String getSignature(Method method) {        StringBuffer sb;        String       signature;        Class[]      parmTypes;        int          len;        int          last;        sb        = new StringBuffer();        parmTypes = method.getParameterTypes();        len       = parmTypes.length;        last      = len - 1;        sb.append(method.getName()).append('(');        for (int i = 0; i < len; i++) {            sb.append(parmTypes[i].getName());            if (i < last) {                sb.append(',');            }        }        sb.append(')');        signature = sb.toString();

⌨️ 快捷键说明

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