|
WebLogic Server 6.1 Code Examples, BEA Systems, Inc. | |||||
See:
Description
| Interface Summary | |
| Account | The methods in this interface are the public face of AccountBean. |
| AccountHome | This interface is the home interface for the EJBean AccountBean, which in WebLogic is implemented by the code-generated container class AccountBeanC. |
| Bank | |
| BankHome | |
| Customer | Interface for a customer bean. |
| CustomerHome | This interface is the home interface for the EJBean CustomerBean. |
| Class Summary | |
| AccountBean | AccountBean is an EntityBean. |
| BankBean | |
| Client | This class demonstrates CMP relationships and EJB-QL by performing the following: |
| CustomerBean | Represents a customer and demonstrates one to many releationship with AccountBean. |
This example is a package that demonstrates the removal of information using cascade delete with the Oracle database. It uses the one-to-many relationships between two EJB's written to the EJB 2.0 specification.The example includes entity EJBeans calledAccountBean, BankBean, and CustomerBean.
The example demonstrates:
The EJB 2.0 examples included in the WebLogic Server 6.1 distribution are not shipped pre-built.To run these examples, you must build the example following the specific examples instructions.
To get the most out of this example, first read through the sourcecode files.
You WILL need to set up the persistent storage of theEJBean. You'll use a database for the persistent storage of the entity EJBean. Each instance ofan EJBean is written to a row in a table. The table (Accounts and Customers) must be created and exist in the databasebefore the example is run.
You'll need to create the following tables in your Oracle database using the following SQLstatements :
"create table cascade_Customers(cust_name varchar(20) constraint pkCustCD primary key, acct_id varchar(20), cust_age integer, cust_level integer, cust_last date);""create table cascade_Accounts(acct_id varchar(20) constraint pkAcctCD primary key, bal numeric, type varchar(20), cust_name varchar(20) CONSTRAINT fk_cust_name REFERENCES cascade_Customers(cust_name) ON DELETE CASCADE);""commit;"
Note: that the persistent storage is completely invisible to theclient; the actual storage is handled automatically by the containerand not by the EJBean. All database properties, such as the loginname and password, are defined in the connection pool. A preconfigured connection pool is included in the example server.
These three sections cover what to do:
We provide a build script for you to build the example:
The build script is build.xml.
Run the build script using the following Java ant command:
$ant
The script will build the example and place the files in thecorrect locations in your WebLogic Server distribution:
Running the build script places the EJB in /config/examples/applications, where it automaticallydeploys once the server is started. If you are already running the server and buildanother EJB, it is automatically placed in this directory and instantly deployed.
Additional information on using the build scriptsis found in Building Enterprise JavaBean examples
A list of deployed EJBs displays.
Although a sample connection pool is provided for many of the EJB 2.0 examples, for this example, you must make sure that your sample connection pool, called demoPool points to the oraclePool.
You'll need to:
# In the left pane, expand the Services node and choose JDBC.
# Click demoPool to display the configuration information in the right pane.
# Click the Connections tab and review the attribute settings to make sure that they are correct.
In particular, make sure that the URL and Driver Classname attributes are set for Oracle database.The example connection pool is preconfigured for Cloudscape. For other databases,you will need to set an appropriate url and driver, such as
URL=jdbc:weblogic:oracle,\ DriverName=weblogic.jdbc.oci.Driver,\
In this example, the fileRealm for the access control list (ACL) is preconfigured to allowaccess for everyone.
If you need more information about how to use connection pools, read UsingWebLogic JDBC: Using connection pools.
$ java examples.ejb20.cascadeDelete.one2many.Client
If you're not running the WebLogic Server with its default settings,you will have to run the client using:
$ java examples.ejb20.cascadeDelete.one2many.Client "t3://WebLogicURL:Port"
where:
Beginning examples.ejb20.cascadeDelete.one2many.Client...Create Accounts and customers: Creating account account0 with a balance of 0.0 account type null... Account account0 successfully created Creating customer customer0... Customer customer0 successfully createdCreating account account1 with a balance of 1000.0 account type Savings...Account account1 successfully createdCreating customer customer1...Customer customer1 successfully createdCreating account account2 with a balance of 2000.0 account type null...Account account2 successfully createdCreating customer customer2...Customer customer2 successfully createdCreating account account3 with a balance of 3000.0 account type Savings...Account account3 successfully createdCreating customer customer3...Customer customer3 successfully createdCreating account account4 with a balance of 4000.0 account type null...Account account4 successfully createdCreating customer customer4...Customer customer4 successfully createdCreated Five Customers and Five Accounts Establish One-to-Many Relationships between Customer and Accounts: Add account account0 to customer0 Add customer customer0 to account account0 Add account account1 to customer0 Add customer customer0 to account account1 Add account account2 to customer0 Add customer customer0 to account account2 Add account account3 to customer3 Add customer customer3 to account account3 Add account account4 to customer3 Add customer customer3 to account account4 Print Customers: Customer: customer0 has accounts: account2 with balance 2000.0 account1 with balance 1000.0 account0 with balance 0.0 Customer: customer1 has accounts: Customer: customer2 has accounts: Customer: customer3 has accounts: account4 with balance 4000.0 account3 with balance 3000.0 Customer: customer4 has accounts: Print Accounts: Account: account0 has customers: customer0 Account: account1 has customers: customer0 Account: account2 has customers: customer0 Account: account3 has customers: customer3 Account: account4 has customers: customer3 Cascade Delete: Removing customer 0 and cascade delete its accounts customer0 removed Print Customers: Customer: customer0 not found Customer: customer1 has accounts: Customer: customer2 has accounts: Customer: customer3 has accounts: account4 with balance 4000.0 account3 with balance 3000.0 Customer: customer4 has accounts: Print Accounts: Account: account0 not found Account: account1 not found Account: account2 not found Account: account3 has customers: customer3 Account: account4 has customers: customer3 cleanup... customer1 removed customer2 removed customer3 removed customer4 removed Done cleanup...- You should receive output from the client application similar to this:
Beginning examples.ejb20.one2many.Client...Creating bank ... Bank successfully created Create Accounts and customers: Creating account account0 with a balance of 0.0 account type null... Account account0 successfully created Creating customer customer0... Customer customer0 successfully createdCreating account account1 with a balance of 1000.0 account type Savings...Account account1 successfully createdCreating customer customer1...Customer customer1 successfully createdCreating account account2 with a balance of 2000.0 account type null...Account account2 successfully createdCreating customer customer2...Customer customer2 successfully createdCreating account account3 with a balance of 3000.0 account type Savings...Account account3 successfully createdCreating customer customer3...Customer customer3 successfully createdCreating account account4 with a balance of 4000.0 account type null...Account account4 successfully createdCreating customer customer4...Customer customer4 successfully created Establish One-to-Many Relationships between Customer and Accounts:Add account account0 to customer0 Add customer customer0 to account account0 Add account account1 to customer0 Add customer customer0 to account account1 Add account account2 to customer0 Add customer customer0 to account account2 Add account account3 to customer3 Add customer customer3 to account account3 Add account account4 to customer3 Add customer customer3 to account account4 Print Customers and Accounts Account: account0 has customers: customer0Account: account1 has customers: customer0Account: account2 has customers: customer0Account: account3 has customers: customer3Account: account4 has customers: customer3Cascade Delete: Removing customer 0 and cascade delete its accounts customer0 removedPrint Customers and Accounts Print Customers:Customer: customer0 not foundCustomer: customer1 has accounts:Customer: customer2 has accounts:Customer: customer3 has accounts: account4 with balance 4000.0 account3 with balance 3000.0Customer: customer4 has accounts:Print Accounts:Account: account0 not foundAccount: account1 not foundAccount: account2 not foundAccount: account3 has customers: customer3Account: account4 has customers: customer3Cleanup... End examples.ejb20.one2many.Client...
|
Documentation is available at http://e-docs.bea.com/wls/docs61 |
|||||