001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: *
022: * Copyright 2005 Sun Microsystems, Inc.
023: *
024: * Licensed under the Apache License, Version 2.0 (the "License");
025: * you may not use this file except in compliance with the License.
026: * You may obtain a copy of the License at
027: *
028: * http://www.apache.org/licenses/LICENSE-2.0
029: *
030: * Unless required by applicable law or agreed to in writing, software
031: * distributed under the License is distributed on an "AS IS" BASIS,
032: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
033: * See the License for the specific language governing permissions and
034: * limitations under the License.
035: *
036: */
037: package org.netbeans.modules.jdbcwizard.builder.dbmodel;
038:
039: import java.util.List;
040:
041: /**
042: * Interface describing foreign-key metadata for data sources providing information in a database or
043: * database-like format. Implementing classes must support the Cloneable interface.
044: *
045: * @author
046: */
047: public interface ForeignKey extends Cloneable {
048:
049: /**
050: * Gets user-defined name for this Foreign Key.
051: *
052: * @return FK name
053: */
054: public String getName();
055:
056: /**
057: * Gets name, if any, of associated primary key
058: *
059: * @return name of this primary key; may be null if no name exists for the PK
060: */
061: public String getPKName();
062:
063: /**
064: * Gets read-only List of Strings (in sequential order) representing names of columns comprising
065: * this ForeignKey.
066: *
067: * @return List of column names
068: */
069: public List getColumnNames();
070:
071: /**
072: * Gets read-only List of Strings (in key sequence order) representing names of PK columns
073: * referenced by elements of this ForeignKey.
074: *
075: * @return List of PK column names referenced by this ForeignKey
076: */
077: public List getPKColumnNames();
078:
079: /**
080: * Gets name of PK column, if any, which the FK column (represented by the given column name)
081: * references.
082: *
083: * @param fkColumnName name of FK column whose referenced PK column is to be retrieved
084: * @return name of matching PK column, or null if fkColumnName is not an FK column
085: */
086: public String getMatchingPKColumn(String fkColumnName);
087:
088: /**
089: * Gets name of table containing PK columns referenced by this ForeignKey.
090: *
091: * @return PK table name
092: */
093: public String getPKTable();
094:
095: /**
096: * Gets name of schema, if any, to which PK table belongs.
097: *
098: * @return schema name for PK table; null if no schema name is defined
099: */
100: public String getPKSchema();
101:
102: /**
103: * Gets name of catalog, if any, to which PK table belongs.
104: *
105: * @return catalog name for PK table; null if no catalog name is defined
106: */
107: public String getPKCatalog();
108:
109: /**
110: * Gets reference to DBTable that owns this primary key.
111: *
112: * @return parent DBTable
113: */
114: public DBTable getParent();
115:
116: /**
117: * Gets count of columns participating in this ForeignKey.
118: *
119: * @return column count
120: */
121: public int getColumnCount();
122:
123: /**
124: * Gets name of the column positioned as the iColumn-th column, if any, participating in this
125: * ForeignKey. iColumn ranges from 1 (first column) to n, where n is the total number of columns
126: * in this ForeignKey.
127: *
128: * @param iColumn index of column whose name is requested
129: * @return name of iColumn-th DBColumn in this ForeignKey, or null if no column exists at the
130: * given position.
131: */
132: public String getColumnName(int iColumn);
133:
134: /**
135: * Gets ordinal (base-one) sequence of the given DBColumn in this FK, provided it is part of
136: * this FK. The return value ranges from 1 (first column) to n, where n is the total number of
137: * columns in this ForeignKey, or -1 if col is not part of the ForeignKey.
138: *
139: * @param col DBColumn whose sequence is requested
140: * @return ordinal sequence of col, starting with 1 if the column is the first in a composite
141: * key; -1 if col does not participate in this ForeignKey
142: */
143: public int getSequence(DBColumn col);
144:
145: /**
146: * Gets enumerated update rule associated with columns of this ForeignKey, as defined in
147: * java.sql.DatabaseMetaData.
148: *
149: * @return int value representing associated update rule
150: * @see java.sql.DatabaseMetaData
151: */
152: public int getUpdateRule();
153:
154: /**
155: * Gets enumerated delete rule associated with columns of this ForeignKey, as defined in
156: * java.sql.DatabaseMetaData.
157: *
158: * @return int value representing associated delete rule
159: * @see java.sql.DatabaseMetaData
160: */
161: public int getDeleteRule();
162:
163: /**
164: * Gets enumerated deferrability rule associated with columns of this ForeignKey, as defined in
165: * java.sql.DatabaseMetaData.
166: *
167: * @return int value representing associated deferrability rule
168: * @see java.sql.DatabaseMetaData
169: */
170: public int getDeferrability();
171:
172: /**
173: * Indicates whether this ForeignKey contains the column represented by the given name.
174: *
175: * @param fkColumnName name of column to test
176: * @return true if this ForeignKey contains the column referenced by fkColumnName, false
177: * otherwise.
178: */
179: public boolean contains(String fkColumnName);
180:
181: /**
182: * Indicates whether this ForeignKey contains the given column.
183: *
184: * @param fkCol JDBCColumn to test
185: * @return true if this ForeignKey contains fkCol, false otherwise
186: */
187: public boolean contains(DBColumn fkCol);
188:
189: /**
190: * Indicates whether this ForeignKey references columns in the DBTable represented by the given
191: * tuple of (table name, schema name, catalog name).
192: *
193: * @param pk PrimaryKey whose relationship to this FK is to be tested
194: * @return true if this FK references columns in pk; false otherwise
195: */
196: public boolean references(PrimaryKey pk);
197: }
|