KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > columns > MetadataPrimaryKeyJoinColumns


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns;
23
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import javax.persistence.PrimaryKeyJoinColumn;
28 import javax.persistence.PrimaryKeyJoinColumns;
29
30 /**
31  * Object to hold onto join column metadata.
32  *
33  * @author Guy Pelletier
34  * @since TopLink EJB 3.0 Reference Implementation
35  */

36 public class MetadataPrimaryKeyJoinColumns {
37     private String JavaDoc m_sourceTableName;
38     private String JavaDoc m_targetTableName;
39     protected List JavaDoc<MetadataPrimaryKeyJoinColumn> m_pkJoinColumns;
40     
41     /**
42      * INTERNAL:
43      */

44     public MetadataPrimaryKeyJoinColumns(String JavaDoc sourceTableName, String JavaDoc targetTableName) {
45         m_sourceTableName = sourceTableName;
46         m_targetTableName = targetTableName;
47         m_pkJoinColumns = new ArrayList JavaDoc<MetadataPrimaryKeyJoinColumn>();
48     }
49     
50     /**
51      * INTERNAL:
52      */

53     public MetadataPrimaryKeyJoinColumns(PrimaryKeyJoinColumn[] primaryKeyJoinColumns, String JavaDoc sourceTableName, String JavaDoc targetTableName) {
54         this(sourceTableName, targetTableName);
55         
56         // Process the primary key join column array.
57
for (PrimaryKeyJoinColumn pkJoinColumn : primaryKeyJoinColumns) {
58             m_pkJoinColumns.add(new MetadataPrimaryKeyJoinColumn(pkJoinColumn, sourceTableName, targetTableName));
59         }
60     }
61     
62     /**
63      * INTERNAL:
64      */

65     public MetadataPrimaryKeyJoinColumns(PrimaryKeyJoinColumns primaryKeyJoinColumns, PrimaryKeyJoinColumn primaryKeyJoinColumn, String JavaDoc sourceTableName, String JavaDoc targetTableName) {
66         this(sourceTableName, targetTableName);
67         
68         // Process all the primary key join columns first.
69
if (primaryKeyJoinColumns != null) {
70             for (PrimaryKeyJoinColumn pkJoinColumn : primaryKeyJoinColumns.value()) {
71                 m_pkJoinColumns.add(new MetadataPrimaryKeyJoinColumn(pkJoinColumn, sourceTableName, targetTableName));
72             }
73         }
74         
75         // Process the single primary key join column second.
76
if (primaryKeyJoinColumn != null) {
77             m_pkJoinColumns.add(new MetadataPrimaryKeyJoinColumn(primaryKeyJoinColumn, sourceTableName, targetTableName));
78         }
79     }
80     
81     /**
82      * INTERNAL:
83      */

84     public List JavaDoc<MetadataPrimaryKeyJoinColumn> values() {
85         // If no primary key join columns are specifed, add a default one.
86
if (m_pkJoinColumns.isEmpty()) {
87             m_pkJoinColumns.add(new MetadataPrimaryKeyJoinColumn(m_sourceTableName, m_targetTableName));
88         }
89         
90         return m_pkJoinColumns;
91     }
92     
93     /**
94      * INTERNAL:
95      */

96     public boolean loadedFromXML() {
97         return false;
98     }
99     
100     /**
101      * INTERNAL:
102      */

103     public int size() {
104         return m_pkJoinColumns.size();
105     }
106 }
107
Popular Tags