In the Package Explorer View make sure the Calculator project is selected.
Create a new Java class. Open menu File > New > Other... and choose Java > Class.
The package will be by.iba.client and the class name PersistentCalculatorClient.
Leave the default options selected and be sure that public static void main(...) method is checked.
Click the Finish button.
Add the following code to the public static void main method body:
try { Context jndiContext = new InitialContext(); Object ref = jndiContext.lookup("PersistentCalculatorBean/remote"); PersistentCalculator calc = (PersistentCalculator) PortableRemoteObject .narrow(ref, PersistentCalculator.class); System.out.println("4 + 3 = " + calc.add(4, 3)); System.out.println("4 - 3 = " + calc.subtract(4, 3)); System.out.println("4 * 3 = " + calc.multiply(4, 3)); System.out.println("4 / 3 = " + calc.divide(4, 3)); System.out.println("6 * 3 = " + calc.multiply(6, 3)); System.out.println("7 / 3 = " + calc.divide(7, 3)); System.out.println(" History before cleanup:"); System.out.println(calc.getHistory()); calc.clearHistory(); System.out.println(" History after cleanup:"); System.out.println(calc.getHistory()); } catch (NamingException ne) { ne.printStackTrace(); }
NOTE: To resolve imports problems press Shift + Ctrl + O. Press Ctrl + S to save the Java class.
Run the Java class by selecting menu Run > Run As > Java Application.
NOTE: Make sure the PersistentCalculatorClient.java is selected in Package Explorer View.
You should see the following result in the Java client's Console View:
4 + 3 = 7.0 4 - 3 = 1.0 4 * 3 = 12.0 4 / 3 = 1.3333333333333333 6 * 3 = 18.0 7 / 3 = 2.3333333333333335 History before cleanup: [ 2006-11-15 13:32:52.159 : 7.0 divide 3.0 is 2.3333333333333335, 2006-11-15 13:32:52.143 : 6.0 multiply 3.0 is 18.0, 2006-11-15 13:32:52.143 : 4.0 divide 3.0 is 1.3333333333333333, 2006-11-15 13:32:52.127 : 4.0 multiply 3.0 is 12.0, 2006-11-15 13:32:52.112 : 4.0 subtract 3.0 is 1.0] History after cleanup: []
OPTIONALLY: You can see the DB table created by JBoss for the Entity Object.
Comment out the history cleanup code line in the client:
System.out.println(" History before cleanup:"); System.out.println(calc.getHistory()); // calc.clearHistory(); ...
Re-run PersistentCalculatorClient client (to populate the table).
Open a browser, go to JMX Console http://localhost:8080/jmx-console:
Go to Hypersonic SQL service and click on startDatabaseManager()
The HSQL Database Manager will come up, displaying the database table OPERATION.
If you execute an SQL query on the table, the data from the OPERATION table will be displayed as shown below:
SELECT * FROM PUBLIC.OPERATION ORDER BY TIMESTAMP ASC
Congratulations ! You have succesfully tested EJB 3.0 application with Entity Object !!!
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |