OpenJPA Logo   ASF Logo

Using Criteria API in DayTrader

A current DayTrader project implementation in Apache Geronimo contains several JPQL queries. These can easily be converted to JPA Criteria API queries. A sample with this conversion can be created to run on either the Apache Geronimo server or the WebSphere Application Server with the built-in Derby database.

Downloading DayTrader

You must have Subversion installed in order to download the DayTrader implementation.Subversion can be downloaded from http://subversion.apache.org/packages.html . Use the 2.1.3 version of DayTrader for this sample. Follow the following steps:

  1. Create a root directory for the download. For this example, we will use a directory called DayTrader.
  2. Create subdirectories branches/2.1.3 under the DayTrader directory
  3. cd to DayTrader
  4. Issue the following subversion command:
    svn checkout https://svn.apache.org/repos/asf/geronimo/daytrader/branches/2.1.3 branches/2.1.3 .
    

Build DayTrader

You must have maven installed in order to build DayTrader. Maven can be downloaded from http://maven.apache.org/download.html. Unzip the file to a directory and run mvn.bat\|.sh in the bin subdirectory to install. Add the bin subdirectory to you system path.

Maven needs a repository. Typically it is at the following:

  • Windows - C:\Documents and Settings\.m2\repository
  • Linux/unix - \~/.m2/repository

From the DayTrader/branches/2.1.3 directory, type "mvn clean install" to build the project. (Note: If you see errors that say "java.util.zip.ZipException: error in opening zip file", ignore them for this exercise.)

Apply the DayTrader Patch

The following patch can be applied using a system or downloaded patch utility. (For example, you can get a patch utility for Windows from http://gnuwin32.sourceforge.net/packages/patch.htm .)

Download the appropriate patch and go to the DayTrader/branches.2.1.3 directory to apply it. For example, with the patch utility mentioned above, you can type:

patch \-p0 \-i <path-to>/daytrader_geronimo.patch

After you have applied the patch, you can see the changes from JPQL to the Criteria API in the java class org.apache.geronimo.samples.daytrader.ejb3.TradeSLSBBean. The changes are in the following 4 methods:

  • getMarketSummary()
  • getClosedOrders()
  • getAllQuotes()
  • getHoldings()

(Note: If you view these changes in eclipse, and you have previously run "mvn eclipse:eclipse" to setup eclipse projects, you'll have to run this command again in order for this file to compile.)

You can also Apply an Eclipse Patch

Re-create the DayTrader ear file

From the DayTrader/branches/2.1.3 directory, type "mvn clean install" to build the project.

Run DayTrader on Geronimo

This writeup assumes some familiarity with Apache Geronimo. The download and documentation can be found at http://geronimo.apache.org.

Install and start the Geronimo server.

Add jpa2 plugins from repository http://geronimo.apache.org/plugins/openjpa2. One way to do this is the following:

  1. Go to the Geronimo console at http://:8080/console and logon
  2. Select plugins
  3. Click on Add Repository and add http://geronimo.apache.org/plugins/openjpa2
  4. Click on Update Repository List
  5. Make sure the new repository is selected. Then click on Show Plugins in selected repository. On that panel:
    1. Select GeronimoPlugins, OpenJPA2::CAR 2.1.3-SNAPSHOT and GeronimoPlugins, OpenJPA2::Deployer 2.1.3-SNAPSHOT
    2. Click on Install
  6. On the next screen, click on Install

Deploy the DayTrader application. This can be done through the console as follows:

  1. Click on Deploy New
  2. For Archive, browse to DayTrader/branches/2.1.3/modules/ear/target/daytrader-ear-2.1.3.ear
  3. For Plan, browse to DayTrader/branches/2.1.3/plans/dayTrader-derby-plan.xml
  4. Check Start app after install
  5. Click on Install

Re-start the server.

Make sure that the system module, org.apache.geronimo.configs/axis-deployer/2.1.5/car, is running.

Run DayTrader:

  1. Go to http://:8080/daytrader/
  2. Click on the Configuration tab and click on (Re)-create DayTrader Database Tables and Indexes
  3. Click on the Configuration  tab and click on (Re)-populate DayTrader Database
  4. Click on the Trading & Portfolios tab, login, and start trading

Run DayTrader on WebSphere

This writeup assumes some familiarity with WebSphere. Also, the script that is provided assumes a local unmanaged node with a single server.

At a minimum, the WebSphere Application Server must be at version 7.0.0.9. You must also have installed the Feature Pack for OSGi Applications and Java Persistence API 2.0. Make sure you have a profile that is augmented for JPA 2.0 function.

Download the following jython script. This script is used to configure the objects needed by DayTrader (data sources, JMS queues and topics) and install the application.

daytrader_singleServer.py

Within the bin directory of the augmented profile:

  1. Start the server.
  2. Run the script using the following command:

    wsadmin -f <location ofdaytrader_singleServer.py> <script options>
    

    You can display the list of available script options by specifying the option "--help".

  3. Re-start the server.

Run DayTrader

  1. On a web browser, go to http://localhost:/daytrader/(The default application port is 9080. But, you may have a different one if you created a new profile.)
  2. Click on the Configuration tab and click on (Re)-create DayTrader Database Tables and Indexes
  3. Click on the Configuration  tab and click on (Re)-populate DayTrader Database
  4. Click on the Trading & Portfolios tab, login, and start trading
Copyright © 2006,2020 The Apache Software Foundation. Licensed under Apache License 2.0.
Apache, the Apache feather logo and OpenJPA are trademarks of The Apache Software Foundation.
Other names may be trademarks of their respective owners.