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

📄 column.java

📁 用JAVA自己写的一个数据交换
💻 JAVA
字号:
package com.gemt.dataswap.dataset;

import java.sql.DatabaseMetaData;

public class Column {
    /**
     * Indicates that the column might not allow <code>NULL</code> values.
     */
    public static final Nullable NO_NULLS = new Nullable("noNulls");
    /**
     * Indicates that the column definitely allows <code>NULL</code> values.
     */
    public static final Nullable NULLABLE = new Nullable("nullable");
    /**
     * Indicates that the nullability of columns is unknown.
     */
    public static final Nullable NULLABLE_UNKNOWN = new Nullable("nullableUnknown");

    private final String _columnName;
    private final String _dataType;
    private final String _sqlTypeName;
    private final Nullable _nullable;

    /**
     * Creates a Column object. This contructor set nullable to true.
     *
     * @param columnName the column name
     * @param dataType the data type
     */
    public Column(String columnName, String dataType)
    {
        _columnName = columnName;
        _dataType = dataType;
        _nullable = NULLABLE_UNKNOWN;
        _sqlTypeName = DataType.DEFAULT_TYPE;
    }

    /**
     * Creates a Column object.
     */
    public Column(String columnName, String dataType, Nullable nullable)
    {
        _columnName = columnName;
        _dataType = dataType;
        _sqlTypeName = DataType.DEFAULT_TYPE;
        _nullable = nullable;
    }

    /**
     * Creates a Column object.
     */
    public Column(String columnName, String dataType, String sqlTypeName,
            Nullable nullable)
    {
        _columnName = columnName;
        _dataType = dataType;
        _sqlTypeName = sqlTypeName;
        _nullable = nullable;
    }

    /**
     * Returns this column name.
     */
    public String getColumnName()
    {
        return _columnName;
    }

    /**
     * Returns this column data type.
     */
    public String getDataType()
    {
        return _dataType;
    }

    /**
     * Returns this column sql data type name.
     */
    public String getSqlTypeName()
    {
        return _sqlTypeName;
    }

    /**
     * Returns <code>true</code> if this column is nullable.
     */
    public Nullable getNullable()
    {
        return _nullable;
    }

    /**
     * Returns the appropriate Nullable constant according specified JDBC
     * DatabaseMetaData constant.
     *
     * @param nullable one of the following constants
     * {@link java.sql.DatabaseMetaData#columnNoNulls},
     * {@link java.sql.DatabaseMetaData#columnNullable},
     * {@link java.sql.DatabaseMetaData#columnNullableUnknown}
     */
    public static Nullable nullableValue(int nullable)
    {
        switch (nullable)
        {
            case DatabaseMetaData.columnNoNulls:
                return NO_NULLS;

            case DatabaseMetaData.columnNullable:
                return NULLABLE;

            case DatabaseMetaData.columnNullableUnknown:
                return NULLABLE_UNKNOWN;

            default:
                throw new IllegalArgumentException("Unknown constant value "
                        + nullable);
        }
    }

    /**
     * Returns the appropriate Nullable constant.
     *
     * @param nullable <code>true</code> if null is allowed
     */
    public static Nullable nullableValue(boolean nullable)
    {
        return nullable ? NULLABLE : NO_NULLS;
    }

    ////////////////////////////////////////////////////////////////////////////
    // Object class

    public String toString()
    {
        return "(" + _columnName + ", " + _dataType + ", " + _nullable + ")";
//        return _columnName;
    }

    public boolean equals(Object o)
    {
        if (this == o) return true;
        if (!(o instanceof Column)) return false;

        final Column column = (Column)o;

        if (!_columnName.equals(column._columnName)) return false;
        if (!_dataType.equals(column._dataType)) return false;
        if (!_nullable.equals(column._nullable)) return false;
        if (!_sqlTypeName.equals(column._sqlTypeName)) return false;

        return true;
    }

    public int hashCode()
    {
        int result;
        result = _columnName.hashCode();
        result = 29 * result + _dataType.hashCode();
        result = 29 * result + _sqlTypeName.hashCode();
        result = 29 * result + _nullable.hashCode();
        return result;
    }

    public static class Nullable
    {

        private final String _name;

        private Nullable(String name)
        {
            _name = name;
        }

        ////////////////////////////////////////////////////////////////////////////
        // Object class

        public String toString()
        {
            return _name;
        }
    }	
}

⌨️ 快捷键说明

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