001: package net.sourceforge.squirrel_sql.plugins.graph;
002:
003: import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.ColumnInfoXmlBean;
004:
005: public class ColumnInfo extends Object {
006: private String _columnName;
007: private String _columnType;
008: private int _columnSize;
009: private int _decimalDigits;
010: private boolean _nullable;
011: private int _index;
012: private String _importedFromTable;
013: private String _importedColumn;
014:
015: private String _toString;
016: private String _constraintName;
017: private boolean _isPrimaryKey;
018:
019: public ColumnInfo(String columnName, String columnType,
020: int columnSize, int decimalDigits, boolean nullable) {
021: _columnName = columnName;
022: _columnType = columnType;
023: _columnSize = columnSize;
024: _decimalDigits = decimalDigits;
025: _nullable = nullable;
026:
027: String decimalDigitsString = 0 == _decimalDigits ? "" : ","
028: + _decimalDigits;
029:
030: _toString = _columnName + " " + _columnType + "("
031: + _columnSize + decimalDigitsString + ") "
032: + (_nullable ? "NULL" : "NOT NULL");
033: }
034:
035: public ColumnInfo(ColumnInfoXmlBean xmlBean) {
036: this (xmlBean.getColumnName(), xmlBean.getColumnType(), xmlBean
037: .getColumnSize(), xmlBean.getDecimalDigits(), xmlBean
038: .isNullable());
039: _index = xmlBean.getIndex();
040: if (xmlBean.isPrimaryKey()) {
041: markPrimaryKey();
042: }
043:
044: if (null != xmlBean.getImportedFromTable()) {
045: setImportData(xmlBean.getImportedFromTable(), xmlBean
046: .getImportedColumn(), xmlBean.getConstraintName());
047: }
048:
049: }
050:
051: public ColumnInfoXmlBean getXmlBean() {
052: ColumnInfoXmlBean ret = new ColumnInfoXmlBean();
053: ret.setColumnName(_columnName);
054: ret.setColumnType(_columnType);
055: ret.setColumnSize(_columnSize);
056: ret.setDecimalDigits(_decimalDigits);
057: ret.setNullable(_nullable);
058: ret.setIndex(_index);
059: ret.setImportedFromTable(_importedFromTable);
060: ret.setImportedColumn(_importedColumn);
061: ret.setConstraintName(_constraintName);
062: ret.setPrimaryKey(_isPrimaryKey);
063:
064: return ret;
065: }
066:
067: public String toString() {
068: return _toString;
069: }
070:
071: public String getName() {
072: return _columnName;
073: }
074:
075: public void setImportData(String importedFromTable,
076: String importedColumn, String constraintName) {
077: _importedFromTable = importedFromTable;
078: _importedColumn = importedColumn;
079: _constraintName = constraintName;
080: _toString += " (FK)";
081:
082: }
083:
084: public boolean isImportedFrom(String tableName) {
085: return tableName.equals(_importedFromTable);
086: }
087:
088: public String getConstraintName() {
089: return _constraintName;
090: }
091:
092: public int getIndex() {
093: return _index;
094: }
095:
096: public String getImportedColumnName() {
097: return _importedColumn;
098: }
099:
100: public void markPrimaryKey() {
101: _isPrimaryKey = true;
102: _toString += " (PK)";
103: }
104:
105: public boolean isPrimaryKey() {
106: return _isPrimaryKey;
107: }
108:
109: public void setIndex(int index) {
110: _index = index;
111: }
112:
113: public String getConstraintToolTipText() {
114: if (null == _importedFromTable) {
115: return null;
116: }
117:
118: return _importedFromTable + "." + _importedColumn + " ("
119: + _constraintName + ")";
120: }
121:
122: public String getImportedTableName() {
123: return _importedFromTable;
124: }
125:
126: }
|