001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.framework.model;
042:
043: import org.netbeans.modules.sql.framework.model.DBColumn;
044: import java.util.List;
045:
046: /**
047: * Interface describing primary-key metadata for data sources providing information
048: * in a database or database-like format. Implementing classes must support the
049: * Cloneable interface.
050: *
051: * @author Jonathan Giron
052: * @version $Revision$
053: */
054: public interface PrimaryKey extends Cloneable {
055:
056: /**
057: * Gets (optional) name of this primary key.
058: *
059: * @return name of PK, or null if none was defined
060: */
061: public String getName();
062:
063: /**
064: * Gets reference to DBTable that owns this primary key.
065: *
066: * @return parent DBTable
067: */
068: public DBTable getParent();
069:
070: /**
071: * Gets read-only List of Strings (in key sequence order)
072: * representing names of columns referenced in this PrimaryKey.
073: *
074: * @return List of ColumnReference instances
075: */
076: public List<String> getColumnNames();
077:
078: /**
079: * Gets count of columns participating in this PrimaryKey.
080: *
081: * @return column count
082: */
083: public int getColumnCount();
084:
085: /**
086: * Gets ordinal (base-one) sequence of the column referenced by the given
087: * columnName in this PrimaryKey, provided the column is actually part of
088: * this PK. The return value ranges from 1 (first column) to n, where
089: * n is the total number of columns in this PrimaryKey, or -1 if the
090: * column referenced by given columnName is not part of this PrimaryKey.
091: *
092: * @param columnName name of column whose sequence is requested
093: * @return ordinal sequence of column referenced by columnName, starting
094: * with 1 if the column is the first in a composite key; -1 if the column
095: * is not part of this PrimaryKey
096: */
097: public int getSequence(String columnName);
098:
099: /**
100: * Gets ordinal (base-one) sequence of the given DBColumn, provided it is
101: * participating in this PK. The return value ranges from 1 (first column)
102: * to n, where n is the total number of columns in this PrimaryKey, or
103: * -1 if col is not part of the PrimaryKey.
104: *
105: * @param col DBColumn whose sequence is requested
106: * @return ordinal sequence of col, starting with 1 if the column is the
107: * first in this (composite) key; -1 if col does not participate in this
108: * PrimaryKey
109: */
110: public int getSequence(DBColumn col);
111:
112: /**
113: * Gets name of the DBColumn positioned as the iColumn-th column, if any,
114: * participating in this PrimaryKey. iColumn ranges from 1 (first column)
115: * to n, where n is the total number of columns in this PrimaryKey.
116: *
117: * @param iColumn index of column whose name is requested
118: * @return name of iColumn-th DBColumn in this PrimaryKey, or null if no
119: * column exists at the given position.
120: */
121: public String getDBColumnName(int iColumn);
122:
123: /**
124: * Indicates whether this primary key contains the column represented by
125: * the given name.
126: *
127: * @param columnName name of column to test
128: * @return true if this PrimaryKey contains the column referenced by
129: * columnName, false otherwise.
130: */
131: public boolean contains(String columnName);
132:
133: /**
134: * Indicates whether this primary key contains the given column.
135: *
136: * @param col DBColumn to test
137: * @return true if this PrimaryKey contains col, false otherwise
138: */
139: public boolean contains(DBColumn col);
140:
141: /**
142: * Indicates whether this PrimaryKey is referenced by the given ForeignKey.
143: *
144: * @param fk ForeignKey whose references are to be tested.
145: * @return true if fk references this PrimaryKey, false otherwise.
146: */
147: public boolean isReferencedBy(ForeignKey fk);
148: }
|