KickJava   Java API By Example, From Geeks To Geeks.

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


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 package oracle.toplink.essentials.internal.ejb.cmp3.metadata;
22
23 import java.util.Collection JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import oracle.toplink.essentials.sequencing.Sequence;
30 import oracle.toplink.essentials.sequencing.TableSequence;
31 import oracle.toplink.essentials.sequencing.NativeSequence;
32
33 import oracle.toplink.essentials.sessions.Project;
34 import oracle.toplink.essentials.sessions.DatasourceLogin;
35 import oracle.toplink.essentials.descriptors.ClassDescriptor;
36 import oracle.toplink.essentials.exceptions.ValidationException;
37 import oracle.toplink.essentials.queryframework.EJBQLPlaceHolderQuery;
38
39 import oracle.toplink.essentials.internal.helper.DatabaseTable;
40 import oracle.toplink.essentials.internal.sessions.AbstractSession;
41
42 import oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl;
43 import oracle.toplink.essentials.internal.ejb.cmp3.base.QueryHintsHandler;
44
45 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor;
46
47 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.queries.MetadataQueryHint;
48 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.queries.MetadataNamedQuery;
49 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.queries.MetadataNamedNativeQuery;
50
51 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataGeneratedValue;
52 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataTableGenerator;
53 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.sequencing.MetadataSequenceGenerator;
54
55 import oracle.toplink.essentials.internal.ejb.cmp3.xml.XMLHelper;
56
57 import org.w3c.dom.Node JavaDoc;
58 import org.w3c.dom.NodeList JavaDoc;
59
60 /**
61  * @author Guy Pelletier
62  * @since TopLink EJB 3.0 Reference Implementation
63  */

64 public class MetadataProject {
65     // The session we are currently processing for.
66
protected AbstractSession m_session;
67
68     // Boolean to specify if we should weave for value holders.
69
protected boolean m_enableLazyForOneToOne;
70
71     // Persistence unit metadata for this project.
72
protected MetadataPersistenceUnit m_persistenceUnit;
73
74     // List of mapped-superclasses found in XML for this project/persistence unit.
75
protected HashMap JavaDoc<String JavaDoc, Node JavaDoc> m_mappedSuperclassNodes;
76     protected HashMap JavaDoc<String JavaDoc, XMLHelper> m_mappedSuperclasses;
77
78     // List of embeddables found in XML for this project/persistence unit.
79
protected HashMap JavaDoc<String JavaDoc, Node JavaDoc> m_embeddableNodes;
80     protected HashMap JavaDoc<String JavaDoc, XMLHelper> m_embeddables;
81
82     // All the descriptors for this project.
83
protected HashMap JavaDoc<String JavaDoc, MetadataDescriptor> m_allDescriptors;
84
85     // Descriptors that have relationships.
86
protected HashSet JavaDoc<MetadataDescriptor> m_relationshipDescriptors;
87
88     // Named queries for this project.
89
protected HashMap JavaDoc<String JavaDoc, MetadataNamedQuery> m_namedQueries;
90
91     // NamedNativeQueries for this project.
92
protected HashMap JavaDoc<String JavaDoc, MetadataNamedNativeQuery> m_namedNativeQueries;
93
94     // Sequencing metadata.
95
protected HashMap JavaDoc<Class JavaDoc, MetadataGeneratedValue> m_generatedValues;
96     protected HashMap JavaDoc<String JavaDoc, MetadataTableGenerator> m_tableGenerators;
97     protected HashMap JavaDoc<String JavaDoc, MetadataSequenceGenerator> m_sequenceGenerators;
98
99     // Default listeners that need to be applied to each entity in the
100
// persistence unit (unless they exclude them).
101
protected HashMap JavaDoc<XMLHelper, NodeList JavaDoc> m_defaultListeners;
102
103     /**
104      * INTERNAL:
105      */

106     public MetadataProject(AbstractSession session, boolean enableLazyForOneToOne) {
107         m_session = session;
108         m_enableLazyForOneToOne = enableLazyForOneToOne;
109
110         m_defaultListeners = new HashMap JavaDoc<XMLHelper, NodeList JavaDoc>();
111
112         m_namedQueries = new HashMap JavaDoc<String JavaDoc, MetadataNamedQuery>();
113         m_namedNativeQueries = new HashMap JavaDoc<String JavaDoc, MetadataNamedNativeQuery>();
114
115         m_mappedSuperclassNodes = new HashMap JavaDoc<String JavaDoc, Node JavaDoc>();
116         m_mappedSuperclasses = new HashMap JavaDoc<String JavaDoc, XMLHelper>();
117
118         m_embeddableNodes = new HashMap JavaDoc<String JavaDoc, Node JavaDoc>();
119         m_embeddables = new HashMap JavaDoc<String JavaDoc, XMLHelper>();
120
121         m_allDescriptors = new HashMap JavaDoc<String JavaDoc, MetadataDescriptor>();
122         m_relationshipDescriptors = new HashSet JavaDoc<MetadataDescriptor>();
123
124         m_generatedValues = new HashMap JavaDoc<Class JavaDoc, MetadataGeneratedValue>();
125         m_tableGenerators = new HashMap JavaDoc<String JavaDoc, MetadataTableGenerator>();
126         m_sequenceGenerators = new HashMap JavaDoc<String JavaDoc, MetadataSequenceGenerator>();
127     }
128
129     /**
130      * INTERNAL:
131      */

132     public void addDefaultListeners(NodeList JavaDoc nodes, XMLHelper helper) {
133         m_defaultListeners.put(helper, nodes);
134     }
135
136     /**
137      * INTERNAL:
138      * This method will add the descriptor to the actual TopLink project as
139      * well if it has not already been added.
140      */

141     public void addDescriptor(MetadataDescriptor descriptor) {
142         // Set the persistence unit defaults (if there are any) on the descriptor.
143
if (m_persistenceUnit != null) {
144             descriptor.setAccess(m_persistenceUnit.getAccess());
145             descriptor.setSchema(m_persistenceUnit.getSchema());
146             descriptor.setCatalog(m_persistenceUnit.getCatalog());
147             descriptor.setIsCascadePersist(m_persistenceUnit.isCascadePersist());
148             descriptor.setIgnoreAnnotations(m_persistenceUnit.isMetadataComplete());
149         }
150
151         Project project = getSession().getProject();
152         ClassDescriptor descriptorOnProject = MetadataHelper.findDescriptor(project, descriptor.getJavaClass());
153
154         if (descriptorOnProject == null) {
155             project.addDescriptor(descriptor.getDescriptor());
156         } else {
157             descriptor.setDescriptor(descriptorOnProject);
158         }
159
160         m_allDescriptors.put(descriptor.getJavaClassName(), descriptor);
161     }
162
163     /**
164      * INTERNAL:
165      */

166     public void addGeneratedValue(MetadataGeneratedValue metadatageneratedvalue, Class JavaDoc entityClass) {
167         m_generatedValues.put(entityClass, metadatageneratedvalue);
168     }
169
170     /**
171      * INTERNAL:
172      * Add a mapped-superclass that we found in an XML document.
173      */

174     public void addMappedSuperclass(Class JavaDoc mappedSuperclass, Node JavaDoc node, XMLHelper helper) {
175         m_mappedSuperclasses.put(mappedSuperclass.getName(), helper);
176         m_mappedSuperclassNodes.put(mappedSuperclass.getName(), node);
177     }
178
179     /**
180      * INTERNAL:
181      * Add an embeddable that we found in an XML document.
182      */

183     public void addEmbeddable(Class JavaDoc embeddable, Node JavaDoc node, XMLHelper helper) {
184         m_embeddables.put(embeddable.getName(), helper);
185         m_embeddableNodes.put(embeddable.getName(), node);
186     }
187
188     /**
189      * INTERNAL:
190      */

191     public void addNamedNativeQuery(MetadataNamedNativeQuery namedNativeQuery) {
192         m_namedNativeQueries.put(namedNativeQuery.getName(), namedNativeQuery);
193     }
194
195     /**
196      * INTERNAL:
197      */

198     public void addNamedQuery(MetadataNamedQuery namedQuery) {
199         m_namedQueries.put(namedQuery.getName(), namedQuery);
200     }
201
202     /**
203      * INTERNAL:
204      */

205     public void addRelationshipDescriptor(MetadataDescriptor descriptor) {
206         m_relationshipDescriptors.add(descriptor);
207     }
208
209     /**
210      * INTERNAL:
211      */

212     public void addSequenceGenerator(MetadataSequenceGenerator sequenceGenerator) {
213         m_sequenceGenerators.put(sequenceGenerator.getName(), sequenceGenerator);
214     }
215
216     /**
217      * INTERNAL:
218      */

219     public void addTableGenerator(MetadataTableGenerator tableGenerator) {
220         m_tableGenerators.put(tableGenerator.getName(), tableGenerator);
221     }
222
223     /**
224      * INTERNAL:
225      */

226     public boolean containsDescriptor(Class JavaDoc cls) {
227         return m_allDescriptors.containsKey(cls.getName());
228     }
229
230     /**
231      * INTERNAL:
232      */

233     public boolean enableLazyForOneToOne() {
234         return m_enableLazyForOneToOne;
235     }
236
237     /**
238      * INTERNAL:
239      */

240     public HashMap JavaDoc<XMLHelper, NodeList JavaDoc> getDefaultListeners() {
241         return m_defaultListeners;
242     }
243
244     /**
245      * INTERNAL:
246      */

247     public MetadataDescriptor getDescriptor(Class JavaDoc cls) {
248         if (cls == null) {
249             return null;
250         } else {
251             MetadataDescriptor descriptor = m_allDescriptors.get(cls.getName());
252             if (descriptor == null) {
253                 throw ValidationException.classNotListedInPersistenceUnit(cls.getName());
254             } else {
255                 return descriptor;
256             }
257         }
258     }
259     
260     /**
261      * INTERNAL:
262      */

263     public Collection JavaDoc<MetadataDescriptor> getDescriptors() {
264         return m_allDescriptors.values();
265     }
266     
267     /**
268      * INTERNAL:
269      */

270     public XMLHelper getMappedSuperclassHelper(Class JavaDoc cls) {
271         return m_mappedSuperclasses.get(cls.getName());
272     }
273     
274     /**
275      * INTERNAL:
276      */

277     public Node JavaDoc getMappedSuperclassNode(Class JavaDoc cls) {
278         return m_mappedSuperclassNodes.get(cls.getName());
279     }
280     
281     /**
282      * INTERNAL:
283      */

284     public XMLHelper getEmbeddableHelper(Class JavaDoc cls) {
285         return m_embeddables.get(cls.getName());
286     }
287
288     /**
289      * INTERNAL:
290      */

291     public Node JavaDoc getEmbeddableNode(Class JavaDoc cls) {
292         return m_embeddableNodes.get(cls.getName());
293     }
294
295     /**
296      * INTERNAL:
297      */

298     public MetadataNamedNativeQuery getNamedNativeQuery(String JavaDoc name) {
299         return m_namedNativeQueries.get(name);
300     }
301     
302     /**
303      * INTERNAL:
304      */

305     public MetadataNamedQuery getNamedQuery(String JavaDoc name) {
306         return m_namedQueries.get(name);
307     }
308     
309     /**
310      * INTERNAL:
311      * Set the classes for processing.
312      */

313     public MetadataPersistenceUnit getPersistenceUnit() {
314         return m_persistenceUnit;
315     }
316     
317     /**
318      * INTERNAL:
319      */

320     public HashSet JavaDoc<MetadataDescriptor> getRelationshipDescriptors() {
321         return m_relationshipDescriptors;
322     }
323     
324     /**
325      * INTERNAL:
326      */

327     public MetadataSequenceGenerator getSequenceGenerator(String JavaDoc name) {
328         return m_sequenceGenerators.get(name);
329     }
330
331     /**
332      * INTERNAL:
333      */

334     public Collection JavaDoc<MetadataSequenceGenerator> getSequenceGenerators() {
335         return m_sequenceGenerators.values();
336     }
337     
338     /**
339      * INTERNAL:
340      */

341     public AbstractSession getSession() {
342         return m_session;
343     }
344     
345     /**
346      * INTERNAL:
347      */

348     public MetadataTableGenerator getTableGenerator(String JavaDoc name) {
349         return m_tableGenerators.get(name);
350     }
351
352     /**
353      * INTERNAL:
354      */

355     public Collection JavaDoc<MetadataTableGenerator> getTableGenerators() {
356         return m_tableGenerators.values();
357     }
358     
359     /**
360      * INTERNAL:
361      */

362     public boolean hasConflictingSequenceGenerator(MetadataSequenceGenerator sequenceGenerator) {
363         if (hasSequenceGenerator(sequenceGenerator.getName())) {
364             return ! getSequenceGenerator(sequenceGenerator.getName()).equals(sequenceGenerator);
365         } else {
366             return false;
367         }
368     }
369
370     /**
371      * INTERNAL:
372      */

373     public boolean hasConflictingTableGenerator(MetadataTableGenerator tableGenerator) {
374         if (hasTableGenerator(tableGenerator.getName())) {
375             return ! getTableGenerator(tableGenerator.getName()).equals(tableGenerator);
376         } else {
377             return false;
378         }
379     }
380     
381     /**
382      * INTERNAL:
383      */

384     public boolean hasDescriptors() {
385         return ! m_allDescriptors.isEmpty();
386     }
387     
388     /**
389      * INTERNAL:
390      */

391     public boolean hasMappedSuperclass(Class JavaDoc cls) {
392         return m_mappedSuperclasses.containsKey(cls.getName());
393     }
394     
395     /**
396      * INTERNAL:
397      */

398     public boolean hasEmbeddable(Class JavaDoc cls) {
399         return m_embeddables.containsKey(cls.getName());
400     }
401
402     /**
403      * INTERNAL:
404      */

405     public boolean hasNamedNativeQuery(String JavaDoc name) {
406         return m_namedNativeQueries.containsKey(name);
407     }
408     
409     /**
410      * INTERNAL:
411      */

412     public boolean hasNamedQuery(String JavaDoc name) {
413         return m_namedQueries.containsKey(name);
414     }
415     
416     /**
417      * INTERNAL:
418      * Set the classes for processing.
419      */

420     public boolean hasPersistenceUnit() {
421         return m_persistenceUnit != null;
422     }
423
424     /**
425      * INTERNAL:
426      */

427     public boolean hasSequenceGenerator(String JavaDoc name) {
428         return getSequenceGenerator(name) != null;
429     }
430
431     /**
432      * INTERNAL:
433      */

434     public boolean hasTableGenerator(String JavaDoc name) {
435         return getTableGenerator(name) != null;
436     }
437
438     /**
439      * INTERNAL:
440      * Performs sequencing setup on Login and Descriptors
441      */

442     public AbstractSession process() {
443         processSequencing();
444         
445         processRelationshipDescriptors();
446         
447         return m_session;
448     }
449     
450     /**
451      * INTERNAL:
452      * Process the named native queries we found and add them to the given
453      * session.
454      */

455     public void processNamedNativeQueries(ClassLoader JavaDoc loader) {
456         for (MetadataNamedNativeQuery query : m_namedNativeQueries.values()) {
457             HashMap JavaDoc<String JavaDoc, String JavaDoc> hints = processQueryHints(query.getHints(), query.getName());
458                 
459             Class JavaDoc resultClass = query.getResultClass();
460                 
461             if (resultClass != void.class) {
462                 resultClass = MetadataHelper.getClassForName(resultClass.getName(), loader);
463                 m_session.addQuery(query.getName(), EJBQueryImpl.buildSQLDatabaseQuery(resultClass, query.getEJBQLString(), hints));
464             } else {
465                 String JavaDoc resultSetMapping = query.getResultSetMapping();
466                 if (! resultSetMapping.equals("")) {
467                     m_session.addQuery(query.getName(), EJBQueryImpl.buildSQLDatabaseQuery(resultSetMapping, query.getEJBQLString(), hints));
468                 } else {
469                     // Neither a resultClass or resultSetMapping is specified so place in a temp query on the session
470
m_session.addQuery(query.getName(), EJBQueryImpl.buildSQLDatabaseQuery(query.getEJBQLString(), hints));
471                 }
472             }
473         }
474     }
475     
476     /**
477      * INTERNAL:
478      * Process the named queries we found and add them to the given session.
479      */

480     public void processNamedQueries(MetadataValidator validator) {
481         for (MetadataNamedQuery query : m_namedQueries.values()) {
482             try {
483                 HashMap JavaDoc<String JavaDoc, String JavaDoc> hints = processQueryHints(query.getHints(), query.getName());
484                 m_session.addEjbqlPlaceHolderQuery(new EJBQLPlaceHolderQuery(query.getName(), query.getEJBQLString(), hints));
485             } catch (Exception JavaDoc exception) {
486                 validator.throwErrorProcessingNamedQueryAnnotation(query.getClass(), query.getName(), exception);
487             }
488         }
489     }
490     
491     /**
492      * INTERNAL:
493      * Process a list of MetadataQueryHint.
494      */

495     protected HashMap JavaDoc<String JavaDoc, String JavaDoc> processQueryHints(List JavaDoc<MetadataQueryHint> hints, String JavaDoc queryName) {
496         HashMap JavaDoc<String JavaDoc, String JavaDoc> hm = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
497         
498         for (MetadataQueryHint hint : hints) {
499             QueryHintsHandler.verify(hint.getName(), hint.getValue(), queryName, m_session);
500             hm.put(hint.getName(), hint.getValue());
501         }
502         
503         return hm;
504     }
505     
506     /**
507      * INTERNAL:
508      * Process the related descriptors.
509      */

510     protected void processRelationshipDescriptors() {
511         for (MetadataDescriptor descriptor : (HashSet JavaDoc<MetadataDescriptor>) getRelationshipDescriptors()) {
512             for (RelationshipAccessor accessor : (Collection JavaDoc<RelationshipAccessor>) descriptor.getRelationshipAccessors()) {
513                 accessor.processRelationship();
514             }
515         }
516     }
517     
518     /**
519      * INTERNAL:
520      * Process the sequencing information.
521      */

522     protected void processSequencing() {
523         if (! m_generatedValues.isEmpty()) {
524             DatasourceLogin login = m_session.getProject().getLogin();
525             
526             // Generators referenced from Id should have correct type
527
for (MetadataGeneratedValue generatedValue : m_generatedValues.values()) {
528                 String JavaDoc type = generatedValue.getStrategy();
529                 String JavaDoc generatorName = generatedValue.getGenerator();
530                 
531                 if (type.equals(MetadataConstants.TABLE)) {
532                     MetadataSequenceGenerator sequenceGenerator = m_sequenceGenerators.get(generatorName);
533                     
534                     if (sequenceGenerator != null) {
535                         // WIP
536
}
537                 } else if (type.equals(MetadataConstants.SEQUENCE) || type.equals(MetadataConstants.IDENTITY)) {
538                     MetadataTableGenerator tableGenerator = m_tableGenerators.get(generatorName);
539                     
540                     if (tableGenerator != null) {
541                         // WIP
542
}
543                 }
544             }
545     
546             Sequence defaultAutoSequence = null;
547             TableSequence defaultTableSequence = new TableSequence(MetadataConstants.DEFAULT_TABLE_GENERATOR);
548             NativeSequence defaultNativeSequence = new NativeSequence(MetadataConstants.DEFAULT_SEQUENCE_GENERATOR);
549             
550             // Sequences keyed on generator names.
551
Hashtable JavaDoc<String JavaDoc, Sequence> sequences = new Hashtable JavaDoc<String JavaDoc, Sequence>();
552             
553             for (MetadataSequenceGenerator sequenceGenerator : m_sequenceGenerators.values()) {
554                 String JavaDoc sequenceGeneratorName = sequenceGenerator.getName();
555                 String JavaDoc seqName = (sequenceGenerator.getSequenceName().equals("")) ? sequenceGeneratorName : sequenceGenerator.getSequenceName();
556                 NativeSequence sequence = new NativeSequence(seqName, sequenceGenerator.getAllocationSize());
557                 sequences.put(sequenceGeneratorName, sequence);
558                 
559                 if (sequenceGeneratorName.equals(MetadataConstants.DEFAULT_AUTO_GENERATOR)) {
560                     // SequenceGenerator defined with DEFAULT_AUTO_GENERATOR.
561
// The sequence it defines will be used as a defaultSequence.
562
defaultAutoSequence = sequence;
563                 } else if (sequenceGeneratorName.equals(MetadataConstants.DEFAULT_SEQUENCE_GENERATOR)) {
564                     // SequenceGenerator deinfed with DEFAULT_SEQUENCE_GENERATOR.
565
// All sequences of GeneratorType SEQUENCE and IDENTITY
566
// referencing non-defined generators will use a clone of
567
// the sequence defined by this generator.
568
defaultNativeSequence = sequence;
569                 }
570             }
571             
572             for (MetadataTableGenerator tableGenerator : m_tableGenerators.values()) {
573                 String JavaDoc tableGeneratorName = tableGenerator.getName();
574                 String JavaDoc seqName = (tableGenerator.getPkColumnValue().equals("")) ? tableGeneratorName : tableGenerator.getPkColumnValue();
575                 TableSequence sequence = new TableSequence(seqName, tableGenerator.getAllocationSize());
576                 sequences.put(tableGeneratorName, sequence);
577                 
578                 // Get the database table from the @TableGenerator values.
579
// In case tableGenerator.table().equals("") default sequence
580
// table name will be extracted from sequence and used, see
581
// TableSequence class.
582
sequence.setTable(new DatabaseTable(MetadataHelper.getFullyQualifiedTableName(tableGenerator.getTable(), sequence.getTableName(), tableGenerator.getCatalog(), tableGenerator.getSchema())));
583                 
584                 // Process the @UniqueConstraints for this table.
585
for (String JavaDoc uniqueConstraint : tableGenerator.getUniqueConstraints()) {
586                     sequence.getTable().addUniqueConstraint(uniqueConstraint);
587                 }
588                 
589                 if (! tableGenerator.getPkColumnName().equals("")) {
590                     sequence.setNameFieldName(tableGenerator.getPkColumnName());
591                 }
592                     
593                 if (! tableGenerator.getValueColumnName().equals("")) {
594                     sequence.setCounterFieldName(tableGenerator.getValueColumnName());
595                 }
596                 
597                 if (tableGeneratorName.equals(MetadataConstants.DEFAULT_AUTO_GENERATOR)) {
598                     // TableGenerator defined with DEFAULT_AUTO_GENERATOR.
599
// The sequence it defines will be used as a defaultSequence.
600
defaultAutoSequence = sequence;
601                 } else if (tableGeneratorName.equals(MetadataConstants.DEFAULT_TABLE_GENERATOR)) {
602                     // SequenceGenerator defined with DEFAULT_TABLE_GENERATOR.
603
// All sequences of GenerationType TABLE referencing non-
604
// defined generators will use a clone of the sequence
605
// defined by this generator.
606
defaultTableSequence = sequence;
607                 }
608             }
609     
610             // Finally loop through descriptors and set sequences as required into
611
// Descriptors and Login
612
for (Class JavaDoc entityClass : m_generatedValues.keySet()) {
613                 MetadataDescriptor descriptor = m_allDescriptors.get(entityClass.getName());
614                 MetadataGeneratedValue generatedValue = m_generatedValues.get(entityClass);
615                 String JavaDoc generatorName = generatedValue.getGenerator();
616                 Sequence sequence = null;
617                 
618                 if (! generatorName.equals("")) {
619                     sequence = sequences.get(generatorName);
620                 }
621                 
622                 if (sequence == null) {
623                     if (generatedValue.getStrategy().equals(MetadataConstants.TABLE)) {
624                         if (generatorName.equals("")) {
625                             sequence = defaultTableSequence;
626                         } else {
627                             sequence = (Sequence)defaultTableSequence.clone();
628                             sequence.setName(generatorName);
629                         }
630                     } else if (generatedValue.getStrategy().equals(MetadataConstants.SEQUENCE) || generatedValue.getStrategy().equals(MetadataConstants.IDENTITY)) {
631                         if (generatorName.equals("")) {
632                             sequence = defaultNativeSequence;
633                         } else {
634                             sequence = (Sequence)defaultNativeSequence.clone();
635                             sequence.setName(generatorName);
636                         }
637                     }
638                 }
639                 
640                 if (sequence != null) {
641                     descriptor.setSequenceNumberName(sequence.getName());
642                     login.addSequence(sequence);
643                 } else if (generatedValue.getStrategy().equals(MetadataConstants.AUTO)) {
644                     if (defaultAutoSequence != null) {
645                         descriptor.setSequenceNumberName(defaultAutoSequence.getName());
646                         login.setDefaultSequence(defaultAutoSequence);
647                     } else {
648                         descriptor.setSequenceNumberName(MetadataConstants.DEFAULT_AUTO_GENERATOR);
649                     }
650                 }
651             }
652         }
653     }
654     
655     /**
656      * INTERNAL:
657      * Set the classes for processing.
658      */

659     public void setPersistenceUnit(MetadataPersistenceUnit persistenceUnit) {
660         m_persistenceUnit = persistenceUnit;
661     }
662 }
663
Popular Tags