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

Container-Managed Persistence in Borland Enterprise Server There are two classes that represent the entities which correspond to these tables, the Address and Country classes. The Address class contains a direct pointer, country, to the Country entity. This direct pointer reference is an EJBObject reference; it is not a direct Java reference to the implementation bean. Now examine the code for both classes: //Address Class public class Address extends EntityBean { public int id; public String street1; public String street1; public String city; public String state; public String zip; public Country country; // this is a direct pointer to the Country } //Country Class public class Country extends EntityBean { public int id; public String name; public int exchange; public String currency; } In order for the Container to resolve the reference from the Address class to the Country class, you must specify information about the Country class in the deployment descriptor. Using the entry in the deployment descriptor, you instruct the Container to link the reference to the field Address.country to the JNDI name for the home object, CountryHome. (Look at the pigs example for a more detailed explanation.) The container optimizes this cross-entity reference; because of the optimization, using the cross reference is as fast as storing the value of the foreign key. However, there are two important differences between using a cross reference and storing the foreign key value: ■ ■ When you use a cross reference pointer to another entity, you do not have to call the other entity's home object findByPrimaryKey() method to retrieve the corresponding object entity. Using the above example as an illustration, the Address.country pointer to the Country object lets you retrieve the country object directly. You do not have to call CountryHome.findByPrimaryKey(address.country) to get the Country object that corresponds to the country id. When you use a cross reference pointer, the state of the referenced entity is only loaded when you actually use it. It is not automatically loaded when the entity containing the pointer is loaded. That is, merely loading in an Address object does not actually load in a Country object. You can think of the Address.country field as a “lazy” reference, though when the underlying object is actually used does a “lazy” reference load in its corresponding state. (Note that this “lazy” behavior is a part of the EJB model.) This facet of the EJB model results in the decoupling of the life cycle of Address.country from the life cycle of the Address bean instance itself. According to the model, Address.country is a normal entity EJBObject reference; thus, the state of Address.country is only loaded when and if it is used. The Container follows the EJB model and controls the state of AddressBean.country as it does with any other EJBObject. Container-managed field names The Borland Container has changed the container-managed persistent field names so that they are more Java friendly. SQL column names often prepend a shortened form of the table name, followed by an underscore, to each column name. For example, in the address table, there is a column for the city called addr_city. The full reference to this column is address.addr_city. With the Borland Container, this maps to the Java Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 119

Setting Properties Setting Properties field Address.city, rather than the more redundant and more awkward Address.addr_city. You can achieve this Java-friendly column-to-field-name mapping using the deployment descriptor. While this section shows you how to manually edit the deployment descriptor, it is best to use the Deployment Descriptor Editor GUI to accomplish this. See the User’s Guide for instructions on using the GUI screens. Should you choose to manually edit the deployment descriptor, use the , , and subtags within the tag. Place the more friendly Java field name in the tag, noting that it is referencing a JDBC column. Put the type of the field in the tag. Lastly, place the actual SQL column name in the tag. The following deployment descriptor code segment illustrates this: ejb.cmp.jdbc.column:city String addr_city Most properties for Enterprise JavaBeans can be set in their deployment descriptors. The Borland Deployment Descriptor Editor (DDEditor) also allows you to set properties and edit descriptor files. Use of the Deployment Descriptor Editor is described in the Borland Enterprise Server User's Guide. Use properties in the deployment descriptor to specify information about the entity bean's interfaces, transaction attributes, and so forth, plus information that is unique to an entity bean. In addition to the general descriptor information for entity beans, here are also three sets of properties that can be set to customize CMP implementations, entity properties, table properties, and column properties. Entity properties can be set either by the EJB Designer Tab in the Deployment Descriptor Editor or in the XML directly. Using the Deployment Descriptor Editor You can use the Deployment Descriptor Editor, which is part of the Borland Enterprise Server AppServer Edition, to set up all of the container-managed persistence information. You should refer to the Borland Enterprise Server User's Guide for complete information on the use of the Deployment Descriptor Editor and other related tools. J2EE 1.2 Entity Bean using BMP or CMP 1.1 Table 14.1 J2EE 1.2 Entity Bean using BMP or CMP 1.1 Descriptor Element Navigation Tree Node/ Panel Name DDEditor Tab Entity Bean name Bean General Entity Bean class Bean General Home Interface Bean General Remote Interface Bean General Home JNDI Name Bean General Persistence Type (CMP or BMP) Bean General Primary Key Class Bean General Reentrancy Bean General Icons Bean General 120 BES Developer’s Guide

Setting Properties<br />

Setting Properties<br />

field Address.city, rather than the more redundant and more awkward<br />

Address.addr_city.<br />

You can achieve this Java-friendly column-to-field-name mapping using the<br />

deployment descriptor. While this section shows you how to manually edit the<br />

deployment descriptor, it is best to use the Deployment Descriptor Editor GUI to<br />

accomplish this. See the User’s Guide for instructions on using the GUI screens.<br />

Should you choose to manually edit the deployment descriptor, use the ,<br />

, and subtags within the tag.<br />

Place the more friendly Java field name in the tag, noting that it is<br />

referencing a JDBC column. Put the type of the field in the tag. Lastly,<br />

place the actual SQL column name in the tag. The following<br />

deployment descriptor code segment illustrates this:<br />

<br />

ejb.cmp.jdbc.column:city<br />

String<br />

addr_city<br />

<br />

Most properties for Enterprise JavaBeans can be set in their deployment descriptors.<br />

The <strong>Borland</strong> Deployment Descriptor Editor (DDEditor) also allows you to set properties<br />

and edit descriptor files. Use of the Deployment Descriptor Editor is described in the<br />

<strong>Borland</strong> Enterprise Server User's Guide. Use properties in the deployment descriptor to<br />

specify information about the entity bean's interfaces, transaction attributes, and so<br />

forth, plus information that is unique to an entity bean. In addition to the general<br />

descriptor information for entity beans, here are also three sets of properties that can<br />

be set to customize CMP implementations, entity properties, table properties, and<br />

column properties. Entity properties can be set either by the EJB Designer Tab in the<br />

Deployment Descriptor Editor or in the XML directly.<br />

Using the Deployment Descriptor Editor<br />

You can use the Deployment Descriptor Editor, which is part of the <strong>Borland</strong> Enterprise<br />

Server AppServer Edition, to set up all of the container-managed persistence<br />

information. You should refer to the <strong>Borland</strong> Enterprise Server User's Guide for<br />

complete information on the use of the Deployment Descriptor Editor and other related<br />

tools.<br />

J2EE 1.2 Entity Bean using BMP or CMP 1.1<br />

Table 14.1 J2EE 1.2 Entity Bean using BMP or CMP 1.1<br />

Descriptor Element<br />

Navigation Tree Node/<br />

Panel Name<br />

DDEditor Tab<br />

Entity Bean name Bean General<br />

Entity Bean class Bean General<br />

Home Interface Bean General<br />

Remote Interface Bean General<br />

Home JNDI Name Bean General<br />

Persistence Type (CMP or BMP) Bean General<br />

Primary Key Class Bean General<br />

Reentrancy Bean General<br />

Icons Bean General<br />

120 BES Developer’s Guide

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

Saved successfully!

Ooh no, something went wrong!