KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > idgenerator > IDGeneratorBean


1 /*
2  * Created on 18.03.2004
3  */

4 package com.nightlabs.ipanema.idgenerator;
5
6 import java.rmi.RemoteException JavaDoc;
7
8 import javax.ejb.CreateException JavaDoc;
9 import javax.ejb.EJBException JavaDoc;
10 import javax.ejb.SessionBean JavaDoc;
11 import javax.jdo.PersistenceManager;
12
13 import com.nightlabs.ModuleException;
14 import com.nightlabs.ipanema.base.BaseSessionBeanImpl;
15
16 /**
17  * @ejb.bean name="ipanema/ejb/IpanemaBaseBean/IDGenerator"
18  * jndi-name="ipanema/ejb/IpanemaBaseBean/IDGenerator"
19  * type="Stateless"
20  *
21  * @ejb.permission role-name = "_Guest_"
22  *
23  * @ejb.util generate = "physical"
24  **/

25
26 public abstract class IDGeneratorBean extends BaseSessionBeanImpl implements SessionBean JavaDoc
27 {
28     /**
29      * @ejb.create-method
30      */

31     public void ejbCreate() throws CreateException JavaDoc
32     {
33         try
34         {
35             System.out.println("IDGeneratorBean created by " + this.getPrincipalString());
36         }
37         catch (ModuleException e)
38         {
39             throw new CreateException JavaDoc(e.getMessage());
40         }
41     }
42     /**
43      * @see javax.ejb.SessionBean#ejbRemove()
44      *
45      * @ejb.permission unchecked="true"
46      */

47     public void ejbRemove() throws EJBException JavaDoc, RemoteException JavaDoc { }
48
49     /**
50      * This method generates a new ID that is unique in the context of the current
51      * organisationID and has never been used before - means can be used for a new object.
52      * @param key Normally, this is the class name of the object that should be persisted.
53      * @return The new ID
54      *
55      * @ejb.interface-method
56      * @ejb.transaction type = "Required"
57      */

58     public long generateIDLong(String JavaDoc key)
59     throws ModuleException
60     {
61         PersistenceManager pm;
62         pm = getPersistenceManager();
63         try
64         {
65             return IDGeneratorAssistant.generateIDLong(pm, key);
66         } finally {
67             pm.close();
68         }
69     }
70
71     /**
72      * This method generates a new ID that is unique in the context of the current
73      * organisationID and has never been used before - means can be used for a new object.
74      * @param key Normally, this is the class name of the object that should be persisted.
75      * @return The new ID
76      *
77      * @ejb.interface-method
78      * @ejb.transaction type = "Required"
79      */

80     public int generateIDInt(String JavaDoc key)
81     throws ModuleException
82     {
83         PersistenceManager pm = getPersistenceManager();
84         try {
85             return IDGeneratorAssistant.generateIDInt(pm, key);
86         } finally {
87             pm.close();
88         }
89     }
90
91 }
Popular Tags