KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > sessions > Project


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.sessions;
23
24 import java.util.*;
25 import java.io.*;
26 import oracle.toplink.essentials.descriptors.ClassDescriptor;
27 import oracle.toplink.essentials.exceptions.ValidationException;
28 import oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl;
29 import oracle.toplink.essentials.internal.helper.*;
30 import oracle.toplink.essentials.queryframework.SQLResultSetMapping;
31 import oracle.toplink.essentials.threetier.*;
32
33 /**
34  * <b>Purpose</b>: Maintain all of the TopLink configuration information for a system.
35  * <p><b>Responsibilities</b>:<ul>
36  * <li> Project wide parameters (name, default for use method accessing, and base filepath for other INI files)
37  * <li> JDBC Login information
38  * <li> Descriptors
39  * <li> Validate Descriptors (instance variable & method access)
40  * <li> Maintain sequencing information & other project wide parameters
41  * <li> Construct valid DatabaseLogin objects for each platform (with sequence info set)
42  * </ul>
43  *
44  * @see DatabaseLogin
45  */

46 public class Project implements Serializable, Cloneable JavaDoc {
47     protected String JavaDoc name;
48     protected Login datasourceLogin;
49     protected Map descriptors;
50     protected Vector orderedDescriptors;
51
52     /** Holds the default set of read-only classes that apply to each UnitOfWork. */
53     protected Vector defaultReadOnlyClasses;
54
55     /** Cache the EJBQL descriptor aliases. */
56     protected Map aliasDescriptors;
57
58     /** Cache if any descriptor is isolated. (set during initialization) */
59     protected boolean hasIsolatedClasses;
60     /** Cache if any descriptor has history. (set during initialization) */
61     protected boolean hasGenericHistorySupport;
62     /** Cache if any descriptor is using ProxyIndirection. (set during initialization */
63     protected boolean hasProxyIndirection;
64     /** Cache if all descriptors are CMP1/2 */
65     protected boolean isPureCMP2Project;
66     
67     /** This a collection of 'maps' that allow users to map custom SQL to query results */
68     protected Map sqlResultSetMappings;
69
70     /**
71      * PUBLIC:
72      * Create a new project.
73      */

74     public Project() {
75         this.name = "";
76         this.descriptors = new HashMap();
77         this.defaultReadOnlyClasses = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
78         this.orderedDescriptors = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
79         this.hasIsolatedClasses = false;
80         this.hasGenericHistorySupport = false;
81         this.isPureCMP2Project = false;
82         this.hasProxyIndirection = false;
83     }
84
85     /**
86      * PUBLIC:
87      * Create a new project that will connect through the login information.
88      * This method can be used if the project is being create in code instead of being read from a file.
89      */

90     public Project(Login login) {
91         this();
92         this.datasourceLogin = login;
93     }
94
95     /**
96      * PUBLIC:
97      * Create a new project that will connect through JDBC using the login information.
98      * This method can be used if the project is being create in code instead of being read from a file.
99      */

100     public Project(DatabaseLogin login) {
101         this();
102         this.datasourceLogin = login;
103     }
104
105     /**
106      * PUBLIC:
107      * Add the read-only class which apply to each UnitOfWork created by default.
108      */

109     public void addDefaultReadOnlyClass(Class JavaDoc readOnlyClass) {
110         getDefaultReadOnlyClasses().addElement(readOnlyClass);
111     }
112
113     /**
114      * PUBLIC:
115      * Add the descriptor to the project.
116      */

117     public void addDescriptor(ClassDescriptor descriptor) {
118         getOrderedDescriptors().add(descriptor);
119         String JavaDoc alias = descriptor.getAlias();
120         if (alias != null) {
121             addAlias(alias, descriptor);
122         }
123
124         // Avoid loading class definition at this point if we haven't done so yet.
125
if ((descriptors != null) && !descriptors.isEmpty()) {
126             getDescriptors().put(descriptor.getJavaClass(), descriptor);
127         }
128     }
129
130     /**
131      * INTERNAL: Used by the BuilderInterface when reading a Project from INI files.
132      */

133     public void addDescriptor(ClassDescriptor descriptor, DatabaseSessionImpl session) {
134         getOrderedDescriptors().add(descriptor);
135         String JavaDoc alias = descriptor.getAlias();
136         if (alias != null) {
137             addAlias(alias, descriptor);
138         }
139
140         // Avoid loading class definition at this point if we haven't done so yet.
141
if ((descriptors != null) && !descriptors.isEmpty()) {
142             getDescriptors().put(descriptor.getJavaClass(), descriptor);
143         }
144         session.initializeDescriptorIfSessionAlive(descriptor);
145     }
146
147     /**
148      * INTERNAL:
149      * Add the descriptors to the session.
150      * All persistent classes must have a descriptor registered for them with the session.
151      * This method allows for a batch of descriptors to be added at once so that TopLink
152      * can resolve the dependancies between the descriptors and perform initialization optimally.
153      */

154     public void addDescriptors(Vector descriptors, DatabaseSessionImpl session) {
155         for (Enumeration enumeration = descriptors.elements(); enumeration.hasMoreElements();) {
156             ClassDescriptor descriptor = (ClassDescriptor)enumeration.nextElement();
157             getDescriptors().put(descriptor.getJavaClass(), descriptor);
158             String JavaDoc alias = descriptor.getAlias();
159             if (alias != null) {
160                 addAlias(alias, descriptor);
161             }
162         }
163
164         if (session.isConnected()) {
165             session.initializeDescriptors(descriptors);
166             // The commit order must be maintain whenever new descriptors are added.
167
session.getCommitManager().initializeCommitOrder();
168         }
169
170         getOrderedDescriptors().addAll(descriptors);
171     }
172
173     /**
174      * PUBLIC:
175      * Merge the descriptors from another project into this one.
176      * All persistent classes must have a descriptor registered for them with the session.
177      * This method allows for a batch of descriptors to be added at once so that TopLink
178      * can resolve the dependancies between the descriptors and perform initialization optimially.
179      */

180     public void addDescriptors(Project project, DatabaseSessionImpl session) {
181         Iterator descriptors = project.getDescriptors().values().iterator();
182         while (descriptors.hasNext()) {
183             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
184             getDescriptors().put(descriptor.getJavaClass(), descriptor);
185             String JavaDoc alias = descriptor.getAlias();
186             if (alias != null) {
187                 addAlias(alias, descriptor);
188             }
189         }
190
191         if (session.isConnected()) {
192             session.initializeDescriptors(project.getDescriptors());
193             // The commit order must be maintained whenever new descriptors are added.
194
session.getCommitManager().initializeCommitOrder();
195         }
196
197         getOrderedDescriptors().addAll(project.getOrderedDescriptors());
198     }
199
200     /**
201      * PUBLIC:
202      * Add a named SQLResultSetMapping to this project. These SQLResultSetMappings
203      * can be later used by ResultSetMappingQueries to map Custom sql results to
204      * results as defined by the SQLResultSetMappings.
205      */

206     public void addSQLResultSetMapping(SQLResultSetMapping sqlResultSetMapping){
207         if (sqlResultSetMapping == null || sqlResultSetMapping.getName() == null){
208             return;
209         }
210         if (this.sqlResultSetMappings == null){
211             this.sqlResultSetMappings = new HashMap();
212         }
213         this.sqlResultSetMappings.put(sqlResultSetMapping.getName(), sqlResultSetMapping);
214     }
215     
216     /**
217      * PUBLIC:
218      * Set all this project's descriptors to conform all read queries within the context of the unit of work.
219      */

220     public void conformAllDescriptors() {
221         Iterator descriptors = getDescriptors().values().iterator();
222         while (descriptors.hasNext()) {
223             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
224             descriptor.setShouldAlwaysConformResultsInUnitOfWork(true);
225         }
226     }
227
228     /**
229      * INTERNAL:
230      * Convert all the class-name-based settings in this project to actual class-based
231      * settings
232      * @param classLoader
233      */

234     public void convertClassNamesToClasses(ClassLoader JavaDoc classLoader){
235         Iterator ordered = orderedDescriptors.iterator();
236         while (ordered.hasNext()){
237             ClassDescriptor descriptor = (ClassDescriptor)ordered.next();
238             descriptor.convertClassNamesToClasses(classLoader);
239         }
240         // convert class names to classes for each SQLResultSetMapping
241
if (sqlResultSetMappings != null) {
242             for (Iterator mappingIt = sqlResultSetMappings.keySet().iterator(); mappingIt.hasNext();) {
243                 SQLResultSetMapping mapping = (SQLResultSetMapping) sqlResultSetMappings.get(mappingIt.next());
244                 mapping.convertClassNamesToClasses(classLoader);
245             }
246         }
247     }
248
249     /**
250      * PUBLIC:
251      * Switch all descriptors to assume existence for non-null primary keys.
252      */

253     public void assumeExistenceForDoesExist() {
254         Iterator descriptors = getDescriptors().values().iterator();
255         while (descriptors.hasNext()) {
256             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
257             descriptor.getQueryManager().assumeExistenceForDoesExist();
258         }
259     }
260
261     /**
262      * PUBLIC:
263      * Switch all descriptors to check the cache for existence.
264      */

265     public void checkCacheForDoesExist() {
266         Iterator descriptors = getDescriptors().values().iterator();
267         while (descriptors.hasNext()) {
268             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
269             descriptor.getQueryManager().checkCacheForDoesExist();
270         }
271     }
272
273     /**
274      * PUBLIC:
275      * Switch all descriptors to check the database for existence.
276      */

277     public void checkDatabaseForDoesExist() {
278         Iterator descriptors = getDescriptors().values().iterator();
279         while (descriptors.hasNext()) {
280             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
281             descriptor.getQueryManager().checkDatabaseForDoesExist();
282         }
283     }
284
285     /**
286      * INTERNAL:
287      * Clones the descriptor
288      */

289     public Object JavaDoc clone() {
290         try {
291             return super.clone();
292         } catch (Exception JavaDoc exception) {
293             return null;
294         }
295     }
296
297     /**
298      * PUBLIC:
299      * Factory method to create session.
300      * This returns an implementor of the DatabaseSession interface, which can be used to login
301      * and add descriptors from other projects. The Session interface however should be used for
302      * reading and writing once connected for complete portability.
303      */

304     public DatabaseSession createDatabaseSession() {
305         return new DatabaseSessionImpl(this);
306     }
307
308     /**
309      * PUBLIC:
310      * Factory method to create a server session.
311      * This returns an implementor of the Server interface, which can be used to login
312      * and add descriptors from other projects, configure connection pooling and acquire client sessions.
313      */

314     public Server createServerSession() {
315         return new ServerSession(this);
316     }
317
318     /**
319      * PUBLIC:
320      * Factory method to create a server session.
321      * This returns an implementor of the Server interface, which can be used to login
322      * and add descriptors from other projects, configure connection pooling and acquire client sessions.
323      * Configure the min and max number of connections for the default pool.
324      */

325     public Server createServerSession(int min, int max) {
326         return new ServerSession(this, min, max);
327     }
328
329     /**
330      * PUBLIC:
331      * Factory method to create a server session.
332      * This returns an implementor of the Server interface, which can be used to login
333      * and add descriptors from other projects, configure connection pooling and acquire client sessions.
334      * Configure the default connection policy to be used.
335      * This policy is used on the "acquireClientSession()" protocol.
336      */

337     public Server createServerSession(ConnectionPolicy defaultConnectionPolicy) {
338         return new ServerSession(this, defaultConnectionPolicy);
339     }
340
341     /**
342      * PUBLIC:
343      * Returns the default set of read-only classes.
344      */

345     public Vector getDefaultReadOnlyClasses() {
346         return defaultReadOnlyClasses;
347     }
348
349     /**
350      * PUBLIC:
351      * Return the descriptor specified for the class.
352      */

353     public ClassDescriptor getClassDescriptor(Class JavaDoc theClass) {
354         ClassDescriptor desc = getDescriptor(theClass);
355         if (desc instanceof ClassDescriptor) {
356             return (ClassDescriptor)desc;
357         } else {
358             throw ValidationException.cannotCastToClass(desc, desc.getClass(), ClassDescriptor.class);
359         }
360     }
361
362     /**
363      * PUBLIC:
364      * Return the descriptor specified for the class.
365      */

366     public ClassDescriptor getDescriptor(Class JavaDoc theClass) {
367         return (ClassDescriptor)getDescriptors().get(theClass);
368     }
369
370     /**
371      * PUBLIC:
372      * Return the descriptors.
373      */

374     public Map getDescriptors() {
375         // Lazy initialize class references from orderedDescriptors when reading from XML.
376
if (descriptors.isEmpty() && (!orderedDescriptors.isEmpty())) {
377             for (Iterator iterator = orderedDescriptors.iterator(); iterator.hasNext();) {
378                 ClassDescriptor descriptor = (ClassDescriptor)iterator.next();
379                 descriptors.put(descriptor.getJavaClass(), descriptor);
380             }
381         }
382         return descriptors;
383     }
384
385     /**
386      * INTERNAL:
387      * Return the descriptors in the order added.
388      * Used to maitain consistent order in XML.
389      */

390     public Vector getOrderedDescriptors() {
391         return orderedDescriptors;
392     }
393
394     /**
395      * INTERNAL:
396      * Set the descriptors order.
397      * Used to maitain consistent order in XML.
398      */

399     public void setOrderedDescriptors(Vector orderedDescriptors) {
400         this.orderedDescriptors = orderedDescriptors;
401         for (Enumeration e = orderedDescriptors.elements(); e.hasMoreElements();) {
402             ClassDescriptor descriptor = (ClassDescriptor)e.nextElement();
403             String JavaDoc alias = descriptor.getAlias();
404             if (alias != null) {
405                 addAlias(alias, descriptor);
406             }
407         }
408     }
409
410     /**
411      * INTERNAL:
412      * Return the login, the login holds any database connection information given.
413      * This has been replaced by getDatasourceLogin to make use of the Login interface
414      * to support non-relational datasources,
415      * if DatabaseLogin API is required it will need to be cast.
416      */

417     public DatabaseLogin getLogin() {
418         return (DatabaseLogin)datasourceLogin;
419     }
420
421     /**
422      * PUBLIC:
423      * Return the login, the login holds any database connection information given.
424      * This return the Login interface and may need to be cast to the datasource specific implementation.
425      */

426     public Login getDatasourceLogin() {
427         return datasourceLogin;
428     }
429
430     /**
431      * PUBLIC:
432      * get the name of the project.
433      */

434     public String JavaDoc getName() {
435         return name;
436     }
437
438     /**
439      * PUBLIC:
440      * Get a named SQLResultSetMapping from this project. These SQLResultSetMappings
441      * can be used by ResultSetMappingQueries to map Custom sql results to
442      * results as defined by the SQLResultSetMappings.
443      */

444     public SQLResultSetMapping getSQLResultSetMapping(String JavaDoc sqlResultSetMapping){
445         if (sqlResultSetMapping == null || this.sqlResultSetMappings == null){
446             return null;
447         }
448         return (SQLResultSetMapping)this.sqlResultSetMappings.get(sqlResultSetMapping);
449     }
450     
451     /**
452      * INTERNAL:
453      * Answers if at least one Descriptor or Mapping had a HistoryPolicy at initialize time.
454      */

455     public boolean hasGenericHistorySupport() {
456         return hasGenericHistorySupport;
457     }
458
459     /**
460      * PUBLIC:
461      * Set the read-only classes which apply to each UnitOfWork create by default.
462      */

463     public void setDefaultReadOnlyClasses(Vector newValue) {
464         this.defaultReadOnlyClasses = (Vector)newValue.clone();
465     }
466
467     /**
468      * INTERNAL:
469      * Set the descriptors registered with this session.
470      */

471     public void setDescriptors(Map descriptors) {
472         this.descriptors = descriptors;
473         for (Iterator iterator = descriptors.values().iterator(); iterator.hasNext();) {
474             ClassDescriptor descriptor = (ClassDescriptor)iterator.next();
475             String JavaDoc alias = descriptor.getAlias();
476             if (alias != null) {
477                 addAlias(alias, descriptor);
478             }
479         }
480     }
481  
482     /**
483      * INTERNAL:
484      * Set to true during descriptor initialize if any descriptor has hsitory.
485      */

486     public void setHasGenericHistorySupport(boolean hasGenericHistorySupport) {
487         this.hasGenericHistorySupport = hasGenericHistorySupport;
488     }
489     
490     /**
491      * INTERNAL:
492      * Return if all descriptors are for CMP1 or CMP2 beans.
493      * Set to true during descriptor initialize.
494      * Allows certain optimizations to be made.
495      */

496     public boolean isPureCMP2Project() {
497         return isPureCMP2Project;
498     }
499     
500     /**
501      * INTERNAL:
502      * Set if all descriptors are for CMP1 or CMP2 beans.
503      * Set to true during descriptor initialize.
504      * Allows certain optimizations to be made.
505      */

506     public void setIsPureCMP2Project(boolean isPureCMP2Project) {
507         this.isPureCMP2Project = isPureCMP2Project;
508     }
509     
510     /**
511      * INTERNAL:
512      * Return if any descriptors are isolated.
513      * Set to true during descriptor initialize if any descriptor is isolated.
514      * Determines if an isolated client session is required.
515      */

516     public boolean hasIsolatedClasses() {
517         return hasIsolatedClasses;
518     }
519     
520     /**
521      * INTERNAL:
522      * Set to true during descriptor initialize if any descriptor is isolated.
523      * Determines if an isolated client session is required.
524      */

525     public void setHasIsolatedClasses(boolean hasIsolatedClasses) {
526         this.hasIsolatedClasses = hasIsolatedClasses;
527     }
528
529     /**
530      * INTERNAL:
531      * Return if any descriptors use ProxyIndirection.
532      * Set to true during descriptor initialize if any descriptor uses ProxyIndirection
533      * Determines if ProxyIndirectionPolicy.getValueFromProxy should be called.
534      */

535     public boolean hasProxyIndirection() {
536         return this.hasProxyIndirection;
537     }
538       
539     /**
540      * INTERNAL:
541      * Set to true during descriptor initialize if any descriptor uses ProxyIndirection
542      * Determines if ProxyIndirectionPolicy.getValueFromProxy should be called.
543      */

544     public void setHasProxyIndirection(boolean hasProxyIndirection) {
545         this.hasProxyIndirection = hasProxyIndirection;
546     }
547     
548     /**
549      * PUBLIC:
550      * Set the login to be used to connect to the database for this project.
551      */

552     public void setLogin(DatabaseLogin datasourceLogin) {
553         this.datasourceLogin = datasourceLogin;
554     }
555
556     /**
557      * PUBLIC:
558      * Set the login to be used to connect to the database for this project.
559      */

560     public void setLogin(Login datasourceLogin) {
561         this.datasourceLogin = datasourceLogin;
562     }
563
564     /**
565      * PUBLIC:
566      * Set the login to be used to connect to the database for this project.
567      */

568     public void setDatasourceLogin(Login datasourceLogin) {
569         this.datasourceLogin = datasourceLogin;
570     }
571
572     /**
573      * PUBLIC:
574      * Set the name of the project.
575      */

576     public void setName(String JavaDoc name) {
577         this.name = name;
578     }
579
580     /**
581      * INTERNAL:
582      */

583     public String JavaDoc toString() {
584         return Helper.getShortClassName(getClass()) + "(" + getName() + ")";
585     }
586
587     /**
588      * PUBLIC:
589      * Switch all descriptors to use the cache identity map.
590      */

591     public void useCacheIdentityMap() {
592         Iterator descriptors = getDescriptors().values().iterator();
593         while (descriptors.hasNext()) {
594             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
595             descriptor.useCacheIdentityMap();
596         }
597     }
598
599     /**
600      * PUBLIC:
601      * Switch all descriptors to use the cache identity map the size.
602      */

603     public void useCacheIdentityMap(int cacheSize) {
604         Iterator descriptors = getDescriptors().values().iterator();
605         while (descriptors.hasNext()) {
606             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
607             descriptor.useCacheIdentityMap();
608             descriptor.setIdentityMapSize(cacheSize);
609         }
610     }
611
612     /**
613      * PUBLIC:
614      * Switch all descriptors to use the full identity map.
615      */

616     public void useFullIdentityMap() {
617         Iterator descriptors = getDescriptors().values().iterator();
618         while (descriptors.hasNext()) {
619             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
620             descriptor.useFullIdentityMap();
621         }
622     }
623
624     /**
625      * PUBLIC:
626      * Switch all descriptors to use the full identity map with initial cache size.
627      */

628     public void useFullIdentityMap(int initialCacheSize) {
629         Iterator descriptors = getDescriptors().values().iterator();
630         while (descriptors.hasNext()) {
631             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
632             descriptor.useFullIdentityMap();
633             descriptor.setIdentityMapSize(initialCacheSize);
634         }
635     }
636
637     /**
638      * PUBLIC:
639      * Switch all descriptors to use no identity map.
640      */

641     public void useNoIdentityMap() {
642         Iterator descriptors = getDescriptors().values().iterator();
643         while (descriptors.hasNext()) {
644             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
645             descriptor.useNoIdentityMap();
646         }
647     }
648
649     /**
650      * PUBLIC:
651      * Switch all descriptors to use the soft cache weak identity map.
652      */

653     public void useSoftCacheWeakIdentityMap() {
654         Iterator descriptors = getDescriptors().values().iterator();
655         while (descriptors.hasNext()) {
656             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
657             descriptor.useSoftCacheWeakIdentityMap();
658         }
659     }
660
661     /**
662      * PUBLIC:
663      * Switch all descriptors to use the soft cache weak identity map with soft cache size.
664      */

665     public void useSoftCacheWeakIdentityMap(int cacheSize) {
666         Iterator descriptors = getDescriptors().values().iterator();
667         while (descriptors.hasNext()) {
668             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
669             descriptor.useSoftCacheWeakIdentityMap();
670             descriptor.setIdentityMapSize(cacheSize);
671         }
672     }
673
674     /**
675      * INTERNAL:
676      * Asks each descriptor if is uses optimistic locking.
677      */

678     public boolean usesOptimisticLocking() {
679         Iterator descriptors = getDescriptors().values().iterator();
680         while (descriptors.hasNext()) {
681             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
682             if (descriptor.usesOptimisticLocking()) {
683                 return true;
684             }
685         }
686         return false;
687     }
688
689     /**
690      * INTERNAL:
691      * Asks each descriptor if is uses sequencing.
692      */

693     public boolean usesSequencing() {
694         Iterator descriptors = getDescriptors().values().iterator();
695         while (descriptors.hasNext()) {
696             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
697             if (descriptor.usesSequenceNumbers()) {
698                 return true;
699             }
700         }
701         return false;
702     }
703
704     /**
705      * PUBLIC:
706      * Switch all descriptors to use the weak identity map.
707      */

708     public void useWeakIdentityMap() {
709         Iterator descriptors = getDescriptors().values().iterator();
710         while (descriptors.hasNext()) {
711             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
712             descriptor.useWeakIdentityMap();
713         }
714     }
715
716     /**
717      * PUBLIC:
718      * Switch all descriptors to use the weak identity map.
719      */

720     public void useWeakIdentityMap(int initialCacheSize) {
721         Iterator descriptors = getDescriptors().values().iterator();
722         while (descriptors.hasNext()) {
723             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
724             descriptor.useWeakIdentityMap();
725             descriptor.setIdentityMapSize(initialCacheSize);
726         }
727     }
728
729     /**
730      * INTERNAL:
731      * Default apply login implementation.
732      * Defined for generated subclasses that may not have a login.
733      * BUG#2669342
734      */

735     public void applyLogin() {
736         // Do nothing by default.
737
}
738
739     /**
740      * INTERNAL:
741      * Returns the alias descriptors hashtable.
742      */

743     public Map getAliasDescriptors() {
744         return aliasDescriptors;
745     }
746
747     /**
748      * PUBLIC:
749      * Add an alias for the descriptor.
750      */

751     public void addAlias(String JavaDoc alias, ClassDescriptor descriptor) {
752         if (aliasDescriptors == null) {
753             aliasDescriptors = new Hashtable(10);
754         }
755         aliasDescriptors.put(alias, descriptor);
756     }
757
758     /**
759      * INTERNAL:
760      * Get the descriptors from the project, and associate the aliases for each
761      * descriptor with the descriptor.
762      */

763     public void addAliasesFromProject(oracle.toplink.essentials.sessions.Project project) {
764         Iterator descriptors = getDescriptors().values().iterator();
765         while (descriptors.hasNext()) {
766             ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
767             if (descriptor.getAlias() != null) {
768                 addAlias(descriptor.getAlias(), descriptor);
769             }
770         }
771     }
772
773     /**
774      * PUBLIC:
775      * Return the descriptor for the alias.
776      */

777     public ClassDescriptor getClassDescriptorForAlias(String JavaDoc alias) {
778         ClassDescriptor d = null;
779         if (aliasDescriptors != null) {
780             d = (ClassDescriptor)aliasDescriptors.get(alias);
781         }
782         return d;
783     }
784
785     /**
786      * PUBLIC:
787      * Return the descriptor for the alias.
788      *
789      * @deprecated Replaced by {@link #getClassDescriptorForAlias(String)}
790      */

791     public ClassDescriptor getDescriptorForAlias(String JavaDoc alias) {
792         ClassDescriptor d = null;
793         if (aliasDescriptors != null) {
794             d = (ClassDescriptor)aliasDescriptors.get(alias);
795         }
796         return d;
797     }
798
799     /**
800      * INTERNAL:
801      * Set the alias descriptors hashtable.
802      */

803     public void setAliasDescriptors(Map aHashtable) {
804         aliasDescriptors = aHashtable;
805     }
806 }
807
Popular Tags