web server - Borland Technical Publications

web server - Borland Technical Publications web server - Borland Technical Publications

techpubs.borland.com
from techpubs.borland.com More from this publisher
12.11.2014 Views

Chapter 15 15Entity Beans and Table Mapping for Chapter CMP 2.0 Important Here we'll examine how entity beans are deployed in the Borland Enterprise Server and how persistence of entities can be managed. This is not, however, an introduction to entity beans and should not be treated as such. Rather, this document will explore the implications of using entity beans within Borland Partitions. We'll discuss descriptor information, persistence options, and other container-optimizations. Information on the Borland-specific deployment descriptors and implementations of Container-Managed Persistence (CMP) will be documented in favor of general EJB information that is generally available from the J2EE Specifications from Sun Microsystems. For documentation updates, go to www.borland.com/techpubs/bes. Entity Beans Entity beans represent a view of data stored in a database. Entity beans can be finegrained entities mapping to a single table with a one-to-one correspondence between entity beans and table rows. Or, entity beans can span multiple tables and present data independent of the underlying database schema. Entity beans can have relationships with one another, can be queried for data by clients, and can be shared among different clients. Deploying your Entity Bean to one of the Borland Enterprise Server Partitions requires that it be packaged as a part of a JAR. The JAR must include two descriptor files: ejbjar.xml and the proprietary ejb-borland.xml file. The ejb-jar.xml descriptor is fullydocumented in the J2EE 1.3 Specification. The DTD for ejb-borland.xml is reproduced in this document and aspects of its usage documented here. The Borland proprietary descriptor allows for the configuration of a number of properties that can be set to optimize container performance and manage the persistence of your entity beans. Chapter 15: Entity Beans and Table Mapping for CMP 2.0 127

Container-managed persistence and Relationships Container-managed persistence and Relationships Borland's EJB container provides tools that generate the persistence calls at the time that the entity bean is deployed; that is, when the entity bean is installed into a Partition. The tools use the deployment descriptors to determine the instance fields which must be persisted. Instead of coding the database access directly in the bean, the bean provider of a container-managed entity bean must specify in the deployment descriptor those instance fields for which the container tools must generate access calls. The container has sophisticated deployment tools capable of mapping the fields of an entity bean to its data source. Container-managed persistence has many advantages over bean-managed persistence. It is simpler to code because the bean provider does not have to code the database access calls. Handling of persistence can also be changed without having to modify and recompile the entity bean code. The Deployer or Application Assembler can do this by modifying the deployment descriptor when deploying the entity bean. Shifting the database access and persistence handling to the container not only reduces the complexity of code in the bean, it also reduces the scope of possible errors. The bean provider can focus on debugging the business logic of the bean rather than the underlying system issues. Borland's Persistence Manager (PM) not only persists CMP fields but also CMP relationships. The container manages bean relationships and maintains the referential integrity of these relationships. Just as you defined container-managed persistence fields in a bean's deployment descriptor, you can now define container-managed relationship fields in the deployment descriptor. The container supports relationships of various cardinalities, including one-to-one, one-to-many, and many-to-many. Packaging Requirements Like session beans, entity beans can expose their methods with a remote interface or with a local interface. The remote interface exposes the bean's methods across the network to other, remote components. The local interface exposes the bean's methods only to local clients; that is, clients located on the same EJB container. Entity beans that use EJB 2.0 container-managed persistence should use the local model. That is, the entity bean's local interface extends the EJBLocalObject interface. The bean's local home interface extends the EJBLocalHome interface. You must deploy these interfaces as well as an implementation of your bean's class. Each Entity Bean must also have corresponding entries in its JAR's deployment descriptors. The standard deployment descriptor, ejb-jar.xml contains essentially three different types of deployment information. These are: 1 General Bean Information: This corresponds to the elements found in the descriptor file and is used for all three types of beans. This information also includes information on the bean's interfaces and class, security information, environmental information, and even query declarations. 2 Relationships: This corresponds to the elements found in the descriptor file and applies to entity beans using CMP only. This is where containermanaged relationships are spelled out. 3 Assembly Information: This corresponds to the element which explains how the beans interact with the application as a whole. Assembly information is broken down into four categories: ■ ■ Security Roles: simple definitions of security roles used by the application. Any security role references you defined for your beans must also be defined here. Method Permissions: each method of each bean can have certain rules about their execution. These are set here. 128 BES Developer’s Guide

Container-managed persistence and Relationships<br />

Container-managed persistence and Relationships<br />

<strong>Borland</strong>'s EJB container provides tools that generate the persistence calls at the time<br />

that the entity bean is deployed; that is, when the entity bean is installed into a<br />

Partition. The tools use the deployment descriptors to determine the instance fields<br />

which must be persisted. Instead of coding the database access directly in the bean,<br />

the bean provider of a container-managed entity bean must specify in the deployment<br />

descriptor those instance fields for which the container tools must generate access<br />

calls. The container has sophisticated deployment tools capable of mapping the fields<br />

of an entity bean to its data source.<br />

Container-managed persistence has many advantages over bean-managed<br />

persistence. It is simpler to code because the bean provider does not have to code the<br />

database access calls. Handling of persistence can also be changed without having to<br />

modify and recompile the entity bean code. The Deployer or Application Assembler can<br />

do this by modifying the deployment descriptor when deploying the entity bean. Shifting<br />

the database access and persistence handling to the container not only reduces the<br />

complexity of code in the bean, it also reduces the scope of possible errors. The bean<br />

provider can focus on debugging the business logic of the bean rather than the<br />

underlying system issues.<br />

<strong>Borland</strong>'s Persistence Manager (PM) not only persists CMP fields but also CMP<br />

relationships. The container manages bean relationships and maintains the referential<br />

integrity of these relationships. Just as you defined container-managed persistence<br />

fields in a bean's deployment descriptor, you can now define container-managed<br />

relationship fields in the deployment descriptor. The container supports relationships of<br />

various cardinalities, including one-to-one, one-to-many, and many-to-many.<br />

Packaging Requirements<br />

Like session beans, entity beans can expose their methods with a remote interface or<br />

with a local interface. The remote interface exposes the bean's methods across the<br />

network to other, remote components. The local interface exposes the bean's methods<br />

only to local clients; that is, clients located on the same EJB container.<br />

Entity beans that use EJB 2.0 container-managed persistence should use the local<br />

model. That is, the entity bean's local interface extends the EJBLocalObject interface.<br />

The bean's local home interface extends the EJBLocalHome interface. You must deploy<br />

these interfaces as well as an implementation of your bean's class.<br />

Each Entity Bean must also have corresponding entries in its JAR's deployment<br />

descriptors. The standard deployment descriptor, ejb-jar.xml contains essentially<br />

three different types of deployment information. These are:<br />

1 General Bean Information: This corresponds to the elements<br />

found in the descriptor file and is used for all three types of beans. This information<br />

also includes information on the bean's interfaces and class, security information,<br />

environmental information, and even query declarations.<br />

2 Relationships: This corresponds to the elements found in the<br />

descriptor file and applies to entity beans using CMP only. This is where containermanaged<br />

relationships are spelled out.<br />

3 Assembly Information: This corresponds to the element<br />

which explains how the beans interact with the application as a whole. Assembly<br />

information is broken down into four categories:<br />

■<br />

■<br />

Security Roles: simple definitions of security roles used by the application. Any<br />

security role references you defined for your beans must also be defined here.<br />

Method Permissions: each method of each bean can have certain rules about<br />

their execution. These are set here.<br />

128 BES Developer’s Guide

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

Saved successfully!

Ooh no, something went wrong!