etl.editor/src/org/netbeans/modules/sql/framework/model/impl/AbstractDBTable.java
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28 * Microsystems, Inc. All Rights Reserved.
30 * If you wish your version of this file to be governed by only the CDDL
31 * or only the GPL Version 2, indicate your decision by adding
32 * "[Contributor] elects to include this software in this distribution
33 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34 * single choice of license, a recipient has the option to distribute
35 * your version of this file under either the CDDL, the GPL Version 2 or
36 * to extend the choice of license to its licensees as provided above.
37 * However, if you add GPL Version 2 code and therefore, elected the GPL
38 * Version 2 license, then the option applies only if the new code is
39 * made subject to such option by the copyright holder.
41 package org.netbeans.modules.sql.framework.model.impl;
43 import java.util.ArrayList;
44 import java.util.Collection;
45 import java.util.Collections;
46 import java.util.Comparator;
47 import java.util.HashMap;
48 import java.util.HashSet;
49 import java.util.Iterator;
50 import java.util.List;
54 import org.netbeans.modules.sql.framework.model.DBColumn;
55 import org.netbeans.modules.sql.framework.common.utils.NativeColumnOrderComparator;
56 import org.netbeans.modules.sql.framework.model.GUIInfo;
57 import org.netbeans.modules.sql.framework.model.SQLDBColumn;
58 import org.netbeans.modules.sql.framework.model.SQLDBModel;
59 import org.netbeans.modules.sql.framework.model.SQLDBTable;
60 import org.netbeans.modules.sql.framework.model.SQLObject;
61 import org.w3c.dom.Element;
62 import org.w3c.dom.NodeList;
64 import com.sun.sql.framework.exception.BaseException;
65 import com.sun.sql.framework.utils.StringUtil;
66 import java.util.LinkedHashMap;
67 import org.netbeans.modules.sql.framework.model.DBTable;
68 import org.netbeans.modules.sql.framework.model.DatabaseModel;
69 import org.netbeans.modules.sql.framework.model.ForeignKey;
70 import org.netbeans.modules.sql.framework.model.Index;
71 import org.netbeans.modules.sql.framework.model.PrimaryKey;
74 * Abstract implementation for org.netbeans.modules.model.database.DBTable and SQLObject interfaces.
76 * @author Sudhendra Seshachala, Jonathan Giron
79 public abstract class AbstractDBTable extends AbstractSQLObject implements SQLDBTable {
81 static class StringComparator implements Comparator {
82 public int compare(Object o1, Object o2) {
83 if (o1 instanceof String && o2 instanceof String) {
84 return ((String) o1).compareTo((String) o2);
86 throw new ClassCastException("StringComparator cannot compare non-String objects.");
90 /** Attribute name for commit batch size. */
91 protected static final String ATTR_COMMIT_BATCH_SIZE = "commitBatchSize";
93 /** String constant for table catalog name attribute. */
94 protected static final String CATALOG_NAME_ATTR = "catalog"; // NOI18N
96 /** String constants for dbTableRef tag. */
97 protected static final String DB_TABLE_REF = "dbTableRef"; // NOI18N
99 /** String constant for table name attribute. */
100 protected static final String DISPLAY_NAME_ATTR = "displayName"; // NOI18N
102 /** String constant for table ID attribute. */
103 protected static final String ID_ATTR = "id"; // NOI18N
105 /** String to use in prefixing each line of a generated XML document */
106 protected static final String INDENT = "\t";
108 /** Initial buffer size for StringBuilder used in marshalling SQLTable to XML */
109 protected static final int INIT_XMLBUF_SIZE = 500;
111 /** Constant for column model name tag. */
112 protected static final String MODEL_NAME_TAG = "dbModelName"; // NOI18N
114 /** String onstant for table schema attribute. */
115 protected static final String SCHEMA_NAME_ATTR = "schema"; // NOI18N
117 /** String constant for table name attribute. */
118 protected static final String TABLE_NAME_ATTR = "name"; // NOI18N
120 private static final String ATTR_ALIAS_NAME = "aliasName";
122 private static final String ATTR_FLATFILE_LOCATION_RUNTIME_INPUT_NAME = "flatFileLocationRuntimeInputName";
124 private static final String ATTR_TABLE_PREFIX = "tablePrefix";
126 private static final String ATTR_USERDEFINED_CATALOG_NAME = "userDefinedCatalogName";
128 private static final String ATTR_USERDEFINED_SCHEMA_NAME = "userDefinedSchemaName";
130 private static final String ATTR_USERDEFINED_TABLE_NAME = "userDefinedTableName";
132 private static final String ATTR_USING_FULLYQUALIFIED_NAME = "usingFullyQualifiedName";
134 private static final int DEFAULT_COMMIT_BATCH_SIZE = 5000;
136 private static final String FQ_TBL_NAME_SEPARATOR = ".";
139 private static final String ATTR_STAGING_TABLE_NAME = "stagingTableName";
141 /** use alias is required : transient variable */
142 protected boolean aliasUsed = false;
144 /** catalog to which this table belongs. */
145 protected String catalog;
147 /** Map of column metadata. */
148 protected Map<String, DBColumn> columns;
150 /** User-defined description. */
151 protected String description;
153 protected boolean editable = true;
155 /** Map of names to ForeignKey instances for this table; may be empty. */
156 protected Map<String, ForeignKey> foreignKeys;
158 /** Contains UI state information */
159 protected GUIInfo guiInfo;
161 /** Map of names to Index instances for this table; may be empty. */
162 protected Map<String, Index> indexes;
164 /** Table name as supplied by data source. */
165 protected String name;
167 protected boolean overrideCatalogName = false;
169 protected String overridenCatalogName = null;
171 protected String overridenSchemaName = null;
172 protected boolean overrideSchemaName = false;
174 /** Model instance that "owns" this table */
175 protected DatabaseModel parentDBModel;
176 /** PrimaryKey for this table; may be null. */
177 protected PrimaryKeyImpl primaryKey;
178 /** schema to which this table belongs. */
179 protected String schema;
181 protected boolean selected;
183 /** No-arg constructor; initializes Collections-related member variables. */
184 protected AbstractDBTable() {
185 columns = new LinkedHashMap<String, DBColumn>();
186 foreignKeys = new HashMap<String, ForeignKey>();
187 indexes = new HashMap<String, Index>();
188 guiInfo = new GUIInfo();
189 setDefaultAttributes();
193 * Creates a new instance of AbstractDBTable, cloning the contents of the given
194 * DBTable implementation instance.
196 * @param src DBTable instance to be 43d
198 protected AbstractDBTable(DBTable src) {
202 throw new IllegalArgumentException("Must supply non-null DBTable instance for src param.");
208 * Creates a new instance of AbstractDBTable with the given name.
210 * @param aName name of new DBTable instance
211 * @param aSchema schema of new DBTable instance; may be null
212 * @param aCatalog catalog of new DBTable instance; may be null
214 protected AbstractDBTable(String aName, String aSchema, String aCatalog) {
217 name = (aName != null) ? aName.trim() : null;
218 schema = (aSchema != null) ? aSchema.trim() : null;
219 catalog = (aCatalog != null) ? aCatalog.trim() : null;
223 * Adds an AbstractDBColumn instance to this table.
225 * @param theColumn column to be added.
226 * @return true if successful. false if failed.
228 public boolean addColumn(SQLDBColumn theColumn) {
229 if (theColumn != null) {
230 theColumn.setParent(this);
231 columns.put(theColumn.getName(), theColumn);
239 * Adds the given ForeignKeyImpl, associating it with this AbstractDBTable instance.
241 * @param newFk new ForeignKeyImpl instance to be added
242 * @return return true if addition succeeded, false otherwise
244 public boolean addForeignKey(ForeignKeyImpl newFk) {
246 newFk.setParent(this);
247 foreignKeys.put(newFk.getName(), newFk);
254 * Adds the given IndexImpl, associating it with this AbstractDBTable instance.
256 * @param newIndex new IndexImpl instance to be added
257 * @return return true if addition succeeded, false otherwise
259 public boolean addIndex(IndexImpl newIndex) {
260 if (newIndex != null) {
261 newIndex.setParent(this);
262 indexes.put(newIndex.getName(), newIndex);
270 * Clears list of foreign keys.
272 public void clearForeignKeys() {
277 * Clears list of indexes.
279 public void clearIndexes() {
283 public void clearOverride(boolean clearCatalogOverride, boolean clearSchemaOverride) {
284 if (clearCatalogOverride) {
285 this.overrideCatalogName = false;
286 this.overridenCatalogName = null;
289 if (clearSchemaOverride) {
290 this.overrideSchemaName = false;
291 this.overridenSchemaName = null;
296 * Compares DBTable with another object for lexicographical ordering. Null objects and
297 * those DBTables with null names are placed at the end of any ordered collection
300 * @param refObj Object to be compared.
301 * @return -1 if the column name is less than obj to be compared. 0 if the column name
302 * is the same. 1 if the column name is greater than obj to be compared.
304 public int compareTo(Object refObj) {
305 if (refObj == null) {
309 if (refObj == this) {
313 String refName = (parentDBModel != null) ? parentDBModel.getFullyQualifiedTableName((DBTable) refObj) : ((DBTable) refObj).getName();
315 String myName = (parentDBModel != null) ? parentDBModel.getFullyQualifiedTableName(this) : name;
317 return (myName != null) ? myName.compareTo(refName) : (refName != null) ? 1 : -1;
321 * Sets the various member variables and collections using the given DBTable instance
322 * as a source object. Concrete implementations should override this method, call
323 * super.copyFrom(DBColumn) to pick up member variables defined in this class and then
324 * implement its own logic for copying member variables defined within itself.
326 * @param source DBTable from which to obtain values for member variables and
329 public void copyFrom(DBTable source) {
330 if (source == null) {
331 throw new IllegalArgumentException("Must supply non-null ref for source");
332 } else if (source == this) {
336 name = source.getName();
337 description = source.getDescription();
338 schema = source.getSchema();
339 catalog = source.getCatalog();
341 parentDBModel = source.getParent();
343 if (source instanceof SQLDBTable) {
344 SQLDBTable abstractTbl = (SQLDBTable) source;
345 super.copyFromSource(abstractTbl);
346 displayName = abstractTbl.getDisplayName();
347 guiInfo = abstractTbl.getGUIInfo();
348 aliasUsed = abstractTbl.isAliasUsed();
351 deepCopyReferences(source);
355 * Deletes all columns associated with this table.
357 * @return true if all columns were deleted successfully, false otherwise.
359 public boolean deleteAllColumns() {
365 * Deletes DBColumn, if any, associated with the given name from this table.
367 * @param columnName column name to be removed.
368 * @return true if successful. false if failed.
370 public boolean deleteColumn(String columnName) {
371 if (columnName != null && columnName.trim().length() != 0) {
372 return (columns.remove(columnName) != null);
378 * Overrides default implementation to return value based on memberwise comparison.
380 * @param obj Object against which we compare this instance
381 * @return true if obj is functionally identical to this SQLTable instance; false
385 public boolean equals(Object obj) {
386 boolean result = false;
388 // Check for reflexivity first.
392 if (!(obj instanceof SQLDBTable)) {
396 result = super.equals(obj);
402 SQLDBTable target = (SQLDBTable) obj;
404 // since now we allow duplicate source tables we need to check the id and if id
405 // is not equal then table is not equal
406 result &= target.getId() != null ? target.getId().equals(this.getId()) : this.getId() == null;
408 // Check for castability (also deals with null obj)
409 if (obj instanceof DBTable) {
410 DBTable aTable = (DBTable) obj;
411 String aTableName = aTable.getName();
412 DatabaseModel aTableParent = aTable.getParent();
413 Map<String, DBColumn> aTableColumns = aTable.getColumns();
414 PrimaryKey aTablePK = aTable.getPrimaryKey();
415 List<ForeignKey> aTableFKs = aTable.getForeignKeys();
416 List<Index> aTableIdxs = aTable.getIndexes();
418 result &= (aTableName != null && name != null && name.equals(aTableName))
419 && (parentDBModel != null && aTableParent != null && parentDBModel.equals(aTableParent));
421 if (columns != null && aTableColumns != null) {
422 Set<String> objCols = aTableColumns.keySet();
423 Set<String> myCols = columns.keySet();
425 // Must be identical (no subsetting), hence the pair of tests.
426 result &= myCols.containsAll(objCols) && objCols.containsAll(myCols);
427 } else if (!(columns == null && aTableColumns == null)) {
431 result &= (primaryKey != null) ? primaryKey.equals(aTablePK) : aTablePK == null;
433 if (foreignKeys != null && aTableFKs != null) {
434 Collection<ForeignKey> myFKs = foreignKeys.values();
435 // Must be identical (no subsetting), hence the pair of tests.
436 result &= myFKs.containsAll(aTableFKs) && aTableFKs.containsAll(myFKs);
437 } else if (!(foreignKeys == null && aTableFKs == null)) {
441 if (indexes != null && aTableIdxs != null) {
442 Collection<Index> myIdxs = indexes.values();
443 // Must be identical (no subsetting), hence the pair of tests.
444 result &= myIdxs.containsAll(aTableIdxs) && aTableIdxs.containsAll(myIdxs);
445 } else if (!(indexes == null && aTableIdxs == null)) {
453 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getAliasName()
455 public String getAliasName() {
456 return (String) this.getAttributeObject(ATTR_ALIAS_NAME);
460 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getBatchSize()
462 public int getBatchSize() {
463 Integer batchSize = (Integer) this.getAttributeObject(ATTR_COMMIT_BATCH_SIZE);
464 return (batchSize != null) ? batchSize.intValue() : DEFAULT_COMMIT_BATCH_SIZE;
468 * @see org.netbeans.modules.model.database.DBTable#getCatalog
470 public String getCatalog() {
475 * Gets List of child SQLObjects belonging to this instance.
477 * @return List of child SQLObjects
480 public List<DBColumn> getChildSQLObjects() {
481 return this.getColumnList();
485 * Gets the DBColumn, if any, associated with the given name
487 * @param columnName column name
488 * @return DBColumn associated with columnName, or null if none exists
490 public DBColumn getColumn(String columnName) {
491 return columns.get(columnName);
495 * @see org.netbeans.modules.model.database.DBTable#getColumnList
497 public List<DBColumn> getColumnList() {
498 List<DBColumn> list = new ArrayList<DBColumn>();
499 list.addAll(columns.values());
500 Collections.sort(list, NativeColumnOrderComparator.getInstance());
506 * @see org.netbeans.modules.model.database.DBTable#getColumns
508 public Map<String, DBColumn> getColumns() {
513 * @see org.netbeans.modules.model.database.DBTable#getDescription
515 public String getDescription() {
522 * @return display name
525 public String getDisplayName() {
526 return this.getQualifiedName();
530 * Gets the flat file location runtime input name which is generate when a flat file
531 * table is added to collaboration. use this name at runtime for file location passed
534 * @return String representing flatfile location runtime input name
536 public String getFlatFileLocationRuntimeInputName() {
537 return (String) this.getAttributeObject(ATTR_FLATFILE_LOCATION_RUNTIME_INPUT_NAME);
541 * @see org.netbeans.modules.model.database.DBTable#getForeignKey(java.lang.String)
543 public ForeignKey getForeignKey(String fkName) {
544 return foreignKeys.get(fkName);
548 * @see org.netbeans.modules.model.database.DBTable#getForeignKeys
550 public List<ForeignKey> getForeignKeys() {
551 return new ArrayList<ForeignKey>(foreignKeys.values());
555 * get table fully qualified name including schema , catalog info
557 * @return fully qualified table name prefixed with alias
559 public String getFullyQualifiedName() {
561 String tblName = getName();
562 String schName = getSchema();
563 String catName = getCatalog();
565 if (tblName == null) {
566 throw new IllegalArgumentException("can not construct fully qualified table name, table name is null.");
569 StringBuilder buf = new StringBuilder(50);
571 if (catName != null && catName.trim().length() != 0) {
572 buf.append(catName.trim());
573 buf.append(FQ_TBL_NAME_SEPARATOR);
576 if (schName != null && schName.trim().length() != 0) {
577 buf.append(schName.trim());
578 buf.append(FQ_TBL_NAME_SEPARATOR);
581 buf.append(tblName.trim());
583 return buf.toString();
587 * @see SQLCanvasObject#getGUIInfo
589 public GUIInfo getGUIInfo() {
594 * @see org.netbeans.modules.model.database.DBTable#getIndex
596 public Index getIndex(String indexName) {
597 return indexes.get(indexName);
601 * @see org.netbeans.modules.model.database.DBTable#getIndexes
603 public List<Index> getIndexes() {
604 return new ArrayList<Index>(indexes.values());
608 * @see org.netbeans.modules.model.database.DBTable#getName
610 public synchronized String getName() {
615 * Get specified SQL object
617 * @param objectId - object ID
620 public SQLObject getObject(String objectId) {
621 List list = this.getColumnList();
622 Iterator it = list.iterator();
624 while (it.hasNext()) {
625 SQLDBColumn dbColumn = (SQLDBColumn) it.next();
626 // if looking for table then return table
627 if (objectId.equals(dbColumn.getId())) {
635 * @see org.netbeans.modules.model.database.DBTable#getParent
637 public DatabaseModel getParent() {
638 return parentDBModel;
642 * @see org.netbeans.modules.model.database.DBTable#getPrimaryKey
644 public PrimaryKey getPrimaryKey() {
649 * get table qualified name
651 * @return qualified table name prefixed with alias
653 public String getQualifiedName() {
654 StringBuilder buf = new StringBuilder(50);
655 String aName = this.getAliasName();
656 if (aName != null && !aName.trim().equals("")) {
660 buf.append(this.getName());
662 buf.append(this.getFullyQualifiedName());
665 return buf.toString();
669 * @see org.netbeans.modules.model.database.DBTable#getReferencedTables
671 public Set getReferencedTables() {
672 List keys = getForeignKeys();
673 Set<DBTable> tables = new HashSet<DBTable>(keys.size());
675 if (keys.size() != 0) {
676 Iterator iter = keys.iterator();
677 while (iter.hasNext()) {
678 ForeignKeyImpl fk = (ForeignKeyImpl) iter.next();
679 DBTable pkTable = parentDBModel.getTable(fk.getPKTable(), fk.getPKSchema(), fk.getPKCatalog());
680 if (pkTable != null && fk.references(pkTable.getPrimaryKey())) {
685 if (tables.size() == 0) {
687 tables = Collections.emptySet();
695 * @see org.netbeans.modules.model.database.DBTable#getReferenceFor
697 public ForeignKey getReferenceFor(DBTable target) {
698 if (target == null) {
702 PrimaryKey targetPK = target.getPrimaryKey();
703 if (targetPK == null) {
707 Iterator iter = foreignKeys.values().iterator();
708 while (iter.hasNext()) {
709 ForeignKey myFK = (ForeignKey) iter.next();
710 if (myFK.references(targetPK)) {
718 public String getRuntimeArgumentName() {
719 return this.getFlatFileLocationRuntimeInputName();
723 * @see org.netbeans.modules.model.database.DBTable#getSchema
725 public String getSchema() {
730 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getTablePrefix()
732 public String getTablePrefix() {
733 return (String) this.getAttributeObject(ATTR_TABLE_PREFIX);
738 * Gets the staging table name.
740 * @return staging table name
742 public String getStagingTableName() {
743 return (String) this.getAttributeObject(ATTR_STAGING_TABLE_NAME);
747 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getUniqueTableName()
749 public String getUniqueTableName() {
750 // Use alias name + given name to make this name consistent with the existing
751 // name formats used in 5.0.x for flatfile runtime arguments.
752 return this.getAliasName() + "_" + this.getName();
756 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getUserDefinedCatalogName()
758 public String getUserDefinedCatalogName() {
759 if (overrideCatalogName) {
760 return overridenCatalogName;
762 return (String) this.getAttributeObject(ATTR_USERDEFINED_CATALOG_NAME);
767 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getUserDefinedSchemaName()
769 public String getUserDefinedSchemaName() {
770 if (overrideSchemaName) {
771 return overridenSchemaName;
773 return (String) this.getAttributeObject(ATTR_USERDEFINED_SCHEMA_NAME);
778 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#getUserDefinedTableName()
780 public String getUserDefinedTableName() {
781 return (String) this.getAttributeObject(ATTR_USERDEFINED_TABLE_NAME);
785 * Overrides default implementation to compute hashCode value for those members used
786 * in equals() for comparison.
788 * @return hash code for this object
789 * @see java.lang.Object#hashCode
792 public int hashCode() {
793 int myHash = super.hashCode();
794 myHash = (name != null) ? name.hashCode() : 0;
795 myHash += (parentDBModel != null) ? parentDBModel.hashCode() : 0;
796 myHash += (schema != null) ? schema.hashCode() : 0;
797 myHash += (catalog != null) ? catalog.hashCode() : 0;
799 // Include hashCodes of all column names.
800 if (columns != null) {
801 myHash += columns.keySet().hashCode();
804 if (primaryKey != null) {
805 myHash += primaryKey.hashCode();
808 if (foreignKeys != null) {
809 myHash += foreignKeys.keySet().hashCode();
812 if (indexes != null) {
813 myHash += indexes.keySet().hashCode();
816 myHash += (displayName != null) ? displayName.hashCode() : 0;
822 * @return Returns the aliasUsed.
824 public boolean isAliasUsed() {
833 public boolean isEditable() {
834 return this.editable;
837 public boolean isInputStatic(String inputName) {
846 public boolean isSelected() {
847 return this.selected;
851 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#isUsingFullyQualifiedName()
853 public boolean isUsingFullyQualifiedName() {
854 Boolean isUsing = (Boolean) getAttributeObject(ATTR_USING_FULLYQUALIFIED_NAME);
855 return (isUsing != null) ? isUsing.booleanValue() : true;
858 public void overrideCatalogName(String nName) {
859 this.overrideCatalogName = true;
860 this.overridenCatalogName = nName;
863 public void overrideSchemaName(String nName) {
864 this.overrideSchemaName = true;
865 this.overridenSchemaName = nName;
869 * Parses the XML content, if any, using the given Element as a source for
870 * reconstituting the member variables and collections of this instance.
872 * @param tableElement DOM element containing XML marshalled version of a
873 * @exception BaseException thrown while parsing XML, or if member variable element is
877 public void parseXML(Element tableElement) throws BaseException {
878 if (tableElement == null) {
879 throw new BaseException("Null ref for tableElement.");
882 if (!(tableElement.getNodeName().equals(getElementTagName()))) {
883 throw new BaseException("No <" + getElementTagName() + "> element found.");
886 super.parseXML(tableElement);
888 name = tableElement.getAttribute(TABLE_NAME_ATTR);
889 schema = tableElement.getAttribute(SCHEMA_NAME_ATTR);
890 catalog = tableElement.getAttribute(CATALOG_NAME_ATTR);
892 NodeList childNodeList = tableElement.getChildNodes();
893 parseChildren(childNodeList);
897 * @see org.netbeans.modules.model.database.DBTable#references
899 public boolean references(DBTable pkTarget) {
900 return (getReferenceFor(pkTarget) != null);
904 * Dissociates the given ForeignKeyImpl from this AbstractDBTable instance, removing
905 * it from its internal FK collection.
907 * @param oldKey new ForeignKeyImpl instance to be removed
908 * @return return true if removal succeeded, false otherwise
910 public boolean removeForeignKey(ForeignKeyImpl oldKey) {
911 if (oldKey != null) {
912 return (foreignKeys.remove(oldKey.getName()) != null);
919 * set the alias name for this table
921 * @param aName alias name
923 public void setAliasName(String aName) {
924 this.setAttribute(ATTR_ALIAS_NAME, aName);
928 * @param aliasUsed The aliasUsed to set.
930 public void setAliasUsed(boolean aliasUsed) {
931 this.aliasUsed = aliasUsed;
935 * Clones contents of the given Map to this table's internal column map, overwriting
936 * any previous mappings.
938 * @param theColumns Map of columns to be substituted
939 * @return true if successful. false if failed.
941 public boolean setAllColumns(Map<String, DBColumn> theColumns) {
943 if (theColumns != null) {
944 columns.putAll(theColumns);
949 public void setBatchSize(int newSize) {
951 newSize = DEFAULT_COMMIT_BATCH_SIZE;
954 this.setAttribute(ATTR_COMMIT_BATCH_SIZE, new Integer(newSize));
958 * Sets catalog name to new value.
960 * @param newCatalog new value for catalog name
962 public void setCatalog(String newCatalog) {
963 catalog = newCatalog;
967 * Sets description text for this instance.
969 * @param newDesc new descriptive text
971 public void setDescription(String newDesc) {
972 description = newDesc;
978 * @param edit - editable
980 public void setEditable(boolean edit) {
981 this.editable = edit;
985 * set flat file location runtime input name which is generate when a flat file table
986 * is added to collaboration
988 * @param runtimeArgName name of runtime input argument for flat file location
990 public void setFlatFileLocationRuntimeInputName(String runtimeArgName) {
991 this.setAttribute(ATTR_FLATFILE_LOCATION_RUNTIME_INPUT_NAME, runtimeArgName);
995 * Sets table name to new value.
997 * @param newName new value for table name
999 public void setName(String newName) {
1004 * Sets parentDBModel DatabaseModel to the given reference.
1006 * @param newParent new DatabaseModel parentDBModel
1008 public void setParent(SQLDBModel newParent) {
1009 parentDBModel = newParent;
1011 setParentObject(newParent);
1012 } catch (BaseException ex) {
1018 * Sets PrimaryKey instance for this DBTable to the given instance.
1020 * @param newPk new PrimaryKey instance to be associated
1021 * @return true if association succeeded, false otherwise
1023 public boolean setPrimaryKey(PrimaryKeyImpl newPk) {
1024 if (newPk != null) {
1025 newPk.setParent(this);
1032 public void setForeignKeyMap(Map<String, ForeignKey> fkMap){
1033 foreignKeys = fkMap;
1037 * Sets schema name to new value.
1039 * @param newSchema new value for schema name
1041 public void setSchema(String newSchema) {
1048 * @param sel - selected
1050 public void setSelected(boolean sel) {
1051 this.selected = sel;
1054 public void setTablePrefix(String tPrefix) {
1055 this.setAttribute(ATTR_TABLE_PREFIX, tPrefix);
1060 * Sets the staging table name.
1062 * @param stName staging table name
1064 public void setStagingTableName(String stName) {
1065 this.setAttribute(ATTR_STAGING_TABLE_NAME, stName);
1069 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#setUserDefinedCatalogName(java.lang.String)
1071 public void setUserDefinedCatalogName(String newName) {
1072 this.setAttribute(ATTR_USERDEFINED_CATALOG_NAME, newName);
1076 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#setUserDefinedSchemaName(java.lang.String)
1078 public void setUserDefinedSchemaName(String newName) {
1079 this.setAttribute(ATTR_USERDEFINED_SCHEMA_NAME, newName);
1083 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#setUserDefinedTableName(java.lang.String)
1085 public void setUserDefinedTableName(String newName) {
1086 this.setAttribute(ATTR_USERDEFINED_TABLE_NAME, newName);
1090 * @see org.netbeans.modules.sql.framework.model.SQLDBTable#setUsingFullyQualifiedName(boolean)
1092 public void setUsingFullyQualifiedName(boolean usesFullName) {
1093 this.setAttribute(ATTR_USING_FULLYQUALIFIED_NAME, (usesFullName ? Boolean.TRUE : Boolean.FALSE));
1097 * Overrides default implementation to return appropriate display name of this DBTable
1099 * @return qualified table name.
1102 public String toString() {
1103 return getQualifiedName();
1107 * @see SQLObject#toXMLString
1110 public String toXMLString(String prefix) throws BaseException {
1111 return toXMLString(prefix, false);
1115 * Returns XML representation of table metadata.
1117 * @param prefix prefix for the xml.
1118 * @param tableOnly flag for generating table only metadata.
1119 * @return XML representation of the table metadata.
1120 * @exception BaseException - exception
1122 public String toXMLString(String prefix, boolean tableOnly) throws BaseException {
1123 throw new UnsupportedOperationException("Not supported yet.");
1127 * Perform deep copy of columns.
1129 * @param source SQLTable whose columns are to be copied.
1131 protected void deepCopyReferences(DBTable source) {
1132 if (source != null && source != this) {
1134 PrimaryKey srcPk = source.getPrimaryKey();
1135 if (srcPk != null) {
1136 primaryKey = new PrimaryKeyImpl(source.getPrimaryKey());
1137 primaryKey.setParent(this);
1140 foreignKeys.clear();
1141 Iterator iter = source.getForeignKeys().iterator();
1142 while (iter.hasNext()) {
1143 ForeignKeyImpl impl = new ForeignKeyImpl((ForeignKey) iter.next());
1144 impl.setParent(this);
1145 foreignKeys.put(impl.getName(), impl);
1149 iter = source.getIndexes().iterator();
1151 while (iter.hasNext()) {
1152 IndexImpl impl = new IndexImpl((Index) iter.next());
1153 impl.setParent(this);
1154 indexes.put(impl.getName(), impl);
1158 iter = source.getColumnList().iterator();
1159 while (iter.hasNext()) {
1161 SQLDBColumn column = (SQLDBColumn) iter.next();
1162 SQLDBColumn clonedColumn = (SQLDBColumn) column.cloneSQLObject();
1163 columns.put(clonedColumn.getName(), clonedColumn);
1164 } catch (Exception ex) {
1165 // TODO Log this exception
1172 * Gets String representing tag name for this table class.
1174 * @return String representing element tag for this class
1176 protected String getElementTagName() {
1177 throw new UnsupportedOperationException("Not supported yet.");
1181 * Parses node elements to extract child components to various collections (columns,
1184 * @param childNodeList Nodes to be unmarshalled
1185 * @throws BaseException if error occurs while parsing
1187 protected void parseChildren(NodeList childNodeList) throws BaseException {
1188 throw new UnsupportedOperationException("Not supported yet.");
1192 * Sets default values for attributes defined in this abstract class.
1194 protected void setDefaultAttributes() {
1195 setUserDefinedTableName("");
1196 setUserDefinedSchemaName("");
1197 setUserDefinedCatalogName("");
1200 setUsingFullyQualifiedName(true);
1201 setStagingTableName("");
1204 public String getResolvedCatalogName() {
1205 // Ensure order of precedence for catalog name is followed.
1206 String resolvedCatalogName = getUserDefinedCatalogName();
1207 if (StringUtil.isNullString(resolvedCatalogName)) {
1208 resolvedCatalogName = getCatalog();
1210 return resolvedCatalogName;
1213 public String getResolvedSchemaName() {
1214 // Ensure order of precedence for schema name is followed.
1215 String resolvedSchemaName = getUserDefinedSchemaName();
1216 if (StringUtil.isNullString(resolvedSchemaName)) {
1217 resolvedSchemaName = getSchema();
1219 return resolvedSchemaName;
1222 public String getResolvedTableName() {
1223 // Ensure order of precedence for schema name is followed.
1224 String resolvedTableName = getUserDefinedTableName();
1225 if (StringUtil.isNullString(resolvedTableName)) {
1226 resolvedTableName = getName();
1228 return resolvedTableName;