KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > sequencing > MetadataTableGenerator


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.sequencing;
23
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import javax.persistence.TableGenerator;
28 import javax.persistence.UniqueConstraint;
29
30 /**
31  * A wrapper class to the MetadataTableGenerator that holds onto a
32  * @TableGenerator for its metadata values.
33  *
34  * @author Guy Pelletier
35  * @since TopLink EJB 3.0 Reference Implementation
36  */

37 public class MetadataTableGenerator extends MetadataGenerator {
38     protected TableGenerator m_tableGenerator;
39     protected List JavaDoc<String JavaDoc> m_uniqueConstraints;
40     
41     /**
42      * INTERNAL:
43      */

44     protected MetadataTableGenerator(String JavaDoc entityClassName) {
45         super(entityClassName);
46     }
47     
48     /**
49      * INTERNAL:
50      */

51     public MetadataTableGenerator(TableGenerator tableGenerator, String JavaDoc entityClassName) {
52         super(entityClassName);
53         m_tableGenerator = tableGenerator;
54     }
55     
56     /**
57      * INTERNAL:
58      */

59     public boolean equals(Object JavaDoc objectToCompare) {
60         if (objectToCompare instanceof MetadataTableGenerator) {
61             MetadataTableGenerator generator = (MetadataTableGenerator) objectToCompare;
62             
63             if (!generator.getName().equals(getName())) {
64                 return false;
65             }
66             
67             if (generator.getInitialValue() != getInitialValue()) {
68                 return false;
69             }
70             
71             if (generator.getAllocationSize() != getAllocationSize()) {
72                 return false;
73             }
74             
75             if (!generator.getPkColumnName().equals(getPkColumnName())) {
76                 return false;
77             }
78             
79             if (!generator.getValueColumnName().equals(getValueColumnName())) {
80                 return false;
81             }
82             
83             if (!generator.getPkColumnValue().equals(getPkColumnValue())) {
84                 return false;
85             }
86             
87             if (!generator.getTable().equals(getTable())) {
88                 return false;
89             }
90                 
91             if (!generator.getSchema().equals(getSchema())) {
92                 return false;
93             }
94                 
95             return generator.getCatalog().equals(getCatalog());
96         }
97         
98         return false;
99     }
100     
101     /**
102      * INTERNAL:
103      */

104     public int getAllocationSize() {
105         return m_tableGenerator.allocationSize();
106     }
107     
108     /**
109      * INTERNAL:
110      * WIP - need to take into consideration the global catalog from XML.
111      */

112     public String JavaDoc getCatalog() {
113         return m_tableGenerator.catalog();
114     }
115     
116     /**
117      * INTERNAL:
118      */

119     public int getInitialValue() {
120         return m_tableGenerator.initialValue();
121     }
122     
123     /**
124      * INTERNAL:
125      */

126     public String JavaDoc getName() {
127         return m_tableGenerator.name();
128     }
129     
130     /**
131      * INTERNAL:
132      */

133     public String JavaDoc getPkColumnName() {
134         return m_tableGenerator.pkColumnName();
135     }
136     
137     /**
138      * INTERNAL:
139      */

140     public String JavaDoc getPkColumnValue() {
141         return m_tableGenerator.pkColumnValue();
142     }
143     
144     /**
145      * INTERNAL:
146      * WIP - need to take into consideration the global schema from XML.
147      */

148     public String JavaDoc getSchema() {
149         return m_tableGenerator.schema();
150     }
151     
152     /**
153      * INTERNAL:
154      */

155     public String JavaDoc getTable() {
156         return m_tableGenerator.table();
157     }
158  
159     /**
160      * INTERNAL:
161      */

162     public List JavaDoc<String JavaDoc> getUniqueConstraints() {
163         if (m_uniqueConstraints == null) {
164             m_uniqueConstraints = new ArrayList JavaDoc();
165             
166             for (UniqueConstraint uniqueConstraint : m_tableGenerator.uniqueConstraints()) {
167                 for (String JavaDoc columnName : uniqueConstraint.columnNames()) {
168                     m_uniqueConstraints.add(columnName);
169                 }
170             }
171         }
172         
173         return m_uniqueConstraints;
174     }
175     
176     /**
177      * INTERNAL:
178      */

179     public String JavaDoc getValueColumnName() {
180         return m_tableGenerator.valueColumnName();
181     }
182 }
183
Popular Tags