001: package net.sourceforge.squirrel_sql.fw.sql;
002:
003: /*
004: * Copyright (C) 2001 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.util.SortedSet;
022: import java.util.TreeSet;
023:
024: public class TableInfo extends DatabaseObjectInfo implements ITableInfo {
025: static final long serialVersionUID = -3184857504910012169L;
026:
027: /** Table Type. */
028: private final String _tableType;
029:
030: /** Table remarks. */
031: private final String _remarks;
032:
033: private SortedSet<ITableInfo> _childList; // build up datastructure.
034: private ITableInfo[] _childs; // final cache.
035:
036: ForeignKeyInfo[] exportedKeys = null;
037: ForeignKeyInfo[] importedKeys = null;
038:
039: public TableInfo(String catalog, String schema, String simpleName,
040: String tableType, String remarks, ISQLDatabaseMetaData md) {
041: super (catalog, schema, simpleName, getTableType(tableType), md);
042: _remarks = remarks;
043: _tableType = tableType;
044: }
045:
046: private static DatabaseObjectType getTableType(String tableType) {
047: if (null == tableType) {
048: return DatabaseObjectType.TABLE;
049: } else if (false == tableType.equalsIgnoreCase("TABLE")
050: && false == tableType.equalsIgnoreCase("VIEW")) {
051: return DatabaseObjectType.TABLE;
052: } else {
053: return tableType.equalsIgnoreCase("VIEW") ? DatabaseObjectType.VIEW
054: : DatabaseObjectType.TABLE;
055: }
056: }
057:
058: // TODO: Rename this to getTableType.
059: public String getType() {
060: return _tableType;
061: }
062:
063: public String getRemarks() {
064: return _remarks;
065: }
066:
067: public boolean equals(Object obj) {
068: if (super .equals(obj) && obj instanceof TableInfo) {
069: TableInfo info = (TableInfo) obj;
070: if ((info._tableType == null && _tableType == null)
071: || ((info._tableType != null && _tableType != null) && info._tableType
072: .equals(_tableType))) {
073: return ((info._remarks == null && _remarks == null) || ((info._remarks != null && _remarks != null) && info._remarks
074: .equals(_remarks)));
075: }
076: }
077: return false;
078: }
079:
080: void addChild(ITableInfo tab) {
081: if (_childList == null) {
082: _childList = new TreeSet<ITableInfo>();
083: }
084: _childList.add(tab);
085: }
086:
087: public ITableInfo[] getChildTables() {
088: if (_childs == null && _childList != null) {
089: _childs = _childList.toArray(new ITableInfo[_childList
090: .size()]);
091: _childList = null;
092: }
093: return _childs;
094: }
095:
096: /* (non-Javadoc)
097: * @see net.sourceforge.squirrel_sql.fw.sql.ITableInfo#getExportedKeys()
098: */
099: public ForeignKeyInfo[] getExportedKeys() {
100: return exportedKeys;
101: }
102:
103: public void setExportedKeys(ForeignKeyInfo[] foreignKeys) {
104: exportedKeys = foreignKeys;
105: }
106:
107: /* (non-Javadoc)
108: * @see net.sourceforge.squirrel_sql.fw.sql.ITableInfo#getImportedKeys()
109: */
110: public ForeignKeyInfo[] getImportedKeys() {
111: return importedKeys;
112: }
113:
114: public void setImportedKeys(ForeignKeyInfo[] foreignKeys) {
115: importedKeys = foreignKeys;
116: }
117:
118: }
|