KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > tables > MetadataTable


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.tables;
23
24 import javax.persistence.Table;
25 import javax.persistence.UniqueConstraint;
26
27 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataHelper;
28
29 import oracle.toplink.essentials.internal.helper.DatabaseTable;
30
31 /**
32  * Object to hold onto table metadata in a TopLink database table.
33  *
34  * @author Guy Pelletier
35  * @since TopLink EJB 3.0 Reference Implementation
36  */

37 public class MetadataTable {
38     protected String JavaDoc m_name;
39     protected String JavaDoc m_schema;
40     protected String JavaDoc m_catalog;
41     protected DatabaseTable m_databaseTable;
42     
43     /**
44      * INTERNAL:
45      */

46     public MetadataTable() {
47         m_databaseTable = new DatabaseTable();
48     }
49     
50     /**
51      * INTERNAL:
52      */

53     public MetadataTable(Table table) {
54         this();
55         
56         if (table != null) {
57             m_name = table.name();
58             m_schema = table.schema();
59             m_catalog = table.catalog();
60             
61             processName();
62             processUniqueConstraints(table.uniqueConstraints());
63         }
64     }
65     
66     /**
67      * INTERNAL:
68      */

69     public String JavaDoc getCatalog() {
70         return m_catalog;
71     }
72     
73     /**
74      * INTERNAL:
75      */

76     public DatabaseTable getDatabaseTable() {
77         return m_databaseTable;
78     }
79     
80     /**
81      * INTERNAL:
82      */

83     public String JavaDoc getName() {
84         return m_name;
85     }
86     
87     /**
88      * INTERNAL:
89      */

90     public String JavaDoc getSchema() {
91         return m_schema;
92     }
93
94     /**
95      * INTERNAL:
96      */

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

104     protected void processName() {
105         // Don't bother setting the name if name is blank.
106
if (! m_name.equals("")) {
107             setName(MetadataHelper.getFullyQualifiedTableName(m_name, m_catalog, m_schema));
108         }
109     }
110     
111     /**
112      * INTERNAL:
113      * Process the unique constraints for the given table.
114      */

115     protected void processUniqueConstraints(UniqueConstraint[] uniqueConstraints) {
116         for (UniqueConstraint uniqueConstraint : uniqueConstraints) {
117             m_databaseTable.addUniqueConstraints(uniqueConstraint.columnNames());
118         }
119     }
120     
121     /**
122      * INTERNAL:
123      */

124     public void setName(String JavaDoc name) {
125         m_databaseTable.setPossiblyQualifiedName(name);
126     }
127 }
128
Popular Tags