![]() |
Container-Managed Transaction Bank Sample Application |
Container-Managed Transaction Bank Sample Application
This document describes how to utilize the Container-Managed Transaction Bank sample application in conjunction with Sun ONE Application Server version 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Application
Deploying the Sample Application
Overview
In this section, the Container-Managed Transaction Bank sample application is described.The Container-Managed Transaction Bank sample application uses container managed-transactions demonstrates how to roll-back a container-managed transaction, synchronizing a session bean's instance variables with the database values. In an enterprise bean with container-managed transactions, the EJB container sets the boundaries of the transactions. You can use container-managed transactions with any type of enterprise bean: session, entity, or message-driven. Container-managed transactions simplify development because the enterprise bean code does not explicitly mark the transaction's boundaries. The code does not include statements that begin and end the transaction.
Typically, the container begins a transaction immediately before an enterprise bean method starts. It commits the transaction just before the method exits. Each method can be associated with a single transaction. Nested or multiple transactions are not allowed within a method. Container-managed transactions do not require all methods to be associated with transactions. When deploying a bean, you specify which of the bean's methods are associated with transactions by setting the transaction attributes.
To better understand sample application source code, you can generate javadocs using asant javadocs and access them at <install_dir>/samples/transactions/ejb/cmt/bank/javadocs/index.html.
In order to successfully deploy and run the transactions-bank sample application, Database resources (PointBase) needs to be setup with the Application Server.
If you want to run this sample on Oracle Database, please refer to (How to run sample applications with Oracle ) .
Compiling and Assembling the Application
To compile and assemble the application, follow these steps:
Go to the src directory of the sample. For example:
Execute asant all under <s1as_install_dir>/samples/transactions/ejb/cmt/bank/src/
- cd <install_dir>/samples/transactions/ejb/cmt/bank/src
Clean the web application project area. For example:
- The default target core will be executed to rebuild the JAR file.
- Execute asant clean to remove the sample application's assemble and build directories. This is required when you want to rebuild the application.
Deploying the Sample Application
The deployment process includes deploying the application EAR, configuring the database and registering required resources to Sun ONE Application Server. Installation comes with already configured PointBase database. If you choose to use prepopulated PointBase database, you do not need to configure the database.You may select one of the following methods of deploying and registering the application:
Command Line Interface (CLI)-based Deployment describes how to manually register the sample application using a Command Line Interface (CLI). This is the fastest means of deploying the application to the application server.
Web Interface (GUI)-based Deployment describes how to use the Sun ONE Deployment Tool to import and deploy the sample application. Alternatively, you can also assemble the application from scratch and deploy it using the Deployment Tool.
Command Line Interface (CLI)-based Deployment
Since the sample application is supplied with a complete EAR file, the fastest means of setting up the application is to use the command line utilities as described in this section. If you would like to experience either deploying through a Web based tool, then follow instructions in Web Interface (GUI)-based Deployment.TThere are two command line utilities to deploy the application, Using asant script or Using asadmin command.
Go to the src directory of the sample. For example:
Execute the following command:
- <install_dir>/samples/transactions/ejb/cmt/bank/src
- asant deploy
Go to the bin of the sample directory. For example:
The deployment process involves the following operations:
Execute asadmin to deploy the module to the local application server instance. For example, go to:
- <install_dir>/bin/
Execute the following:
- s1as_install_dir/samples/transactions/ejb/cmt/bank
Commit the changes. For example:
- asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name>
- asadmin reconfig -H <host> -p <Admin Port> -u <user> -w <password> <instancename>
Authenticates against the local application server's administrative server.
If you would like to verify the registration of the application, proceed to Verifying Registration. Otherwise, you are now ready to exercise the application by Running the Sample Application.The EAR file is transferred to the administrative server.
The administrative server begins the registration process:
Verifying Registration
As an optional step, you can use the Sun ONE Application Server Administration Tool to verify that the application has been registered. If you do not want to verify that the application has been registered, proceed directly to Running the Sample Application.To verify the registration of the application, do one of the following:
Execute asadmin to look at applications deployed with a server instance. For example:
You will see the transactions-bank app as one of the listed applications.
- asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>
Web Interface (GUI)-based Deployment
Login to web-based administration tool from browser.
Click on the Deploy icon.
- Application Server Instances --> <server instance> -- Applications --> Enterprise Applications
Use Browse button to locate the transactions-bank.ear file and then click OK button.
Type in product in "App Name" and then click OK.
Verify that the application is deployed by clicking on the product link.
Running the Sample Application
This describes how to start and navigate through the application.Running the sample is a two step process:
Go to the directory where the sample has been deployed.
Run appclient using the following instructions:
- > cd <s1as_install_dir>/domains/domain1/server1/applications/j2ee-apps/transactions-bank_1/
- > appclient -client transactions-bankClient.jar -name BankClient -textauth
- You will see the following output:
- ...
- checking: 60.0
- saving: 540.0
In order to run the application again, you must run asant sql in the <install_dir>/samples/transactions/ejb/cmt/bank/src directory in order to restore the database to its original state.
Troubleshooting
Make certain that you run asant undeploy before redeploying this sample to make sure that all modules are undeployed and the resources are disabled.
You may also restore the orginal state of the database by executing asant sql in the <install_dir>/samples/transactions/ejb/cmt/bank/src directory.
When using the admin UI to restart the Sun ONE application server, it may be necessary to click on 'Apply Changes' then on 'RestartServer'.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated July 26, 2002