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

📄 ditypeinfo.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* 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.util.Locale;import org.hsqldb.resources.BundleHandler;import org.hsqldb.store.ValuePool;/** * Provides information intrinsic to each standard data type known to * HSQLDB.  This includes all types for which standard type codes are known * at the time of writing and thus includes types that may not yet be * supported as table or procedure columns. <p> * * @author  boucherb@users * @version 1.8.0 * @since 1.7.2 */final class DITypeInfo {    // related to DatabaseMetaDataValues    static final int columnNoNulls  = 0;    static final int columnNullable = 1;    static final int typePredNone   = 0;    static final int typePredChar   = 1;    static final int typePredBasic  = 2;    static final int typeSearchable = 3;    /** BundleHandler id for create params resource bundle. */    private int hnd_create_params = -1;    /** BundleHandler id for local names resource bundle. */    private int hnd_local_names = -1;    /** BundleHandler id for data type remarks resource bundle. */    private int hnd_remarks = -1;    /** The SQL type code on which this object is reporting. */    private int type = Types.NULL;    /** The HSQLDB subtype code on which this object is reporting. */    private int typeSub = Types.TYPE_SUB_DEFAULT;    boolean     locale_set;    /** Creates a new DITypeInfo object having the default Locale. */    DITypeInfo() {        // boucherb@users 20050515 - patch 1.8.0 - make setLocale lazy        //setLocale(Locale.getDefault());    }    /**     * Retrieves the maximum Integer.MAX_VALUE bounded length, in bytes, for     * character types. <p>     *     * @return the maximum Integer.MAX_VALUE bounded length, in     *    bytes, for character types     */    Integer getCharOctLen() {        return null;    }    /**     * Retrieves the maximum Long.MAX_VALUE bounded length, in bytes, for     * character types. <p>     *     * @return the maximum Long.MAX_VALUE bounded length, in     *    bytes, for character types     */    Long getCharOctLenAct() {        switch (type) {            case Types.CHAR :            case Types.LONGVARCHAR :            case Types.VARCHAR :                return ValuePool.getLong(2L * Integer.MAX_VALUE);            case Types.CLOB :                return ValuePool.getLong(Long.MAX_VALUE);            default :                return null;        }    }    /**     * Retrieves the fully-qualified name of the Java class whose instances     * are manufactured by HSQLDB to store table column values in     * memory. <p>     *     * This is also typically the fully-qualified name of the Java class whose     * instances are manufactured by HSQLDB in response to     * jdbcResultSet.getObject(int). <p>     *     * @return the fully-qualified name of the Java class whose     *    instances are manufactured by HSQLDB to store     *    table column values in memory     */    String getColStClsName() {        return Types.getColStClsName(type);    }    /**     * Retrieves a character sequence representing a CSV list, in     * DDL declaraion order, of the create parameters for the type. <p>     *     * @return a character sequence representing a CSV     *    list, in DDL declaraion order, of the create     *    parameters for the type.     */    String getCreateParams() {        if (!locale_set) {            setLocale(Locale.getDefault());        }        String names;        switch (type) {            case Types.CHAR :            case Types.VARCHAR :                names = "LENGTH";                break;            case Types.DECIMAL :            case Types.NUMERIC :                names = "PRECISION,SCALE";                break;            case Types.FLOAT :            case Types.TIMESTAMP :                names = "PRECISION";                break;            default :                names = null;                break;        }        return names;    }    /**     * Retrieves the fully-qualified name of the HSQLDB-provided java.sql     * interface implementation class whose instances would be manufactured     * by HSQLDB to retrieve column values of this type, if the     * the type does not have a standard Java mapping.  <p>     *     * This value is simply the expected class name, regardless of whether     * HSQLDB, the specific HSQLDB distribution instance or the hosting JVM     * actually provide or support such implementations. That is, as of a     * specific release, HSQLDB may not yet provide such an implementation     * or may not automatically map to it or may not support it as a table     * column type, the version of java.sql may not define the interface to     * implement and the HSQLDB jar may not contain the implementation     * classes, even if they are defined in the corresponding release     * and build options and are supported under the hosting JVM's java.sql     * version.<p>     *     * @return the fully-qualified name of the HSQLDB-provided java.sql     *    interface implementation class whose instances would     *    be manufactured by HSQLDB to retrieve column values of     *    this type, given that the type does not have a standard Java     *    mapping and regardless of whether a class with the indicated     *    name is actually implemented or available on the class path     */    String getCstMapClsName() {        switch (type) {            case Types.ARRAY :                return "org.hsqldb.jdbc.jdbcArray";            case Types.BLOB :                return "org.hsqldb.jdbc.jdbcBlob";            case Types.CLOB :                return "org.hsqldb.jdbc.jdbcClob";            case Types.DISTINCT :                return "org.hsqldb.jdbc.jdbcDistinct";            case Types.REF :                return "org.hsqldb.jdbc.jdbcRef";            case Types.STRUCT :                return "org.hsqldb.jdbc.jdbcStruct";            default :                return null;        }    }// NOTES:// From recent usability testing, this patch and the corresponding patch in// jdbcResultSetMetaData together provide better compatibility with existing// tools than through the previous method of dynamically scanning each result// in jdbcResultSetMetaData.  This is especially true given that many tools use// the display size to set their internal max # of characters reserved for// result columns at said position. Also, since adding implementation of// ResultSetMetaData retreived from PreparedStatement's getMetaData method,// there exists the case where there is no data to scan in order to determine// an approximation.  Finally, since for plain old Statement objects the only// way to get metadata is to execute the query and since the scan approximation// can vary from one execution to the next, it turns out it's much "safer" and// more usable in a tool setting to simply indicate a large but expected// acceptable number of characters, rather than report either a number generally// too large to handle or a number too small to hold the actual expected maximum// number of characters for result colums of CHAR or VARCHAR types    /**     * Retrieves the maximum length that a String representation of     * the type may have. <p>     *     * The calculation follows these rules: <p>     *     * <ol>     * <li>Long character and datetime types:<p>     *     *     The maximum length/precision, repectively.<p>     *     * <li>CHAR and VARCHAR types: <p>     *     *      The value of the system property hsqldb.max_xxxchar_display_size     *      or the magic value 32766 (0x7FFE) (tested usable/accepted by most     *      tools and compatible with assumptions made by java.io read/write     *      UTF) when the system property is not defined or is not accessible,     *      due to security constraints. <p>     *     * <li>Number types: <p>     *     *     The max precision, plus the length of the negation character (1),     *     plus (if applicable) the maximum number of characters that may     *     occupy the exponent character sequence. <p>     *     * <li>BOOLEAN/BIT types: <p>     *     *     The length of the character sequence "false" (5), the longer of the     *     two boolean value String representations. <p>     *     * <li>All remaining types: <p>     *     *     The result of whatever calculation must be performed to determine     *     the maximum length of the type's String representation. If the     *     maximum display size is unknown, unknowable or inapplicable, then     *     zero is returned. <p>     *     * </ol>     *     * @return the maximum length that a String representation of     *      the type may have, or zero (0) if unknown or unknowable     */    int getMaxDisplaySize() {        return Types.getMaxDisplaySize(type);    }    /**     * Retrieves the data type, as an Integer. <p>     *     * @return the data type, as an Integer.     */    Integer getDataType() {        return ValuePool.getInt(type);    }    /**     * Retrieves the data subtype, as an Integer. <p>     *     * @return the data subtype, as an Integer     */    Integer getDataTypeSub() {        return ValuePool.getInt(typeSub);    }    /**     * Retrieves the implied or single permitted scale for exact numeric     * types, when no scale is declared or no scale declaration is     * permitted. <p>     *     * @return the implied or single permitted scale for exact numeric     *    types, when no scale is declared or no scale declaration     *    is permitted     */    Integer getDefaultScale() {        switch (type) {            case Types.BIGINT :            case Types.INTEGER :            case Types.SMALLINT :            case Types.TINYINT :                return ValuePool.getInt(0);            default :                return null;        }    }    /**     * Retrieves null (not implemented). <p>     *     * @return null (not implemented)     */    Integer getIntervalPrecision() {        return null;    }    /**     * Retrieves the character(s) prefixing a literal of this type. <p>     *     * @return the character(s) prefixing a literal of this type.     */    String getLiteralPrefix() {        switch (type) {            case Types.BINARY :            case Types.BLOB :            case Types.CHAR :            case Types.CLOB :            case Types.LONGVARBINARY :            case Types.LONGVARCHAR :            case Types.VARBINARY :            case Types.VARCHAR :                return "'";            case Types.DATALINK :                return "'";    // hypothetically: "{url '";            case Types.DATE :                return "'";    // or JDBC escape: "{d '";            case Types.OTHER :                return "'";    // hypothetically: "{o '"; or new "pkg.cls"(...)            case Types.TIME :                return "'";    // or JDBC escape: "{t '";            case Types.TIMESTAMP :                return "'";    // or JDBC escape: "{ts '";            case Types.XML :                return "'";    // hypothetically: "{xml '";            default :                return null;        }    }    /**     * Retrieves the character(s) terminating a literal of this type. <p>     *     * @return the character(s) terminating a literal of this type     */    String getLiteralSuffix() {        switch (type) {            case Types.BINARY :            case Types.BLOB :            case Types.CHAR :            case Types.CLOB :            case Types.LONGVARBINARY :            case Types.LONGVARCHAR :            case Types.VARBINARY :            case Types.VARCHAR :                return "'";

⌨️ 快捷键说明

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