01: package org.mockejb.test;
02:
03: import javax.naming.*;
04:
05: import java.sql.*;
06: import javax.sql.DataSource;
07:
08: /**
09: * Simple EJB with some auxiliary methods.
10: *
11: * @ejb:bean type="Stateless" view-type="local" name="SampleHelper" local-jndi-name="mockejb/SampleHelper"
12: * @ejb:interface local-class="org.mockejb.test.SampleHelper"
13: * @ejb:home local-class="org.mockejb.test.SampleHelperHome"
14: * @ejb.resource-ref res-ref-name="jdbc/SampleDataSource" res-type="javax.sql.DataSource" res-auth="Container" jndi-name="jdbc/SampleDataSource"
15: *
16: */
17: public class SampleHelperBean extends BaseSessionBean {
18:
19: /**
20: * Simple method to return a predefined string for testing purposes.
21: * @param param this parameter is ignored. It is here only for testing.
22: * @ejb.interface-method
23: * @ejb:transaction type="Supports"
24: */
25: public String dummyMethod(String param) {
26:
27: return getClass().getName();
28:
29: }
30:
31: /**
32: * Example of a database insert
33: *
34: * @ejb.interface-method
35: * @ejb:transaction type="Supports"
36: */
37: public void insertData() throws NamingException, SQLException {
38:
39: Context ctx = new InitialContext();
40:
41: DataSource ds = (DataSource) ctx
42: .lookup("java:comp/env/jdbc/SampleDataSource");
43:
44: Connection con = ds.getConnection();
45: Statement stmt = con.createStatement();
46: stmt.execute("insert into test_table values('ts')");
47:
48: con.close();
49:
50: }
51:
52: /**
53: * @ejb.interface-method
54: * @ejb:transaction type="Supports"
55: */
56: public void throwSystemException() throws RuntimeException {
57: throw new RuntimeException("Example of a system exception");
58: }
59:
60: }
|