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

📄 column.java

📁 Town是一个100% 纯Java API
💻 JAVA
字号:
package com.workingdogs.town;

import java.io.*;

/*
Town, a Java JDBC abstraction layer
Copyright (C) 1999  Serge Knystautas, Jon Stevens

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.
*/

import java.sql.*;

/**
This class represents a Column in the database and its associated meta information.
A <a href="com.workingdogs.town.Record.html">Record</A> is a collection of columns.

@author Jon S. Stevens <A HREF="mailto:jon@working-dogs.com">jon@working-dogs.com</A>
@author Serge Knystautas <a href="mailto:sergek@lokitech.com">sergek@lokitech.com</a>
@version 1.0
*/
public class Column
{
    /** column number in a schema object */
    private int columnNumber = -1;
    /** name of the column */
    private String name = "";
    /** example: this column is of type "String" */
    private String columnTypeName = "";
    /** what java.sql.Type is this column? */
    private int columnType = -1;
    /** name of table that this column belongs to */
    private String tableName = "";
    /** is null allowed for this column? */
    private boolean nullAllowed = false;
    /** is this an auto increment column? */
    private boolean autoIncrement = false;
    /** is this a read only column? */
    private boolean readOnly = false;
    /** is this a searchable column? */
    private boolean searchable = false;
    /** what is the scale of this column? */
    private int scale = -1;
    /** what is the precision of this column? */
    private int precision = -1;
    /** what is the length of this column? */
    private int length = -1;
    /** the column type resolved internally */
    private String type = "";

    /** Constructor */
    public Column()
    {
        this.columnNumber = -1;
        this.name = "";
        this.columnTypeName = "";
        this.tableName = "";
        this.columnType = -1;
        this.nullAllowed = false;
        this.autoIncrement = false;
        this.readOnly = false;
        this.searchable = false;
        this.scale = -1;
        this.precision = -1;
        this.length = -1;
        this.type = "";
    }
    /**
        does this column auto increment?
        @returns whether or not this column auto increments
      */
    public boolean autoIncrement()
    {
        return this.autoIncrement;
    }
    /**
        the data type of a column
        @returns the java.sql.Types String
      */
    public String dbType()
    {
        return this.columnTypeName;
    }
    /** column isBigDecimal: Types.NUMERIC || Types.DECIMAL */
    public boolean isBigDecimal()
    {
        if (this.typeEnum() == Types.NUMERIC || this.typeEnum() == Types.DECIMAL)
            return true;
        else
            return false;
    }
    /** column isBinary: Types.BINARY */
    public boolean isBinary()
    {
        if (this.typeEnum() == Types.BINARY)
            return true;
        else
            return false;
    }
    /** column isBoolean: Types.BIT */
    public boolean isBoolean()
    {
        if (this.typeEnum() == Types.BIT)
            return true;
        else
            return false;
    }
    /** column isByte: Types.TINYINT */
    public boolean isByte()
    {
        if (this.typeEnum() == Types.TINYINT)
            return true;
        else
            return false;
    }
    /** column isBytes: Types.BINARY || Types.VARBINARY || Types.LONGVARBINARY */
    public boolean isBytes()
    {
        if (this.typeEnum() == Types.LONGVARBINARY || this.typeEnum() == Types.VARBINARY ||
                this.columnType == Types.BINARY)
            return true;
        else
            return false;
    }
    /** column isDate: Types.Date */
    public boolean isDate()
    {
        if (this.typeEnum() == Types.DATE)
            return true;
        else
            return false;
    }
    /** column isDouble: Types.FLOAT || Types.DOUBLE */
    public boolean isDouble()
    {
        if (this.typeEnum() == Types.FLOAT || this.typeEnum() == Types.DOUBLE)
            return true;
        else
            return false;
    }
    /** column isFloat: Types.REAL */
    public boolean isFloat()
    {
        if (this.typeEnum() == Types.REAL)
            return true;
        else
            return false;
    }
    /** column isInt: Types.INTEGER */
    public boolean isInt()
    {
        if (this.typeEnum() == Types.INTEGER)
            return true;
        else
            return false;
    }
    /** column isLong: Types.BIGINT */
    public boolean isLong()
    {
        if (this.typeEnum() == Types.BIGINT)
            return true;
        else
            return false;
    }
    /** column isLongVarBinary: Types.LONGVARBINARY */
    public boolean isLongVarBinary()
    {
        if (this.typeEnum() == Types.LONGVARBINARY)
            return true;
        else
            return false;
    }
    /** column isShort: Types.SMALLINT */
    public boolean isShort()
    {
        if (this.typeEnum() == Types.SMALLINT)
            return true;
        else
            return false;
    }
    /** column isString: Types.LONGVARCHAR || -11 || Types.VARCHAR */
    public boolean isString()
    {
        if (this.typeEnum() == Types.LONGVARCHAR || this.typeEnum() == 11 ||
                this.typeEnum() == Types.VARCHAR)
            return true;
        else
            return false;
    }
    /** column isTime: Types.TIME */
    public boolean isTime()
    {
        if (this.typeEnum() == Types.TIME)
            return true;
        else
            return false;
    }
    /** column isTimestamp: Types.TIMESTAMP */
    public boolean isTimestamp()
    {
        if (this.typeEnum() == Types.TIMESTAMP)
            return true;
        else
            return false;
    }
    /** column isVarBinary: Types.VARBINARY */
    public boolean isVarBinary()
    {
        if (this.typeEnum() == Types.VARBINARY)
            return true;
        else
            return false;
    }
    /** unknown use */
    public String javaType() throws DataSetException
    {
        throw new DataSetException ("Method not implemented: Unknown use!");
    }
    /**
        the storage length of a column
        @returns the storage length of a column
      */
    public int length()
    {
        return this.length;
    }
    /**
        the name of the column
        @retuns the name of the column
      */
    public String name()
    {
        return this.name;
    }
    /**
        does this column allow null?
        @returns whether or not the column has null Allowed
      */
    public boolean nullAllowed()
    {
        return this.nullAllowed;
    }
    /** internal package method for populating a Column instance */
    void populate (ResultSetMetaData rsmd,
            int colNum) throws ConnectionException
    {
        try
        {
            this.columnNumber = colNum;
            this.name = rsmd.getColumnName (columnNumber);
            this.tableName = rsmd.getTableName(columnNumber);
            this.columnTypeName = rsmd.getColumnTypeName (columnNumber);
            this.columnType = rsmd.getColumnType (columnNumber);
            this.nullAllowed = rsmd.isNullable(columnNumber) == 1;
            this.autoIncrement = rsmd.isAutoIncrement(columnNumber);
            this.readOnly = rsmd.isReadOnly (columnNumber);
            this.searchable = rsmd.isSearchable (columnNumber);
            this.scale = rsmd.getScale (columnNumber);
            this.precision = rsmd.getPrecision (columnNumber);
            this.length = rsmd.getColumnDisplaySize (columnNumber);
        }
        catch (SQLException sqle)
        {
            throw new ConnectionException (sqle);
        }
    }
    /**
        the precision of the column
        @returns the precision of the column
      */
    public int precision()
    {
        return this.precision;
    }
    /**
        is this column read only?
        @returns whether or not this column is read only
      */
    public boolean readOnly()
    {
        return this.readOnly;
    }
    /**
        the scale of the column
        @returns the scale of the column
      */
    public int scale()
    {
        return this.scale;
    }
    /**
        is this column searchable?
        @returns true if this column is searchable
      */
    public boolean searchable()
    {
        return this.searchable;
    }
    /**
        the type of the column as a string
        @returns the type of the column as a string
      */
    public String type()
    {
        if (isBoolean())
            return "BOOLEAN";
        else if (isByte())
            return "BYTE";
        else if (isShort())
            return "SHORT";
        else if (isInt())
            return "INTEGER";
        else if (isLong())
            return "LONG";
        else if (isFloat())
            return "FLOAT";
        else if (isDouble())
            return "DOUBLE";
        else if (isBigDecimal())
            return "BIGDECIMAL";
        else if (isDate())
            return "DATE";
        else if (isTime())
            return "TIME";
        else if (isTimestamp())
            return "TIMESTAMP";
        else if (isString())
            return "STRING";
        else if (isBinary())
            return "BINARY";
        else if (isVarBinary())
            return "VARBINARY";
        else if (isLongVarBinary())
            return "LONGVARBINARY";

        return "UNKNOWN TYPE: " + typeEnum();
    }
    /**
        the data type of a column
        @returns the java.sql.Types enum
      */
    public int typeEnum()
    {
        return this.columnType;
    }
}

⌨️ 快捷键说明

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