10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

method, like all methods in session beans that use container-managed transaction demarcation,<br />

has an implicit Required transaction attribute. That is, you don’t need to explicitly decorate the<br />

method with a @TransactionAttribute annotation.<br />

<strong>Java</strong> Persistence Entities<br />

For each business entity represented in our simple bank, the Duke’s Bank application has a<br />

matching <strong>Java</strong> Persistence API entity:<br />

■ Account<br />

■ Customer<br />

■ Tx<br />

<strong>The</strong> purpose of these entities is to provide an object view of these database tables:<br />

bank_account, bank_customer, and bank_tx. For each column in a table, the corresponding<br />

entity has an instance variable. Because they use the <strong>Java</strong> Persistence API, the entities contain no<br />

SQL statements that access the tables. <strong>The</strong> enterprise bean container manages all data in the<br />

underlying data source, including adding, updating, and deleting data from the database tables.<br />

Unlike the session beans, the entities do not validate method parameters. <strong>The</strong> session beans<br />

check the parameters and throw the application exceptions, such as<br />

CustomerNotInAccountException and IllegalAccountTypeException. Consequently, if<br />

some other application were to include these entities, its session beans would also have to<br />

validate the method parameters. Validation code was not added to the entity’s methods, in<br />

order to keep the business logic separate from the entity data.<br />

Helper Classes<br />

<strong>The</strong> EJB JAR files include several helper classes that are used by the enterprise beans. <strong>The</strong> source<br />

code for these classes is in the following directory:<br />

tut-install/javaeetutorial5/examples/dukesbank/dukesbank-ejb/src/java/com/sun/tutorial/javaee/dukesbank/util/<br />

Table 37–1 briefly describes the helper classes.<br />

TABLE 37–1 Helper Classes for the Application’s Enterprise Beans<br />

Class Name Description<br />

AccountDetails Encapsulates the state of an Account instance. Returned by the getDetails<br />

method of AccountControllerBean.<br />

CustomerDetails Encapsulates the state of a Customer instance. Returned by the getDetails<br />

method of CustomerControllerBean.<br />

Enterprise Beans<br />

Chapter 37 • <strong>The</strong> Duke’s Bank Application 1053

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!