📄 column.java
字号:
/* Copyrights and Licenses * * This product includes Hypersonic SQL. * Originally developed by Thomas Mueller and the Hypersonic SQL Group. * * Copyright (c) 1995-2000 by the Hypersonic SQL 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. * - All advertising materials mentioning features or use of this software must display the * following acknowledgment: "This product includes Hypersonic SQL." * - Products derived from this software may not be called "Hypersonic SQL" nor may * "Hypersonic SQL" appear in their names without prior written permission of the * Hypersonic SQL Group. * - Redistributions of any form whatsoever must retain the following acknowledgment: "This * product includes Hypersonic SQL." * This software is provided "as is" and any expressed 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 the Hypersonic SQL Group or its 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 any 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. * This software consists of voluntary contributions made by many individuals on behalf of the * Hypersonic SQL Group. * * * For work added by the HSQL Development Group: * * Copyright (c) 2001-2002, 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, including earlier * license statements (above) and comply with all above license conditions. * * 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, including earlier * license statements (above) and comply with all above license conditions. * * 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 net.jumperz.ext.org.hsqldb;import net.jumperz.ext.org.hsqldb.lib.HsqlDateTime;import java.sql.SQLException;import java.sql.Time;import java.sql.Timestamp;import java.sql.Types;import java.math.BigDecimal;import java.util.Hashtable;import java.text.Collator;// fredt@users 20020320 - doc 1.7.0 - update// fredt@users 20020401 - patch 442993 by fredt - arithmetic expressions// to allow mixed type arithmetic expressions beginning with a narrower type// changes applied to several lines of code and not marked separately// consists of changes to arithmatic functions to allow promotion of// java.lang.Number values and new functions to choose type for promotion// fredt@users 20020401 - patch 455757 by galena@users (Michiel de Roo)// interpretation of TINYINT as Byte instead of Short// fredt@users 20020130 - patch 505356 by daniel_fiser@users// use of the current locale for string comparison (instead of posix)// turned off by default but can be applied accross the database by defining// sql.compare_in_locale=true in database.properties file// changes marked separately// fredt@users 20020130 - patch 491987 by jimbag@users// support for sql standard char and varchar. size is maintained as// defined in the DDL and trimming and padding takes place accordingly// modified by fredt - trimming and padding are turned off by default but// can be applied accross the database by defining sql.enforce_size=true in// database.properties file// fredt@users 20020215 - patch 1.7.0 by fredt - quoted identifiers// applied to different parts to support the sql standard for// naming of columns and tables (use of quoted identifiers as names)// fredt@users 20020328 - patch 1.7.0 by fredt - change REAL to Double// fredt@users 20020402 - patch 1.7.0 by fredt - type conversions// frequently used type conversions are done without creating temporary// Strings to reduce execution time and garbage collection// fredt@users 20021013 - patch 1.7.1 by fredt - type conversions// scripting of Double.Nan and infinity values/** * Implementation of SQL table columns as defined in DDL statements with * static methods to process their values. * * @version 1.7.0 */class Column { // non-standard type not in JDBC static final int VARCHAR_IGNORECASE = 100; // lookup for types private static Hashtable hTypes; // supported JDBC types - exclude NULL and VARCHAR_IGNORECASE static final int numericTypes[] = { Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.BIGINT, Types.NUMERIC, Types.DECIMAL, Types.FLOAT, Types.REAL, Types.DOUBLE }; static final int otherTypes[] = { Types.BIT, Types.LONGVARBINARY, Types.VARBINARY, Types.BINARY, Types.LONGVARCHAR, Types.CHAR, Types.VARCHAR, Types.DATE, Types.TIME, Types.TIMESTAMP, Types.OTHER }; static final int[][] typesArray = { Column.numericTypes, Column.otherTypes }; // DDL name, size, scale, null, identity and default values // most variables are final but not declared so because of a bug in // JDK 1.1.8 compiler HsqlName columnName; private int colType; private int colSize; private int colScale; private boolean isNullable; private boolean isIdentity; private boolean isPrimaryKey; private String defaultString; // helper values private static final BigDecimal BIGDECIMAL_0 = new BigDecimal("0"); static { hTypes = new Hashtable(67, 1); hTypes.put("INTEGER", new Integer(Types.INTEGER)); hTypes.put("INT", new Integer(Types.INTEGER)); hTypes.put("int", new Integer(Types.INTEGER)); hTypes.put("java.lang.Integer", new Integer(Types.INTEGER)); hTypes.put("IDENTITY", new Integer(Types.INTEGER)); hTypes.put("DOUBLE", new Integer(Types.DOUBLE)); hTypes.put("double", new Integer(Types.DOUBLE)); hTypes.put("java.lang.Double", new Integer(Types.DOUBLE)); hTypes.put("FLOAT", new Integer(Types.FLOAT)); hTypes.put("REAL", new Integer(Types.REAL)); hTypes.put("VARCHAR", new Integer(Types.VARCHAR)); hTypes.put("java.lang.String", new Integer(Types.VARCHAR)); hTypes.put("CHAR", new Integer(Types.CHAR)); hTypes.put("CHARACTER", new Integer(Types.CHAR)); hTypes.put("LONGVARCHAR", new Integer(Types.LONGVARCHAR)); hTypes.put("VARCHAR_IGNORECASE", new Integer(VARCHAR_IGNORECASE)); hTypes.put("DATE", new Integer(Types.DATE)); hTypes.put("java.sql.Date", new Integer(Types.DATE)); hTypes.put("TIME", new Integer(Types.TIME)); hTypes.put("java.sql.Time", new Integer(Types.TIME)); hTypes.put("TIMESTAMP", new Integer(Types.TIMESTAMP)); hTypes.put("java.sql.Timestamp", new Integer(Types.TIMESTAMP)); hTypes.put("DATETIME", new Integer(Types.TIMESTAMP)); hTypes.put("DECIMAL", new Integer(Types.DECIMAL)); hTypes.put("java.math.BigDecimal", new Integer(Types.DECIMAL)); hTypes.put("NUMERIC", new Integer(Types.NUMERIC)); hTypes.put("BIT", new Integer(Types.BIT)); hTypes.put("boolean", new Integer(Types.BIT)); hTypes.put("java.lang.Boolean", new Integer(Types.BIT)); hTypes.put("TINYINT", new Integer(Types.TINYINT)); hTypes.put("byte", new Integer(Types.TINYINT)); hTypes.put("java.lang.Byte", new Integer(Types.TINYINT)); hTypes.put("SMALLINT", new Integer(Types.SMALLINT)); hTypes.put("short", new Integer(Types.SMALLINT)); hTypes.put("java.lang.Short", new Integer(Types.SMALLINT)); hTypes.put("BIGINT", new Integer(Types.BIGINT)); hTypes.put("long", new Integer(Types.BIGINT)); hTypes.put("java.lang.Long", new Integer(Types.BIGINT)); hTypes.put("BINARY", new Integer(Types.BINARY)); hTypes.put("[B", new Integer(Types.BINARY)); hTypes.put("VARBINARY", new Integer(Types.VARBINARY)); hTypes.put("LONGVARBINARY", new Integer(Types.LONGVARBINARY)); hTypes.put("OTHER", new Integer(Types.OTHER)); hTypes.put("OBJECT", new Integer(Types.OTHER)); hTypes.put("java.lang.Object", new Integer(Types.OTHER)); hTypes.put("NULL", new Integer(Types.NULL)); hTypes.put("void", new Integer(Types.NULL)); hTypes.put("java.lang.Void", new Integer(Types.NULL)); }// fredt@users 20020130 - patch 491987 by jimbag@users /** * Creates a column defined in DDL statement. * * @param name * @param nullable * @param type * @param identity * @param namequoted Description of the Parameter * @param size Description of the Parameter * @param scale Description of the Parameter * @param defvalue Description of the Parameter */ Column(HsqlName name, boolean nullable, int type, int size, int scale, boolean identity, boolean primarykey, String defstring) { columnName = name; isNullable = nullable; colType = type; colSize = size; colScale = scale; isIdentity = identity; isPrimaryKey = primarykey; defaultString = defstring; } /** * Is this the identity column in the table. * * @return boolean */ boolean isIdentity() { return isIdentity; } /** * Is column nullable. * * @return boolean */ boolean isNullable() { return isNullable; } /** * Set nullable. * */ void setNullable(boolean value) { isNullable = value; } /** * Is this single column primary key of the table. * * @return boolean */ boolean isPrimaryKey() { return isPrimaryKey; } /** * Set primary key. * */ void setPrimaryKey(boolean value) { isPrimaryKey = value; } /** * The default value for the column. * * @return default value string as defined in DDL */ String getDefaultString() { return defaultString; } /** * Type of the column. * * @return java.sql.Types int value for the column */ int getType() { return colType; } /** * Size of the column in DDL (0 if not defined). * * @return DDL size of column */ int getSize() { return colSize; } /** * Scale of the column in DDL (0 if not defined). * * @return DDL scale of column */ int getScale() { return colScale; } /** * * @param SQL type string * @return java.sql.Types int value * @throws SQLException */ static int getTypeNr(String type) throws SQLException { Integer i = (Integer) hTypes.get(type); Trace.check(i != null, Trace.WRONG_DATA_TYPE, type); return i.intValue(); } /** * * @param type * @return SQL type string for a java.sql.Types int value * @throws SQLException */ static String getTypeString(int type) throws SQLException { switch (type) { case Types.NULL : return "NULL"; case Types.INTEGER : return "INTEGER"; case Types.DOUBLE : return "DOUBLE"; case VARCHAR_IGNORECASE : return "VARCHAR_IGNORECASE"; case Types.VARCHAR : return "VARCHAR"; case Types.CHAR : return "CHAR"; case Types.LONGVARCHAR : return "LONGVARCHAR"; case Types.DATE : return "DATE"; case Types.TIME : return "TIME"; case Types.DECIMAL : return "DECIMAL"; case Types.BIT : return "BIT"; case Types.TINYINT : return "TINYINT"; case Types.SMALLINT : return "SMALLINT";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -