001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns;
038:
039: import javax.persistence.PrimaryKeyJoinColumn;
040:
041: import oracle.toplink.essentials.internal.helper.DatabaseField;
042:
043: /**
044: * Object to hold onto join column metadata in a TopLink database fields.
045: *
046: * @author Guy Pelletier
047: * @since TopLink EJB 3.0 Reference Implementation
048: */
049: public class MetadataPrimaryKeyJoinColumn {
050: protected DatabaseField m_pkField;
051: protected DatabaseField m_fkField;
052:
053: public static final String DEFAULT_NAME = "";
054: public static final String DEFAULT_COLUMN_DEFINITION = "";
055: public static final String DEFAULT_REFERENCED_COLUMN_NAME = "";
056:
057: /**
058: * INTERNAL:
059: * Called for association override.
060: */
061: public MetadataPrimaryKeyJoinColumn(
062: PrimaryKeyJoinColumn primaryKeyJoinColumn,
063: String sourceTableName, String targetTableName) {
064: this (sourceTableName, targetTableName);
065:
066: if (primaryKeyJoinColumn != null) {
067: // Process the primary key field metadata.
068: m_pkField.setName(primaryKeyJoinColumn
069: .referencedColumnName());
070:
071: // Process the foreign key field metadata.
072: m_fkField.setName(primaryKeyJoinColumn.name());
073: m_fkField.setColumnDefinition(primaryKeyJoinColumn
074: .columnDefinition());
075: }
076: }
077:
078: /**
079: * INTERNAL:
080: */
081: public MetadataPrimaryKeyJoinColumn(String sourceTableName,
082: String targetTableName) {
083: this (sourceTableName, targetTableName,
084: DEFAULT_REFERENCED_COLUMN_NAME, DEFAULT_NAME);
085: }
086:
087: /**
088: * INTERNAL:
089: */
090: public MetadataPrimaryKeyJoinColumn(String sourceTableName,
091: String targetTableName, String defaultFieldName) {
092: this (sourceTableName, targetTableName, defaultFieldName,
093: defaultFieldName);
094: }
095:
096: /**
097: * INTERNAL:
098: */
099: protected MetadataPrimaryKeyJoinColumn(String sourceTableName,
100: String targetTableName, String defaultPKFieldName,
101: String defaultFKFieldName) {
102: m_pkField = new DatabaseField();
103: m_pkField.setName(defaultPKFieldName);
104: m_pkField.setTableName(sourceTableName);
105:
106: m_fkField = new DatabaseField();
107: m_fkField.setName(defaultFKFieldName);
108: m_fkField.setTableName(targetTableName);
109: m_fkField.setColumnDefinition(DEFAULT_COLUMN_DEFINITION);
110: }
111:
112: /**
113: * INTERNAL:
114: */
115: public DatabaseField getForeignKeyField() {
116: return m_fkField;
117: }
118:
119: /**
120: * INTERNAL:
121: */
122: public DatabaseField getPrimaryKeyField() {
123: return m_pkField;
124: }
125:
126: /**
127: * INTERNAL:
128: */
129: public boolean isForeignKeyFieldNotSpecified() {
130: return m_fkField.getName().equals("");
131: }
132:
133: /**
134: * INTERNAL:
135: */
136: public boolean isPrimaryKeyFieldNotSpecified() {
137: return m_pkField.getName().equals("");
138: }
139:
140: /**
141: * INTERNAL:
142: */
143: public boolean loadedFromXML() {
144: return false;
145: }
146: }
|