001: /*
002: * This is free software, licensed under the Gnu Public License (GPL)
003: * get a copy from <http://www.gnu.org/licenses/gpl.html>
004: * @version $Id: Column.java,v 1.3 2004/03/07 14:22:02 hzeller Exp $
005: * @author <a href="mailto:martin.grotzke@javakaffee.de">Martin Grotzke</a>
006: */
007: package henplus.sqlmodel;
008:
009: /**
010: * Represents the meta data for a telational table Column
011: *
012: * @author Martin Grotzke
013: */
014: public final class Column implements Comparable {
015: private String _name;
016: private int _position; // starting at 1
017: private String _type;
018: private int _size;
019: private boolean _nullable;
020: private String _default;
021: private ColumnPkInfo _pkInfo;
022: private ColumnFkInfo _fkInfo;
023:
024: public Column(String name) {
025: _name = name;
026: }
027:
028: public String getName() {
029: return _name;
030: }
031:
032: public void setName(String string) {
033: _name = string;
034: }
035:
036: public String getDefault() {
037: return _default;
038: }
039:
040: public String getType() {
041: return _type;
042: }
043:
044: /**
045: * Set the default value for this Column.
046: * @param defaultValue
047: */
048: public void setDefault(String defaultValue) {
049: _default = defaultValue;
050: }
051:
052: public void setType(String string) {
053: _type = string;
054: }
055:
056: public int getSize() {
057: return _size;
058: }
059:
060: public void setSize(int i) {
061: _size = i;
062: }
063:
064: public boolean isNullable() {
065: return _nullable;
066: }
067:
068: public void setNullable(boolean b) {
069: _nullable = b;
070: }
071:
072: public int getPosition() {
073: return _position;
074: }
075:
076: public void setPosition(int i) {
077: _position = i;
078: }
079:
080: public boolean isPartOfPk() {
081: return _pkInfo != null;
082: }
083:
084: public ColumnPkInfo getPkInfo() {
085: return _pkInfo;
086: }
087:
088: public void setPkInfo(ColumnPkInfo pkInfo) {
089: _pkInfo = pkInfo;
090: }
091:
092: public boolean isForeignKey() {
093: return _fkInfo != null;
094: }
095:
096: public ColumnFkInfo getFkInfo() {
097: return _fkInfo;
098: }
099:
100: public void setFkInfo(ColumnFkInfo info) {
101: _fkInfo = info;
102: }
103:
104: /*
105: * Compares both <code>Column</code>s according to their position.
106: * @see java.lang.Comparable#compareTo(java.lang.Object)
107: */
108: public int compareTo(Object o) {
109: int result = 1;
110: Column other = (Column) o;
111: if (other.getPosition() < _position)
112: result = -1;
113: else if (other.getPosition() == _position)
114: result = 0;
115: return result;
116: }
117:
118: /**
119: *
120: * @param o
121: * @param colNameIgnoreCase specifies if column names shall be compared in a case insensitive way.
122: * @return if the columns are equal
123: */
124: public boolean equals(Object o, boolean colNameIgnoreCase) {
125: if (o instanceof Column) {
126: Column other = (Column) o;
127:
128: if (_size != other._size)
129: return false;
130:
131: // ignore the position, it's not important
132: /*
133: if (_position != other._position)
134: return false;
135: */
136:
137: if (_nullable != other._nullable)
138: return false;
139:
140: if ((_name == null && other._name != null)
141: || (_name != null && (colNameIgnoreCase
142: && !_name.equalsIgnoreCase(other._name) || !colNameIgnoreCase
143: && !_name.equals(other._name))))
144: return false;
145:
146: if ((_type == null && other._type != null)
147: || (_type != null && !_type.equals(other._type)))
148: return false;
149:
150: if ((_default == null && other._default != null)
151: || (_default != null && !_default
152: .equals(other._default)))
153: return false;
154:
155: if ((_pkInfo == null && other._pkInfo != null)
156: || (_pkInfo != null && !_pkInfo
157: .equals(other._pkInfo)))
158: return false;
159:
160: if ((_fkInfo == null && other._fkInfo != null)
161: || (_fkInfo != null && !_fkInfo
162: .equals(other._fkInfo)))
163: return false;
164:
165: }
166: return true;
167: }
168:
169: }
|