
dk.eobjects.metamodel.schema.Column Maven / Gradle / Ivy
/**
* This file is part of MetaModel.
*
* MetaModel is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MetaModel 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MetaModel. If not, see .
*/
package dk.eobjects.metamodel.schema;
import java.io.Serializable;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* Represents a column and it's metadata description. Columns reside within a
* Table and can be used as keys for relationships between tables.
*
* @see Table
* @see Relationship
*/
public class Column implements Serializable, Comparable {
private static final long serialVersionUID = -353183696233890927L;
private int _columnNumber;
private String _name;
private ColumnType _type;
private Table _table;
private Boolean _nullable = null;
private String _remarks;
private boolean _indexed = false;
private Integer _columnSize = null;
private String _nativeType = null;
private String _quoteString = null;
public Column() {
}
public Column(String name) {
this();
setName(name);
}
public Column(String name, ColumnType type) {
this(name);
setType(type);
}
public Column(String name, ColumnType type, Table table, int columnNumber,
Boolean nullable) {
this(name, type);
setColumnNumber(columnNumber);
setTable(table);
setNullable(nullable);
}
/**
* Returns the column number or index. Note: This column number is 0-based
* whereas the JDBC is 1-based.
*/
public int getColumnNumber() {
return _columnNumber;
}
public Column setColumnNumber(int columnNumber) {
_columnNumber = columnNumber;
return this;
}
/**
* Returns the Column Name
*/
public String getName() {
return _name;
}
public Column setName(String name) {
_name = name;
return this;
}
/**
* Gets the type of the column
*/
public ColumnType getType() {
return _type;
}
public Column setType(ColumnType type) {
_type = type;
return this;
}
/**
* Gets the table for which this column belong
*/
public Table getTable() {
return _table;
}
public Column setTable(Table table) {
_table = table;
return this;
}
public Boolean isNullable() {
return _nullable;
}
public Column setNullable(Boolean nullable) {
_nullable = nullable;
return this;
}
public String getRemarks() {
return _remarks;
}
public void setRemarks(String remarks) {
_remarks = remarks;
}
public Integer getColumnSize() {
return _columnSize;
}
public Column setColumnSize(Integer columnSize) {
_columnSize = columnSize;
return this;
}
public String getNativeType() {
return _nativeType;
}
public Column setNativeType(String nativeType) {
_nativeType = nativeType;
return this;
}
public boolean isIndexed() {
return _indexed;
}
public Column setIndexed(boolean indexed) {
_indexed = indexed;
return this;
}
public String getQuote() {
return _quoteString;
}
public Column setQuote(String quoteString) {
_quoteString = quoteString;
return this;
}
public String getQuotedName() {
if (_quoteString != null) {
return _quoteString + getName() + _quoteString;
}
return getName();
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("name", _name).append("columnNumber", _columnNumber)
.append("type", _type).append("nullable", _nullable).append(
"indexed", isIndexed()).append("nativeType",
_nativeType).append("columnSize", _columnSize)
.toString();
}
@Override
public int hashCode() {
HashCodeBuilder hcb = new HashCodeBuilder();
hcb.append(_columnNumber).append(_name).append(_table);
return hcb.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Column) {
Column that = (Column) obj;
EqualsBuilder eb = new EqualsBuilder().append(this.getName(),
that.getName()).append(this.getColumnNumber(),
that.getColumnNumber()).append(this.getType(),
that.getType()).append(this.isIndexed(), that.isIndexed())
.append(this.getNativeType(), that.getNativeType()).append(
this.getColumnSize(), that.getColumnSize());
if (this.getTable() != null && that.getTable() != null) {
eb.append(this.getTable().getName(), that.getTable().getName());
}
return eb.isEquals();
}
return false;
}
public int compareTo(Column that) {
CompareToBuilder ctb = new CompareToBuilder();
ctb.append(this.getColumnNumber(), that.getColumnNumber());
ctb.append(this.getTable(), that.getTable());
return ctb.toComparison();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy