KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > jdo > JDOManagerBean


1 /*
2  * Created on May 7, 2005
3  */

4 package com.nightlabs.ipanema.jdo;
5
6 import java.rmi.RemoteException JavaDoc;
7 import java.util.Collection JavaDoc;
8 import java.util.Set JavaDoc;
9
10 import javax.ejb.CreateException JavaDoc;
11 import javax.ejb.EJBException JavaDoc;
12 import javax.ejb.SessionBean JavaDoc;
13 import javax.jdo.PersistenceManager;
14
15 import com.nightlabs.ModuleException;
16 import com.nightlabs.ipanema.base.BaseSessionBeanImpl;
17 import com.nightlabs.ipanema.jdo.cache.CacheManager;
18
19
20 /**
21  * @ejb.bean name="ipanema/ejb/IpanemaBaseBean/JDOManager"
22  * jndi-name="ipanema/ejb/IpanemaBaseBean/JDOManager"
23  * type="Stateless"
24  * transaction-type="Container"
25  *
26  * @ejb.util generate = "physical"
27  */

28 public abstract class JDOManagerBean
29 extends BaseSessionBeanImpl
30 implements SessionBean JavaDoc
31 {
32     /**
33      * @ejb.create-method
34      * @ejb.permission role-name="_Guest_"
35      */

36     public void ejbCreate()
37     throws CreateException JavaDoc
38     {
39     }
40     /**
41      * @see javax.ejb.SessionBean#ejbRemove()
42      *
43      * @ejb.permission unchecked="true"
44      */

45     public void ejbRemove() throws EJBException JavaDoc, RemoteException JavaDoc
46     {
47     }
48
49     /**
50      * This method finds out the type of a <tt>PersistenceCapable</tt> object defined
51      * by its JDO object ID.
52      *
53      * @param objectID A JDO object ID specifying a persistent object.
54      * This should implement {@link com.nightlabs.jdo.ObjectID}, because the client's logic
55      * is triggered by that tagging interface.
56      * @return Returns the fully qualified class name of the JDO persistence capable object
57      * defined by the given <tt>objectID</tt>.
58      *
59      * @throws javax.jdo.JDOObjectNotFoundException if no persistent object exists with the
60      * given ID.
61      *
62      * @ejb.interface-method
63      * @ejb.permission role-name="_Guest_"
64      * @ejb.transaction type = "Supports"
65      */

66     public String JavaDoc getPersistenceCapableClassName(Object JavaDoc objectID)
67     throws ModuleException
68     {
69         PersistenceManager pm = getPersistenceManager();
70         try {
71             Object JavaDoc o = pm.getObjectById(objectID);
72             return o.getClass().getName();
73         } finally {
74             pm.close();
75         }
76     }
77
78     /**
79      * This method removes and adds listeners to your cache session. The listeners cause
80      * the client to get notified if the
81      * persistence capable objects specified by <tt>addObjectIDs</tt> have been changed.
82      * <p>
83      * The remove action will be performed before the add action. Hence, if an objectID
84      * is in both of them, it will be added in total.
85      *
86      * @param cacheSessionID The ID of your session.
87      * @param removeObjectIDs Either <tt>null</tt> or the object-ids of those JDO objects for which to remove listeners
88      * @param addObjectIDs Either <tt>null</tt> or the object-ids of those JDO objects for which to add listeners
89      *
90      * @ejb.interface-method
91      * @ejb.permission role-name="_Guest_"
92      * @ejb.transaction type = "Supports"
93      */

94     public void removeAddChangeListeners(
95             String JavaDoc cacheSessionID,
96             Collection JavaDoc removeObjectIDs,
97             Collection JavaDoc addObjectIDs)
98     throws ModuleException
99     {
100         CacheManager cm = getLookup().getCacheManager(cacheSessionID);
101
102         if (removeObjectIDs != null)
103             cm.removeChangeListeners(removeObjectIDs);
104
105         if (addObjectIDs != null)
106             cm.addChangeListeners(addObjectIDs);
107     }
108
109     /**
110      * This method diffs the listeners of your cache session with the ones that
111      * should be there (specified by <tt>subscribedObjectIDs</tt>). Then it adds
112      * the missing and removes the ones that shouldn't be there.
113      *
114      * @param cacheSessionID The ID of your session.
115      * @param removeObjectIDs Either <tt>null</tt> or the object-ids of those JDO objects for which to remove listeners
116      * @param addObjectIDs Either <tt>null</tt> or the object-ids of those JDO objects for which to add listeners
117      *
118      * @see JDOManager#removeAddChangeListeners(java.lang.String, java.util.Collection, java.util.Collection)
119      *
120      * @ejb.interface-method
121      * @ejb.permission role-name="_Guest_"
122      * @ejb.transaction type = "Supports"
123      */

124     public void resubscribeAllChangeListeners(
125             String JavaDoc cacheSessionID,
126             Set JavaDoc subscribedObjectIDs)
127     throws ModuleException
128     {
129         CacheManager cm = getLookup().getCacheManager(cacheSessionID);
130         cm.resubscribeAllChangeListeners(subscribedObjectIDs);
131     }
132
133     /**
134      * This method removes all listeners that have been registered for
135      * the given <tt>cacheSessionID</tt>. The method <tt>waitForChanges(...)</tt>
136      * will be released (if it's currently waiting).
137      *
138      * @ejb.interface-method
139      * @ejb.permission role-name="_Guest_"
140      * @ejb.transaction type = "Supports"
141      */

142     public void closeCacheSession(String JavaDoc cacheSessionID)
143     throws ModuleException
144     {
145         CacheManager cm = getLookup().getCacheManager(cacheSessionID);
146         cm.closeCacheSession();
147     }
148
149     /**
150      * This method blocks and returns not before a certain timeout occured
151      * or when <tt>closeCacheSession(...)</tt> has been called or - the main
152      * reason - at least one persistence-capable object has been changed.
153      * Because this method tries to collect multiple (by returning only at
154      * predefined time spots and by reacting only at the end of a transaction),
155      * it might return many object ids.
156      *
157      * @param cacheSessionID The ID of your cache session.
158      * @param waitTimeout The time in milliseconds defining how long this
159      * method shall wait for changes, before it returns <tt>null</tt>.
160      *
161      * @return Returns either <tt>null</tt> if nothing changed or a <tt>Collection</tt>
162      * of object ids.
163      *
164      * @see CacheManager#waitForChanges(long)
165      *
166      * @ejb.interface-method
167      * @ejb.permission role-name="_Guest_"
168      * @ejb.transaction type = "Supports"
169      */

170     public Collection JavaDoc waitForChanges(String JavaDoc cacheSessionID, long waitTimeout)
171     throws ModuleException
172     {
173         CacheManager cm = getLookup().getCacheManager(cacheSessionID);
174         return cm.waitForChanges(waitTimeout);
175     }
176
177 }
178
Popular Tags