12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />

Although the PM does not manage transactions (this is the Container's responsibility),<br />

it is aware of transaction start and completion and can therefore manage entity state.<br />

The PM uses the TxContext class to represent the root of managed entities during<br />

transaction lifecycles. When the container manages a transaction it asks the PM for the<br />

associated TxContext instance. If none exists, as is the case when a new transaction<br />

has started, one is created by the PM. When a transaction is completing, the container<br />

calls the method TxContext.beforeCompletion() to alert the PM to verify entity state.<br />

The PM has complete responsibility for entity data storage and the maintenance of the<br />

state of relationships between entities. Relationship editing is also managed by the PM.<br />

This simplifies interactions with the container and allows the PM to optimize its read<br />

and write operations. This approach also suppresses duplicate find requests by<br />

tracking returned primary keys for requested entities. Data from duplicate find<br />

operations can then be returned from the first load of the entity's data.<br />

<strong>Borland</strong> CMP engine's CMP 2.0 implementation<br />

In CMP 2.0, the details of constructing finder and select methods have been pushed<br />

into the EJB 2.0 specification. Users should thoroughly inspect the specification for<br />

details on implementing their database SQL. The <strong>Borland</strong> EJB Container is fullycompliant<br />

with the EJB 2.0 specification and supports all of its features.<br />

The implementation class for an entity bean using 2.0 container-managed persistence<br />

is different from that of a bean using 1.1 container-managed persistence. The major<br />

differences are as follows:<br />

■<br />

The class is declared as an abstract class.<br />

■<br />

There are no public declarations for the fields that are container-managed fields.<br />

Instead, there are abstract get and set methods for container-managed fields.<br />

These methods are abstract because the container provides their implementation.<br />

For example, rather than declaring the fields balance and name, the CheckingAccount<br />

class might include these get and set methods:<br />

public abstract float getBalance();<br />

public abstract void setBalance(float bal);<br />

public abstract String getName();<br />

public abstract void setName(String n);<br />

■<br />

Container-managed relationship fields are likewise not declared as instance<br />

variables. The class instead provides abstract get and set methods for these fields,<br />

and the container provides the implementation for these methods.<br />

Table Mapping for CMP 2.0 is accomplished using the vendor-specific ejb-borland.xml<br />

deployment descriptor. The descriptor is a companion to the ejb-jar.xml descriptor<br />

described in the EJB 2.0 specification. <strong>Borland</strong> uses the XML tag as an<br />

enclosure for table mapping data as needed. Then you use the and<br />

its associated elements to specify particular information about the<br />

entity bean's implementation. Use the DTD for syntax of the XML grammar.<br />

Optimistic Concurrency Behavior<br />

The container uses optimistic or pessimistic concurrency to control the behavior of<br />

multiple transactions accessing the same data. BES has four optimistic concurrency<br />

behaviors which are specified as Table Properties. These behaviors are:<br />

■<br />

SelectForUpdate<br />

■<br />

SelectForUpdateNoWAIT<br />

■<br />

UpdateAllFields<br />

■<br />

UpdateModifiedFields<br />

130 BES Developer’s Guide

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

Saved successfully!

Ooh no, something went wrong!