KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > testUseDatabase1InSB_TestingSessionBean


1 package test;
2
3 import javax.ejb.*;
4
5 /**
6  * This is the bean class for the TestingSessionBean enterprise bean.
7  * Created 29.4.2005 15:24:25
8  * @author lm97939
9  */

10 public class TestingSessionBean implements SessionBean, TestingSessionRemoteBusiness, TestingSessionLocalBusiness {
11     private SessionContext context;
12     
13     // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
14
// TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
15
// TODO Add business methods or web service operations
16
/**
17      * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
18      */

19     public void setSessionContext(SessionContext aContext) {
20         context = aContext;
21     }
22     
23     /**
24      * @see javax.ejb.SessionBean#ejbActivate()
25      */

26     public void ejbActivate() {
27         
28     }
29     
30     /**
31      * @see javax.ejb.SessionBean#ejbPassivate()
32      */

33     public void ejbPassivate() {
34         
35     }
36     
37     /**
38      * @see javax.ejb.SessionBean#ejbRemove()
39      */

40     public void ejbRemove() {
41         
42     }
43     // </editor-fold>
44

45     /**
46      * See section 7.10.3 of the EJB 2.0 specification
47      * See section 7.11.3 of the EJB 2.1 specification
48      */

49     public void ejbCreate() {
50         // TODO implement ejbCreate if necessary, acquire resources
51
// This method has access to the JNDI context so resource aquisition
52
// spanning all methods can be performed here such as home interfaces
53
// and data sources.
54
}
55     
56     
57     
58     // Add business logic below. (Right-click in editor and choose
59
// "EJB Methods > Add Business Method" or "Web Service > Add Operation")
60

61     public String JavaDoc testBusinessMethod1() {
62         //TODO implement testBusinessMethod1
63
return null;
64     }
65
66     public String JavaDoc testBusinessMethod2(String JavaDoc a, int b) throws Exception JavaDoc {
67         //TODO implement testBusinessMethod2
68
return null;
69     }
70
71     private test.TestingEntityLocalHome lookupTestingEntityBean() {
72         try {
73             javax.naming.Context JavaDoc c = new javax.naming.InitialContext JavaDoc();
74             test.TestingEntityLocalHome rv = (test.TestingEntityLocalHome) c.lookup("java:comp/env/ejb/TestingEntityBean");
75             return rv;
76         }
77         catch(javax.naming.NamingException JavaDoc ne) {
78             java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
79             throw new RuntimeException JavaDoc(ne);
80         }
81     }
82
83     private test.TestingEntityRemoteHome lookupMyTestingEntityBean() {
84         try {
85             javax.naming.Context JavaDoc c = new javax.naming.InitialContext JavaDoc();
86             Object JavaDoc remote = c.lookup("java:comp/env/ejb/MyTestingEntityBean");
87             test.TestingEntityRemoteHome rv = (test.TestingEntityRemoteHome) javax.rmi.PortableRemoteObject.narrow(remote, test.TestingEntityRemoteHome.class);
88             return rv;
89         }
90         catch(javax.naming.NamingException JavaDoc ne) {
91             java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
92             throw new RuntimeException JavaDoc(ne);
93         }
94     }
95
96     private javax.sql.DataSource JavaDoc getMyTestingDatabase() throws javax.naming.NamingException JavaDoc {
97         javax.naming.Context JavaDoc c = new javax.naming.InitialContext JavaDoc();
98         return (javax.sql.DataSource JavaDoc) c.lookup("java:comp/env/jdbc/myTestingDatabase");
99     }
100     
101     
102     
103 }
104
Popular Tags