KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > hibernate > ejb > AggregateProfileBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.hibernate.ejb;
8
9 import org.jboss.test.hibernate.model.User;
10 import org.jboss.test.hibernate.ejb.interfaces.ProfileServiceHome;
11 import org.jboss.test.hibernate.ejb.interfaces.ProfileServiceUtil;
12 import org.jboss.test.hibernate.ejb.interfaces.ProfileService;
13
14 import javax.ejb.SessionBean JavaDoc;
15 import javax.ejb.EJBException JavaDoc;
16 import javax.ejb.SessionContext JavaDoc;
17 import javax.ejb.CreateException JavaDoc;
18 import javax.naming.NamingException JavaDoc;
19 import java.rmi.RemoteException JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * An ejb which simply wraps calls to the ProfileBean service.
24  * Used to test the issue with sessions, nested ejb calls,
25  * and the CachedConnectionManager.
26  *
27  * @author <a HREF="mailto:steve@hibernate.org">Steve Ebersole</a>
28  * @version $Revision: 1.1.2.1 $
29  *
30  * @ejb:bean name="AggregateProfileService"
31  * jndi-name="AggregateProfileService"
32  * view-type="remote"
33  * type="Stateless"
34  */

35 public class AggregateProfileBean implements SessionBean JavaDoc
36 {
37    /**
38     * @exception javax.ejb.EJBException if an error occurs
39     * @ejb:interface-method
40     */

41    public User storeUser(User user) throws EJBException JavaDoc
42    {
43       ProfileService service = null;
44       try
45       {
46          service = locateService();
47          return service.storeUser( user );
48       }
49       catch( EJBException JavaDoc e )
50       {
51          throw e;
52       }
53       catch( RemoteException JavaDoc e )
54       {
55          throw new EJBException JavaDoc( "Unable to access profile service", e );
56       }
57       finally
58       {
59          release( service );
60       }
61    }
62
63    /**
64     * @exception javax.ejb.EJBException if an error occurs
65     * @ejb:interface-method
66     */

67    public User loadUser(long id) throws EJBException JavaDoc
68    {
69       ProfileService service = null;
70       try
71       {
72          service = locateService();
73          return service.loadUser(id);
74       }
75       catch( EJBException JavaDoc e )
76       {
77          throw e;
78       }
79       catch( RemoteException JavaDoc e )
80       {
81          throw new EJBException JavaDoc( "Unable to access profile service", e );
82       }
83       finally
84       {
85          release( service );
86       }
87    }
88
89    /**
90     * @exception javax.ejb.EJBException if an error occurs
91     * @ejb:interface-method
92     */

93    public User loadUser(Long JavaDoc id) throws EJBException JavaDoc
94    {
95       ProfileService service = null;
96       try
97       {
98          service = locateService();
99          return service.loadUser(id);
100       }
101       catch( EJBException JavaDoc e )
102       {
103          throw e;
104       }
105       catch( RemoteException JavaDoc e )
106       {
107          throw new EJBException JavaDoc( "Unable to access profile service", e );
108       }
109       finally
110       {
111          release( service );
112       }
113    }
114
115    /**
116     * @exception javax.ejb.EJBException if an error occurs
117     * @ejb:interface-method
118     */

119    public List JavaDoc listUsers() throws EJBException JavaDoc
120    {
121       ProfileService service = null;
122       try
123       {
124          service = locateService();
125          return service.listUsers();
126       }
127       catch( EJBException JavaDoc e )
128       {
129          throw e;
130       }
131       catch( RemoteException JavaDoc e )
132       {
133          throw new EJBException JavaDoc( "Unable to access profile service", e );
134       }
135       finally
136       {
137          release( service );
138       }
139    }
140
141    /**
142     * @ejb:create-method
143     */

144    public void ejbCreate()
145    {
146    }
147
148    public void ejbActivate() throws EJBException JavaDoc, RemoteException JavaDoc
149    {
150    }
151
152    public void ejbPassivate() throws EJBException JavaDoc, RemoteException JavaDoc
153    {
154    }
155
156    public void ejbRemove() throws EJBException JavaDoc, RemoteException JavaDoc
157    {
158    }
159
160    public void setSessionContext(SessionContext JavaDoc ctx) throws EJBException JavaDoc, RemoteException JavaDoc
161    {
162    }
163
164    private ProfileService locateService() throws EJBException JavaDoc
165    {
166       try
167       {
168          ProfileServiceHome home = ProfileServiceUtil.getHome();
169          return home.create();
170       }
171       catch( NamingException JavaDoc e )
172       {
173          throw new EJBException JavaDoc( "Unable to locate profile service", e );
174       }
175       catch( CreateException JavaDoc e )
176       {
177          throw new EJBException JavaDoc( "Unable to create ref to profile service", e );
178       }
179       catch( RemoteException JavaDoc e )
180       {
181          throw new EJBException JavaDoc( "Unable to access profile service", e );
182       }
183    }
184
185    private void release(ProfileService service)
186    {
187       if ( service != null )
188       {
189          try
190          {
191             service.remove();
192          }
193          catch( Throwable JavaDoc ignore )
194          {
195          }
196       }
197    }
198 }
199
Popular Tags