1 /*** $Id: EJBTester.java,v 1.1.1.1 2004/05/18 10:50:23 mochoa Exp $*/
2 package cmd_dao.sample.common.tester;
3
4 //sql
5 import java.sql.*;
6 import java.rmi.RemoteException;
7 //dto
8 import cmd_dao.sample.common.dto.EmployeeTO;
9 import cmd_dao.sample.common.tester.CRUDTester;
10 import cmd_dao.sample.common.ejb.employee.EmployeeHome;
11 import cmd_dao.sample.common.ejb.employee.Employee;
12 import cmd_dao.sample.common.ejb.employee.EmployeePK;
13
14 import javax.naming.InitialContext;
15 import javax.naming.Context;
16 import javax.naming.NamingException;
17 import javax.rmi.PortableRemoteObject;
18 import javax.ejb.CreateException;
19 import javax.ejb.FinderException;
20 import javax.ejb.RemoveException;
21
22 /***
23 * Last modified $Date: 2004/05/18 10:50:23 $
24 * @version $Revision: 1.1.1.1 $
25 * @author jvlio (jvlio@users.sourceforge.net) - 17/10/2002 - 02:42:53
26 */
27 public class EJBTester implements CRUDTester {
28
29 protected String beanName = null;
30
31 public EJBTester(String beanName) { this.beanName = beanName; }
32
33 public TuneData insert(Connection con, int count, DataSetter ds) throws SQLException {
34 long stime = 0;
35 try {
36 /***
37 * Create access to the naming context.
38 */
39 Context context = new InitialContext();
40
41 /***
42 * Lookup the EmployeeHome object. The reference is retrieved from the
43 * application-local context (java:comp/env). The variable is
44 * specified in the assembly descriptor (META-INF/application-client.xml).
45 */
46 Object homeObject = context.lookup("java:comp/env/"+beanName);
47 // Narrow the reference to a EmployeeHome.
48 EmployeeHome home = (EmployeeHome) PortableRemoteObject.narrow(homeObject,EmployeeHome.class);
49
50 Employee rec = null;
51 EmployeeTO emp = new EmployeeTO();
52
53 long begin = 0;
54 long time = 0;
55 stime = 0;
56 for(int i=0; i<count; i++) {
57 emp = (EmployeeTO)ds.set(i,emp);
58 begin = System.currentTimeMillis();
59 rec = (Employee) PortableRemoteObject.narrow(home.create(emp),Employee.class);
60 time = System.currentTimeMillis()-begin;
61 stime += time;
62 }
63 } catch (NamingException e) {
64 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
65 } catch (ClassCastException e) {
66 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
67 } catch (CreateException e) {
68 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
69 } catch (RemoteException e) {
70 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
71 }
72
73 TuneData tunning = new TuneData();
74 tunning.setProcesedTime(stime);
75 return tunning;
76 }
77
78
79 public TuneData find(Connection con, int count, DataSetter ds) throws SQLException {
80 long stime = 0;
81 try {
82 /***
83 * Create access to the naming context.
84 */
85 Context context = new InitialContext();
86
87 /***
88 * Lookup the EmployeeHome object. The reference is retrieved from the
89 * application-local context (java:comp/env). The variable is
90 * specified in the assembly descriptor (META-INF/application-client.xml).
91 */
92 Object homeObject = context.lookup("java:comp/env/"+beanName);
93 // Narrow the reference to a EmployeeHome.
94 EmployeeHome home = (EmployeeHome) PortableRemoteObject.narrow(homeObject,EmployeeHome.class);
95
96 Employee rec = null;
97 EmployeeTO emp = new EmployeeTO();
98
99 long begin = 0;
100 long time = 0;
101 stime = 0;
102 for(int i=0; i<count; i++) {
103 emp = (EmployeeTO)ds.set(i,emp);
104 begin = System.currentTimeMillis();
105 rec = (Employee) PortableRemoteObject.narrow(home.findByPrimaryKey(new EmployeePK(emp.getNo())),Employee.class);
106 time = System.currentTimeMillis()-begin;
107 stime += time;
108 }
109 } catch (NamingException e) {
110 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
111 } catch (ClassCastException e) {
112 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
113 } catch (FinderException e) {
114 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
115 } catch (RemoteException e) {
116 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
117 }
118
119 TuneData tunning = new TuneData();
120 tunning.setProcesedTime(stime);
121 return tunning;
122 }
123
124
125 public TuneData update(Connection con, int count, DataSetter ds) throws SQLException {
126 long stime = 0;
127 try {
128 /***
129 * Create access to the naming context.
130 */
131 Context context = new InitialContext();
132
133 /***
134 * Lookup the EmployeeHome object. The reference is retrieved from the
135 * application-local context (java:comp/env). The variable is
136 * specified in the assembly descriptor (META-INF/application-client.xml).
137 */
138 Object homeObject = context.lookup("java:comp/env/"+beanName);
139 // Narrow the reference to a EmployeeHome.
140 EmployeeHome home = (EmployeeHome) PortableRemoteObject.narrow(homeObject,EmployeeHome.class);
141
142 Employee rec = null;
143 EmployeeTO emp = new EmployeeTO();
144
145 long begin = 0;
146 long time = 0;
147 stime = 0;
148 for(int i=0; i<count; i++) {
149 emp = (EmployeeTO)ds.set(i,emp);
150 begin = System.currentTimeMillis();
151 rec = (Employee) PortableRemoteObject.narrow(home.findByPrimaryKey(new EmployeePK(emp.getNo())),Employee.class);
152 rec.setDetails(emp);
153 time = System.currentTimeMillis()-begin;
154 stime += time;
155 }
156 } catch (NamingException e) {
157 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
158 } catch (ClassCastException e) {
159 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
160 } catch (FinderException e) {
161 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
162 } catch (RemoteException e) {
163 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
164 }
165
166 TuneData tunning = new TuneData();
167 tunning.setProcesedTime(stime);
168 return tunning;
169 }
170
171
172
173 public TuneData delete(Connection con, int count, DataSetter ds) throws SQLException {
174 long stime = 0;
175 try {
176 /***
177 * Create access to the naming context.
178 */
179 Context context = new InitialContext();
180
181 /***
182 * Lookup the EmployeeHome object. The reference is retrieved from the
183 * application-local context (java:comp/env). The variable is
184 * specified in the assembly descriptor (META-INF/application-client.xml).
185 */
186 Object homeObject = context.lookup("java:comp/env/"+beanName);
187 // Narrow the reference to a EmployeeHome.
188 EmployeeHome home = (EmployeeHome) PortableRemoteObject.narrow(homeObject,EmployeeHome.class);
189
190 EmployeeTO emp = new EmployeeTO();
191
192 long begin = 0;
193 long time = 0;
194 stime = 0;
195 for(int i=0; i<count; i++) {
196 emp = (EmployeeTO)ds.set(i,emp);
197 begin = System.currentTimeMillis();
198 home.remove(new EmployeePK(emp.getNo()));
199 time = System.currentTimeMillis()-begin;
200 stime += time;
201 }
202 } catch (NamingException e) {
203 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
204 } catch (ClassCastException e) {
205 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
206 } catch (RemoveException e) {
207 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
208 } catch (RemoteException e) {
209 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
210 }
211
212 TuneData tunning = new TuneData();
213 tunning.setProcesedTime(stime);
214 return tunning;
215 }
216 }
This page was automatically generated by Maven