KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > jpa > map > JpaEntityMap


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.jpa.map;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.cayenne.util.TreeNodeChild;
28
29 /**
30  * An object that stores JPA mapping information. This is a root object in the hierarchy
31  * defined in the <em>orm_1_0.xsd</em> schema.
32  *
33  * @author Andrus Adamchik
34  */

35 public class JpaEntityMap {
36
37     // mapped properties
38
protected String JavaDoc version;
39     protected String JavaDoc description;
40     protected String JavaDoc packageName;
41     protected String JavaDoc catalog;
42     protected String JavaDoc schema;
43     protected AccessType access;
44     protected JpaPersistenceUnitMetadata persistenceUnitMetadata;
45
46     protected Collection JavaDoc<JpaEntity> entities;
47     protected Collection JavaDoc<JpaEmbeddable> embeddables;
48     protected Collection JavaDoc<JpaMappedSuperclass> mappedSuperclasses;
49     protected Collection JavaDoc<JpaNamedQuery> namedQueries;
50     protected Collection JavaDoc<JpaNamedNativeQuery> namedNativeQueries;
51     protected Collection JavaDoc<JpaSqlResultSetMapping> sqlResultSetMappings;
52     protected Collection JavaDoc<JpaSequenceGenerator> sequenceGenerators;
53     protected Collection JavaDoc<JpaTableGenerator> tableGenerators;
54
55     /**
56      * Returns true if a given managed class is already loaded.
57      */

58     public boolean containsManagedClass(String JavaDoc className) {
59         if (className == null) {
60             throw new IllegalArgumentException JavaDoc("Null class name");
61         }
62
63         if (mappedSuperclasses != null) {
64             for (JpaMappedSuperclass object : mappedSuperclasses) {
65                 if (className.equals(object.getClassName())) {
66                     return true;
67                 }
68             }
69         }
70
71         if (entities != null) {
72             for (JpaEntity object : entities) {
73                 if (className.equals(object.getClassName())) {
74                     return true;
75                 }
76             }
77         }
78
79         if (embeddables != null) {
80             for (JpaEmbeddable object : embeddables) {
81                 if (className.equals(object.getClassName())) {
82                     return true;
83                 }
84             }
85         }
86
87         return false;
88     }
89
90     /**
91      * Compiles and returns a map of managed class descriptors that includes descriptors
92      * for entities, managed superclasses and embeddables. Note that class name key in the
93      * map uses slashes, not dots, to separate package components.
94      */

95     public Map JavaDoc<String JavaDoc, JpaClassDescriptor> getMangedClasses() {
96         Map JavaDoc<String JavaDoc, JpaClassDescriptor> managedClasses = new HashMap JavaDoc<String JavaDoc, JpaClassDescriptor>();
97
98         if (mappedSuperclasses != null) {
99             for (JpaMappedSuperclass object : mappedSuperclasses) {
100                 managedClasses.put(object.getClassName(), object.getClassDescriptor());
101             }
102         }
103
104         if (entities != null) {
105             for (JpaEntity object : entities) {
106                 // TODO: andrus, 5/1/2006 - need not enhance entities extending mapped
107
// superclasses
108
managedClasses.put(object.getClassName(), object.getClassDescriptor());
109             }
110         }
111
112         if (embeddables != null) {
113             for (JpaEmbeddable object : embeddables) {
114                 // TODO: andrus, 5/1/2006 - need not enhance entities extending mapped
115
// superclasses
116
managedClasses.put(object.getClassName(), object.getClassDescriptor());
117             }
118         }
119
120         return managedClasses;
121     }
122
123     /**
124      * Returns a JpaEntity describing a given persistent class.
125      */

126     public JpaEntity entityForClass(Class JavaDoc entityClass) {
127
128         if (entityClass == null) {
129             throw new IllegalArgumentException JavaDoc("Null entity class");
130         }
131
132         return entityForClass(entityClass.getName());
133     }
134
135     /**
136      * Returns a JpaEntity describing a given persistent class.
137      */

138     public JpaEntity entityForClass(String JavaDoc entityClassName) {
139         if (entityClassName == null) {
140             throw new IllegalArgumentException JavaDoc("Null entity class name");
141         }
142
143         for (JpaEntity entity : entities) {
144             if (entityClassName.equals(entity.getClassName())) {
145                 return entity;
146             }
147         }
148
149         return null;
150     }
151
152     public AccessType getAccess() {
153         return access;
154     }
155
156     public void setAccess(AccessType access) {
157         this.access = access;
158     }
159
160     public String JavaDoc getCatalog() {
161         return catalog;
162     }
163
164     public void setCatalog(String JavaDoc catalog) {
165         this.catalog = catalog;
166     }
167
168     public String JavaDoc getPackageName() {
169         return packageName;
170     }
171
172     public void setPackageName(String JavaDoc packageProperty) {
173         this.packageName = packageProperty;
174     }
175
176     public String JavaDoc getSchema() {
177         return schema;
178     }
179
180     public void setSchema(String JavaDoc schema) {
181         this.schema = schema;
182     }
183
184     @TreeNodeChild(type = JpaEmbeddable.class)
185     public Collection JavaDoc<JpaEmbeddable> getEmbeddables() {
186         if (embeddables == null) {
187             embeddables = new ArrayList JavaDoc<JpaEmbeddable>();
188         }
189
190         return embeddables;
191     }
192
193     @TreeNodeChild(type = JpaEntity.class)
194     public Collection JavaDoc<JpaEntity> getEntities() {
195         if (entities == null) {
196             entities = new ArrayList JavaDoc<JpaEntity>();
197         }
198
199         return entities;
200     }
201
202     @TreeNodeChild(type = JpaMappedSuperclass.class)
203     public Collection JavaDoc<JpaMappedSuperclass> getMappedSuperclasses() {
204         if (mappedSuperclasses == null) {
205             mappedSuperclasses = new ArrayList JavaDoc<JpaMappedSuperclass>();
206         }
207
208         return mappedSuperclasses;
209     }
210
211     @TreeNodeChild(type = JpaNamedNativeQuery.class)
212     public Collection JavaDoc<JpaNamedNativeQuery> getNamedNativeQueries() {
213         if (namedNativeQueries == null) {
214             namedNativeQueries = new ArrayList JavaDoc<JpaNamedNativeQuery>();
215         }
216
217         return namedNativeQueries;
218     }
219
220     @TreeNodeChild(type = JpaNamedQuery.class)
221     public Collection JavaDoc<JpaNamedQuery> getNamedQueries() {
222         if (namedQueries == null) {
223             namedQueries = new ArrayList JavaDoc<JpaNamedQuery>();
224         }
225
226         return namedQueries;
227     }
228
229     @TreeNodeChild(type = JpaSequenceGenerator.class)
230     public Collection JavaDoc<JpaSequenceGenerator> getSequenceGenerators() {
231         if (sequenceGenerators == null) {
232             sequenceGenerators = new ArrayList JavaDoc<JpaSequenceGenerator>();
233         }
234
235         return sequenceGenerators;
236     }
237
238     @TreeNodeChild(type = JpaSqlResultSetMapping.class)
239     public Collection JavaDoc<JpaSqlResultSetMapping> getSqlResultSetMappings() {
240         if (sqlResultSetMappings == null) {
241             sqlResultSetMappings = new ArrayList JavaDoc<JpaSqlResultSetMapping>();
242         }
243
244         return sqlResultSetMappings;
245     }
246
247     @TreeNodeChild(type = JpaTableGenerator.class)
248     public Collection JavaDoc<JpaTableGenerator> getTableGenerators() {
249         if (tableGenerators == null) {
250             tableGenerators = new ArrayList JavaDoc<JpaTableGenerator>();
251         }
252
253         return tableGenerators;
254     }
255
256     public String JavaDoc getDescription() {
257         return description;
258     }
259
260     public void setDescription(String JavaDoc description) {
261         this.description = description;
262     }
263
264     public String JavaDoc getVersion() {
265         return version;
266     }
267
268     public void setVersion(String JavaDoc version) {
269         this.version = version;
270     }
271
272     @TreeNodeChild
273     public JpaPersistenceUnitMetadata getPersistenceUnitMetadata() {
274         return persistenceUnitMetadata;
275     }
276
277     public void setPersistenceUnitMetadata(
278             JpaPersistenceUnitMetadata persistenceUnitMetadata) {
279         this.persistenceUnitMetadata = persistenceUnitMetadata;
280     }
281 }
282
Popular Tags