com.github.jinahya.sql.database.metadata.bind.Column.java Source code

Java tutorial

Introduction

Here is the source code for com.github.jinahya.sql.database.metadata.bind.Column.java

Source

/*
 * Copyright 2013 Jin Kwon <onacit at gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.jinahya.sql.database.metadata.bind;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang3.builder.CompareToBuilder;

/**
 * An entity class for binding information from
 * {@link java.sql.DatabaseMetaData#getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) DatabaseMetaData.getColumns}.
 *
 * @author Jin Kwon &lt;jinahya_at_gmail.com&gt;
 */
@XmlRootElement
@XmlType(propOrder = { "columnName", "dataType", "typeName", "columnSize", "bufferLength", "decimalDigits",
        "numPrecRadix", "nullable", "remarks", "columnDef", "sqlDataType", "sqlDatetimeSub", "charOctetLength",
        "ordinalPosition", "isNullable", "scopeCatalog", "scopeSchema", "scopeTable", "sourceDataType",
        "isAutoincrement", "isGeneratedcolumn",
        // ---------------------------------------------------------------------
        "columnPrivileges" })
public class Column extends AbstractChild<Table> {

    public static Comparator<Column> natural() {

        return new Comparator<Column>() {

            @Override
            public int compare(final Column o1, final Column o2) {

                // by TABLE_CAT,TABLE_SCHEM, TABLE_NAME, and ORDINAL_POSITION.
                return new CompareToBuilder().append(o1.getTableCat(), o2.getTableCat())
                        .append(o1.getTableSchem(), o2.getTableSchem()).append(o1.getTableName(), o2.getTableName())
                        .append(o1.getOrdinalPosition(), o2.getOrdinalPosition()).build();
            }

        };
    }

    @Override
    public String toString() {

        return super.toString() + "{" + "tableCat=" + tableCat + ", tableSchem=" + tableSchem + ", tableName="
                + tableName + ", columnName=" + columnName + ", dataType=" + dataType + ", typeName=" + typeName
                + ", columnSize=" + columnSize + ", bufferLength=" + bufferLength + ", decimalDigits="
                + decimalDigits + ", numPrecRadix=" + numPrecRadix + ", nullable=" + nullable + ", remarks="
                + remarks + ", columnDef=" + columnDef + ", sqlDataType=" + sqlDataType + ", sqlDatetimeSub="
                + sqlDatetimeSub + ", charOctetLength=" + charOctetLength + ", ordinalPosition=" + ordinalPosition
                + ", isNullable=" + isNullable + ", scopeCatalog=" + scopeCatalog + ", scopeSchema=" + scopeSchema
                + ", scopeTable=" + scopeTable + ", sourceDataType=" + sourceDataType + ", isAutoincrement="
                + isAutoincrement + ", isGeneratedcolumn=" + isGeneratedcolumn + "}";
    }

    // ---------------------------------------------------------------- tableCat
    public String getTableCat() {

        return tableCat;
    }

    public void setTableCat(final String tableCat) {

        this.tableCat = tableCat;
    }

    // -------------------------------------------------------------- tableSchem
    public String getTableSchem() {

        return tableSchem;
    }

    public void setTableSchem(final String tableSchem) {

        this.tableSchem = tableSchem;
    }

    // --------------------------------------------------------------- tableName
    public String getTableName() {

        return tableName;
    }

    public void setTableName(final String tableName) {

        this.tableName = tableName;
    }

    // -------------------------------------------------------------- columnName
    public String getColumnName() {

        return columnName;
    }

    public void setColumnName(final String columnName) {

        this.columnName = columnName;
    }

    // ---------------------------------------------------------------- dataType
    public int getDataType() {

        return dataType;
    }

    public void setDataType(final int dataType) {

        this.dataType = dataType;
    }

    // ---------------------------------------------------------------- typeName
    public String getTypeName() {

        return typeName;
    }

    public void setTypeName(final String typeName) {

        this.typeName = typeName;
    }

    // -------------------------------------------------------------- columnSize
    public int getColumnSize() {

        return columnSize;
    }

    public void setColumnSize(int columnSize) {

        this.columnSize = columnSize;
    }

    // ------------------------------------------------------------ bufferLength
    public Integer getBufferLength() {

        return bufferLength;
    }

    public void setBufferLength(final Integer bufferLength) {

        this.bufferLength = bufferLength;
    }

    // ----------------------------------------------------------- decimalDigits
    public Integer getDecimalDigits() {

        return decimalDigits;
    }

    public void setDecimalDigits(final Integer decimalDigits) {

        this.decimalDigits = decimalDigits;
    }

    // ------------------------------------------------------------ numPrecRadix
    public int getNumPrecRadix() {

        return numPrecRadix;
    }

    public void setNumPrecRadix(final int numPrecRadix) {

        this.numPrecRadix = numPrecRadix;
    }

    // ---------------------------------------------------------------- nullable
    public int getNullable() {

        return nullable;
    }

    public void setNullable(final int nullable) {

        this.nullable = nullable;
    }

    // ----------------------------------------------------------------- remarks
    public String getRemarks() {

        return remarks;
    }

    public void setRemarks(final String remarks) {

        this.remarks = remarks;
    }

    // --------------------------------------------------------------- columnDef
    public String getColumnDef() {

        return columnDef;
    }

    public void setColumnDef(final String columnDef) {

        this.columnDef = columnDef;
    }

    // ------------------------------------------------------------- sqlDataType
    public Integer getSqlDataType() {

        return sqlDataType;
    }

    public void setSqlDataType(final Integer sqlDataType) {

        this.sqlDataType = sqlDataType;
    }

    // ---------------------------------------------------------- sqlDatetimeSub
    public Integer getSqlDatetimeSub() {

        return sqlDatetimeSub;
    }

    public void setSqlDatetimeSub(final Integer sqlDatetimeSub) {

        this.sqlDatetimeSub = sqlDatetimeSub;
    }

    // --------------------------------------------------------- charOctetLength
    public int getCharOctetLength() {

        return charOctetLength;
    }

    public void setCharOctetLength(final int charOctetLength) {

        this.charOctetLength = charOctetLength;
    }

    // --------------------------------------------------------- ordinalPosition
    public int getOrdinalPosition() {

        return ordinalPosition;
    }

    public void setOrdinalPosition(final int ordinalPosition) {

        this.ordinalPosition = ordinalPosition;
    }

    // -------------------------------------------------------------- isNullable
    public String getIsNullable() {

        return isNullable;
    }

    public void setIsNullable(final String isNullable) {

        this.isNullable = isNullable;
    }

    // ------------------------------------------------------------ scopeCatalog
    public String getScopeCatalog() {

        return scopeCatalog;
    }

    public void setScopeCatalog(final String scopeCatalog) {

        this.scopeCatalog = scopeCatalog;
    }

    // ------------------------------------------------------------- scopeSchema
    public String getScopeSchema() {

        return scopeSchema;
    }

    public void setScopeSchema(final String scopeSchema) {

        this.scopeSchema = scopeSchema;
    }

    // -------------------------------------------------------------- scopeTable
    public String getScopeTable() {

        return scopeTable;
    }

    public void setScopeTable(final String scopeTable) {

        this.scopeTable = scopeTable;
    }

    // ---------------------------------------------------------- sourceDataType
    public Short getSourceDataType() {

        return sourceDataType;
    }

    public void setSourceDataType(final Short sourceDataType) {

        this.sourceDataType = sourceDataType;
    }

    // --------------------------------------------------------- isAutoincrement
    public String getIsAutoincrement() {

        return isAutoincrement;
    }

    public void setIsAutoincrement(final String isAutoincrement) {

        this.isAutoincrement = isAutoincrement;
    }

    // ------------------------------------------------------- isGeneratedcolumn
    public String getIsGeneratedcolumn() {

        return isGeneratedcolumn;
    }

    public void setIsGeneratedcolumn(final String isGeneratedcolumn) {

        this.isGeneratedcolumn = isGeneratedcolumn;
    }

    // ------------------------------------------------------------------- table
    // just for class diagram
    private Table getTable() {

        return getParent();
    }

    //    public void setTable(final Table table) {
    //
    //        setParent(table);
    //    }
    //
    //
    //    Column table(final Table table) {
    //
    //        setTable(table);
    //
    //        return this;
    //    }
    // -------------------------------------------------------- columnPrivileges
    public List<ColumnPrivilege> getColumnPrivileges() {

        if (columnPrivileges == null) {
            columnPrivileges = new ArrayList<ColumnPrivilege>();
        }

        return columnPrivileges;
    }

    public void setColumnPrivileges(List<ColumnPrivilege> columnPrivileges) {
        this.columnPrivileges = columnPrivileges;
    }

    // -------------------------------------------------------------------------
    @Label("TABLE_CAT")
    @NillableBySpecification
    @XmlAttribute
    private String tableCat;

    @Label("TABLE_SCHEM")
    @NillableBySpecification
    @XmlAttribute
    private String tableSchem;

    @Label("TABLE_NAME")
    @XmlAttribute
    private String tableName;

    @Label("COLUMN_NAME")
    @XmlElement(required = true)
    private String columnName;

    @Label("DATA_TYPE")
    @XmlElement(required = true)
    private int dataType;

    @Label("TYPE_NAME")
    @XmlElement(required = true)
    private String typeName;

    @Label("COLUMN_SIZE")
    @XmlElement(required = true)
    private int columnSize;

    @Label("BUFFER_LENGTH")
    @Unused
    @XmlElement(nillable = true, required = true)
    private Integer bufferLength;

    @Label("DECIMAL_DIGITS")
    @NillableBySpecification
    @XmlElement(required = true)
    private Integer decimalDigits;

    @Label("NUM_PREC_RADIX")
    @XmlElement(required = true)
    private int numPrecRadix;

    @Label("NULLABLE")
    @XmlElement(required = true)
    private int nullable;

    @Label("REMARKS")
    @NillableBySpecification
    @XmlElement(nillable = true, required = true)
    private String remarks;

    @Label("COLUMN_DEF")
    @NillableBySpecification
    @XmlElement(nillable = true, required = true)
    private String columnDef;

    @Label("SQL_DATA_TYPE")
    @Unused
    @XmlElement(nillable = true, required = true)
    private Integer sqlDataType;

    @Label("SQL_DATETIME_SUB")
    @Unused
    @XmlElement(nillable = true, required = true)
    private Integer sqlDatetimeSub;

    @Label("CHAR_OCTET_LENGTH")
    @XmlElement(required = true)
    private int charOctetLength;

    @Label("ORDINAL_POSITION")
    @XmlElement(required = true)
    private int ordinalPosition;

    @Label("IS_NULLABLE")
    @XmlElement(required = true)
    private String isNullable;

    @Label("SCOPE_CATALOG")
    @NillableBySpecification
    @XmlElement(nillable = true, required = true)
    private String scopeCatalog;

    @Label("SCOPE_SCHEMA")
    @NillableBySpecification
    @XmlElement(nillable = true, required = true)
    private String scopeSchema;

    @Label("SCOPE_TABLE")
    @NillableBySpecification
    @XmlElement(nillable = true, required = true)
    private String scopeTable;

    @Label("SOURCE_DATA_TYPE")
    @NillableBySpecification
    @XmlElement(nillable = true, required = true)
    private Short sourceDataType;

    @Label("IS_AUTOINCREMENT")
    @XmlElement(required = true)
    private String isAutoincrement;

    @Label("IS_GENERATEDCOLUMN")
    @XmlElement(required = true)
    private String isGeneratedcolumn;

    @Invocation(name = "getColumnPrivileges", types = { String.class, String.class, String.class,
            String.class }, argsarr = {
                    @InvocationArgs({ ":tableCat", ":tableSchem", ":tableName", ":columnName" }) })
    @XmlElementRef
    private List<ColumnPrivilege> columnPrivileges;

}