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 primary-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 PrimaryKey extends Cloneable {
048:
049: /**
050: * Gets (optional) name of this primary key.
051: *
052: * @return name of PK, or null if none was defined
053: */
054: public String getName();
055:
056: /**
057: * Gets reference to DBTable that owns this primary key.
058: *
059: * @return parent DBTable
060: */
061: public DBTable getParent();
062:
063: /**
064: * Gets read-only List of Strings (in key sequence order) representing names of columns
065: * referenced in this PrimaryKey.
066: *
067: * @return List of ColumnReference instances
068: */
069: public List getColumnNames();
070:
071: /**
072: * Gets count of columns participating in this PrimaryKey.
073: *
074: * @return column count
075: */
076: public int getColumnCount();
077:
078: /**
079: * Gets ordinal (base-one) sequence of the column referenced by the given columnName in this
080: * PrimaryKey, provided the column is actually part of this PK. The return value ranges from 1
081: * (first column) to n, where n is the total number of columns in this PrimaryKey, or -1 if the
082: * column referenced by given columnName is not part of this PrimaryKey.
083: *
084: * @param columnName name of column whose sequence is requested
085: * @return ordinal sequence of column referenced by columnName, starting with 1 if the column is
086: * the first in a composite key; -1 if the column is not part of this PrimaryKey
087: */
088: public int getSequence(String columnName);
089:
090: /**
091: * Gets ordinal (base-one) sequence of the given DBColumn, provided it is participating in this
092: * PK. The return value ranges from 1 (first column) to n, where n is the total number of
093: * columns in this PrimaryKey, or -1 if col is not part of the PrimaryKey.
094: *
095: * @param col DBColumn whose sequence is requested
096: * @return ordinal sequence of col, starting with 1 if the column is the first in this
097: * (composite) key; -1 if col does not participate in this PrimaryKey
098: */
099: public int getSequence(DBColumn col);
100:
101: /**
102: * Gets name of the DBColumn positioned as the iColumn-th column, if any, participating in this
103: * PrimaryKey. iColumn ranges from 1 (first column) to n, where n is the total number of columns
104: * in this PrimaryKey.
105: *
106: * @param iColumn index of column whose name is requested
107: * @return name of iColumn-th DBColumn in this PrimaryKey, or null if no column exists at the
108: * given position.
109: */
110: public String getDBColumnName(int iColumn);
111:
112: /**
113: * Indicates whether this primary key contains the column represented by the given name.
114: *
115: * @param columnName name of column to test
116: * @return true if this PrimaryKey contains the column referenced by columnName, false
117: * otherwise.
118: */
119: public boolean contains(String columnName);
120:
121: /**
122: * Indicates whether this primary key contains the given column.
123: *
124: * @param col DBColumn to test
125: * @return true if this PrimaryKey contains col, false otherwise
126: */
127: public boolean contains(DBColumn col);
128:
129: /**
130: * Indicates whether this PrimaryKey is referenced by the given ForeignKey.
131: *
132: * @param fk ForeignKey whose references are to be tested.
133: * @return true if fk references this PrimaryKey, false otherwise.
134: */
135: public boolean isReferencedBy(ForeignKey fk);
136: }
|