Ignore:
Timestamp:
02/04/10 21:56:24 (2 years ago)
Author:
kasper
Message:
 
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 modify 
    5  *  it under the terms of the GNU General Public License as published by 
    6  *  the Free Software Foundation, either version 3 of the License, or 
    7  *  (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 of 
    11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    12  *  GNU General Public License for more details. 
    13  * 
    14  *  You should have received a copy of the GNU General Public License 
    15  *  along with MetaModel.  If not, see <http://www.gnu.org/licenses/>. 
    16  */ 
    171package 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; 
    262 
    273/** 
     
    328 * @see Relationship 
    339 */ 
    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         } 
     10public interface Column extends Comparable<Column> { 
    6911 
    7012        /** 
     
    7214         * whereas the JDBC is 1-based. 
    7315         */ 
    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(); 
    8217 
    8318        /** 
    8419         * Returns the Column Name 
    8520         */ 
    86         public String getName() { 
    87                 return _name; 
    88         } 
     21        public String getName(); 
    8922 
    9023        /** 
     
    9629         * @return a qualified label 
    9730         */ 
    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(); 
    11632 
    11733        /** 
    11834         * Gets the type of the column 
    11935         */ 
    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(); 
    12837 
    12938        /** 
    13039         * Gets the table for which this column belong 
    13140         */ 
    132         public Table getTable() { 
    133                 return _table; 
    134         } 
     41        public Table getTable(); 
    13542 
    136         public Column setTable(Table table) { 
    137                 _table = table; 
    138                 _qualifiedLabel = null; 
    139                 return this; 
    140         } 
     43        public Boolean isNullable(); 
    14144 
    142         public Boolean isNullable() { 
    143                 return _nullable; 
    144         } 
     45        public String getRemarks(); 
    14546 
    146         public Column setNullable(Boolean nullable) { 
    147                 _nullable = nullable; 
    148                 return this; 
    149         } 
     47        public Integer getColumnSize(); 
    15048 
    151         public String getRemarks() { 
    152                 return _remarks; 
    153         } 
     49        public String getNativeType(); 
    15450 
    155         public void setRemarks(String remarks) { 
    156                 _remarks = remarks; 
    157         } 
     51        public boolean isIndexed(); 
    15852 
    159         public Integer getColumnSize() { 
    160                 return _columnSize; 
    161         } 
     53        public String getQuote(); 
    16254 
    163         public Column setColumnSize(Integer columnSize) { 
    164                 _columnSize = columnSize; 
    165                 return this; 
    166         } 
     55        public String getQuotedName(); 
    16756 
    168         public String getNativeType() { 
    169                 return _nativeType; 
    170         } 
     57        public int compareTo(Column that); 
    17158 
    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         @Override 
    203         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         @Override 
    213         public int hashCode() { 
    214                 HashCodeBuilder hcb = new HashCodeBuilder(); 
    215                 hcb.append(_columnNumber).append(_name).append(_table); 
    216                 return hcb.toHashCode(); 
    217         } 
    218  
    219         @Override 
    220         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. This 
    249          * is typically done if the table is being renamed or similar. 
    250          */ 
    251         protected void fireTableChanged() { 
    252                 _qualifiedLabel = null; 
    253         } 
    25459} 
Note: See TracChangeset for help on using the changeset viewer.