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-2006 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:
042: package org.netbeans.modules.dbschema;
043:
044: /** Describes a directed column pair. Because of its direction, it has
045: * the notion of belonging to a table.
046: */
047: public final class ColumnPairElement extends DBMemberElement {
048: /** the local column to which this element is associated */
049: private ColumnElement _localColumn;
050:
051: /** the referenced column to which this element is associated */
052: private ColumnElement _referencedColumn;
053:
054: /** Create a new column pair element represented in memory.
055: */
056: public ColumnPairElement() {
057: this (new Memory(), null, null, null);
058: }
059:
060: /** Creates a new column pair element.
061: * @param localColumn local column of this column pair
062: * @param referencedColumn referenced column of this column pair
063: * @param declaringTable declaring table of this column pair, or <code>null</code>
064: */
065: public ColumnPairElement(ColumnElement localColumn,
066: ColumnElement referencedColumn, TableElement declaringTable) {
067: this (new Memory(), localColumn, referencedColumn,
068: declaringTable);
069: }
070:
071: /** Creates a new column pair element.
072: * @param impl the pluggable implementation
073: * @param localColumn local column of this column pair
074: * @param referencedColumn referenced column of this column pair
075: * @param declaringTable declaring table of this column pair, or <code>null</code>
076: */
077: public ColumnPairElement(ColumnPairElement.Impl impl,
078: ColumnElement localColumn, ColumnElement referencedColumn,
079: TableElement declaringTable) {
080: super (impl, declaringTable);
081: _localColumn = localColumn;
082: _referencedColumn = referencedColumn;
083: }
084:
085: /** Returns the implementation for the column pair.
086: * @return implementation for the column pair
087: */
088: final Impl getColumnPairImpl() {
089: return (Impl) getElementImpl();
090: }
091:
092: /** Gets the local column.
093: * @return the local column of this column pair
094: */
095: public final ColumnElement getLocalColumn() {
096: return _localColumn;
097: }
098:
099: /** Sets the local column.
100: * @param ce the local column
101: */
102: public final void setLocalColumn(ColumnElement ce) {
103: if (_localColumn == null)
104: _localColumn = ce;
105: }
106:
107: /** Gets the referenced column.
108: * @return the referenced column of this column pair
109: */
110: public final ColumnElement getReferencedColumn() {
111: return _referencedColumn;
112: }
113:
114: /** Sets the referenced column.
115: * @param ce the referenced column
116: */
117: public final void setReferencedColumn(ColumnElement ce) {
118: if (_referencedColumn == null)
119: _referencedColumn = ce;
120: }
121:
122: /** Gets the name of this element.
123: * @return the name
124: */
125: public DBIdentifier getName() {
126: ColumnElement lce = getLocalColumn();
127: ColumnElement fce = getReferencedColumn();
128:
129: DBIdentifier name = DBIdentifier.create(lce.getName()
130: .getFullName()
131: + ";" + fce.getName().getFullName()); //NOI18N
132:
133: return name;
134: }
135:
136: /** Implementation of a reference key column element.
137: * @see DBMemberElement
138: */
139: public interface Impl extends DBMemberElement.Impl {
140: }
141:
142: static class Memory extends DBMemberElement.Memory implements Impl {
143: /** Default constructor.
144: */
145: Memory() {
146: }
147:
148: /** Copy constructor.
149: * @param column the object from which to read values
150: */
151: Memory(ColumnPairElement column) {
152: super(column);
153: }
154: }
155: }
|