- Timestamp:
- 02/04/10 21:56:24 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MetadataBeans/trunk/src/main/java/org/eobjects/metamodel/schema/Column.java
r886 r887 1 /**2 * This file is part of MetaModel.3 *4 * MetaModel is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 3 of the License, or7 * (at your option) any later version.8 *9 * MetaModel is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with MetaModel. If not, see <http://www.gnu.org/licenses/>.16 */17 1 package org.eobjects.metamodel.schema; 18 19 import java.io.Serializable;20 21 import org.apache.commons.lang.builder.CompareToBuilder;22 import org.apache.commons.lang.builder.EqualsBuilder;23 import org.apache.commons.lang.builder.HashCodeBuilder;24 import org.apache.commons.lang.builder.ToStringBuilder;25 import org.apache.commons.lang.builder.ToStringStyle;26 2 27 3 /** … … 32 8 * @see Relationship 33 9 */ 34 public class Column implements Serializable, Comparable<Column> { 35 36 private static final long serialVersionUID = -353183696233890927L; 37 private transient String _qualifiedLabel; 38 private int _columnNumber; 39 private String _name; 40 private ColumnType _type; 41 private Table _table; 42 private Boolean _nullable = null; 43 private String _remarks; 44 private boolean _indexed = false; 45 private Integer _columnSize = null; 46 private String _nativeType = null; 47 private String _quoteString = null; 48 49 public Column() { 50 } 51 52 public Column(String name) { 53 this(); 54 setName(name); 55 } 56 57 public Column(String name, ColumnType type) { 58 this(name); 59 setType(type); 60 } 61 62 public Column(String name, ColumnType type, Table table, int columnNumber, 63 Boolean nullable) { 64 this(name, type); 65 setColumnNumber(columnNumber); 66 setTable(table); 67 setNullable(nullable); 68 } 10 public interface Column extends Comparable<Column> { 69 11 70 12 /** … … 72 14 * whereas the JDBC is 1-based. 73 15 */ 74 public int getColumnNumber() { 75 return _columnNumber; 76 } 77 78 public Column setColumnNumber(int columnNumber) { 79 _columnNumber = columnNumber; 80 return this; 81 } 16 public int getColumnNumber(); 82 17 83 18 /** 84 19 * Returns the Column Name 85 20 */ 86 public String getName() { 87 return _name; 88 } 21 public String getName(); 89 22 90 23 /** … … 96 29 * @return a qualified label 97 30 */ 98 public String getQualifiedLabel() { 99 if (_qualifiedLabel == null) { 100 StringBuilder sb = new StringBuilder(); 101 if (_table != null) { 102 sb.append(_table.getQualifiedLabel()); 103 sb.append('.'); 104 } 105 sb.append(getName()); 106 _qualifiedLabel = sb.toString(); 107 } 108 return _qualifiedLabel; 109 } 110 111 public Column setName(String name) { 112 _name = name; 113 _qualifiedLabel = null; 114 return this; 115 } 31 public String getQualifiedLabel(); 116 32 117 33 /** 118 34 * Gets the type of the column 119 35 */ 120 public ColumnType getType() { 121 return _type; 122 } 123 124 public Column setType(ColumnType type) { 125 _type = type; 126 return this; 127 } 36 public ColumnType getType(); 128 37 129 38 /** 130 39 * Gets the table for which this column belong 131 40 */ 132 public Table getTable() { 133 return _table; 134 } 41 public Table getTable(); 135 42 136 public Column setTable(Table table) { 137 _table = table; 138 _qualifiedLabel = null; 139 return this; 140 } 43 public Boolean isNullable(); 141 44 142 public Boolean isNullable() { 143 return _nullable; 144 } 45 public String getRemarks(); 145 46 146 public Column setNullable(Boolean nullable) { 147 _nullable = nullable; 148 return this; 149 } 47 public Integer getColumnSize(); 150 48 151 public String getRemarks() { 152 return _remarks; 153 } 49 public String getNativeType(); 154 50 155 public void setRemarks(String remarks) { 156 _remarks = remarks; 157 } 51 public boolean isIndexed(); 158 52 159 public Integer getColumnSize() { 160 return _columnSize; 161 } 53 public String getQuote(); 162 54 163 public Column setColumnSize(Integer columnSize) { 164 _columnSize = columnSize; 165 return this; 166 } 55 public String getQuotedName(); 167 56 168 public String getNativeType() { 169 return _nativeType; 170 } 57 public int compareTo(Column that); 171 58 172 public Column setNativeType(String nativeType) {173 _nativeType = nativeType;174 return this;175 }176 177 public boolean isIndexed() {178 return _indexed;179 }180 181 public Column setIndexed(boolean indexed) {182 _indexed = indexed;183 return this;184 }185 186 public String getQuote() {187 return _quoteString;188 }189 190 public Column setQuote(String quoteString) {191 _quoteString = quoteString;192 return this;193 }194 195 public String getQuotedName() {196 if (_quoteString != null) {197 return _quoteString + getName() + _quoteString;198 }199 return getName();200 }201 202 @Override203 public String toString() {204 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)205 .append("name", _name).append("columnNumber", _columnNumber)206 .append("type", _type).append("nullable", _nullable).append(207 "indexed", isIndexed()).append("nativeType",208 _nativeType).append("columnSize", _columnSize)209 .toString();210 }211 212 @Override213 public int hashCode() {214 HashCodeBuilder hcb = new HashCodeBuilder();215 hcb.append(_columnNumber).append(_name).append(_table);216 return hcb.toHashCode();217 }218 219 @Override220 public boolean equals(Object obj) {221 if (obj == this) {222 return true;223 }224 if (obj instanceof Column) {225 Column that = (Column) obj;226 EqualsBuilder eb = new EqualsBuilder().append(this.getName(),227 that.getName()).append(this.getColumnNumber(),228 that.getColumnNumber()).append(this.getType(),229 that.getType()).append(this.isIndexed(), that.isIndexed())230 .append(this.getNativeType(), that.getNativeType()).append(231 this.getColumnSize(), that.getColumnSize());232 if (this.getTable() != null && that.getTable() != null) {233 eb.append(this.getTable().getName(), that.getTable().getName());234 }235 return eb.isEquals();236 }237 return false;238 }239 240 public int compareTo(Column that) {241 CompareToBuilder ctb = new CompareToBuilder();242 ctb.append(this.getColumnNumber(), that.getColumnNumber());243 ctb.append(this.getTable(), that.getTable());244 return ctb.toComparison();245 }246 247 /**248 * Tells the column object that the table it belongs to have changed. This249 * is typically done if the table is being renamed or similar.250 */251 protected void fireTableChanged() {252 _qualifiedLabel = null;253 }254 59 }
Note: See TracChangeset
for help on using the changeset viewer.
