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 CASE 1: A development environment without existing database tables using either JDataStore or Cloudscape databases. CASE 2: A deployment environment with (or without) existing database tables using supported databases. In this case, the Borland CMP engine creates tables automatically, assuming that the entity bean name is the same as the desired table name. You need only provide the bean's name and its associated datasource as a property: CustomerEJB ejb.datasource serial://ds/myDatasource The Borland CMP engine will automatically create tables in this datasource based on the bean's name and fields. In this case, you need to supply information on the tables to which the entities map. You'll provide a table name in the portion of the descriptor, and some properties in the portion: CustomerEJB CUSTOMER . . CUSTOMER datasource serial://ds/myDatasource Note that the datasource property is called datasource when specified in the element and ejb.datasource when in the element. If you are using a database other than JDataStore or Cloudscape and would like to have the Borland CMP engine automatically create this table, add the following XML to the element: . . CUSTOMER create-tables True Basic Mapping of CMP fields to columns Basic field mapping is accomplished using the element in the ejbborland.xml deployment descriptor. In this element, you specify a field name and a corresponding column to which it maps. Consider the following XML for an entity bean called LineItem, which maps two fields, orderNumber and line, to two columns, ORDER_NUMBER and LINE: LineItem orderNumber Chapter 15: Entity Beans and Table Mapping for CMP 2.0 133

Container-Managed Persistence in Borland Enterprise Server ORDER_NUMBER line LINE Mapping one field to multiple columns Many users may employ coarse-grained entity beans that implement a Java class to represent more fine-grained data. For example, an entity bean might use an Address class as a field, but may need to map elements of the class (like AddressLine1, AddressCity, and so forth) to an underlying database. To do this, you use the element, which defines a field map between your fine-grained class and its underlying database representation. Note that such classes must implement java.io.Serializable and all their data members must be public. Consider an entity bean called Customer that uses the class Address to represent a customer's address. The Address class has fields for AddressLine, AddressCity, AddressState, and AddressZip. Using the following XML, we can map the class to its representation in a database with corresponding columns: Customer . . Address Address.AddressLine STREET Address.AddressCity CITY Address.AddressState STATE Address.AddressZip ZIP . . Note that we use one element per database column. 134 BES Developer’s Guide

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

CASE 1: A<br />

development<br />

environment without<br />

existing database<br />

tables using either<br />

JDataStore or<br />

Cloudscape databases.<br />

CASE 2: A deployment<br />

environment with (or<br />

without) existing<br />

database tables using<br />

supported databases.<br />

In this case, the <strong>Borland</strong> CMP engine creates tables automatically, assuming that the<br />

entity bean name is the same as the desired table name. You need only provide the<br />

bean's name and its associated datasource as a property:<br />

<br />

CustomerEJB<br />

<br />

ejb.datasource<br />

serial://ds/myDatasource<br />

<br />

<br />

The <strong>Borland</strong> CMP engine will automatically create tables in this datasource based on<br />

the bean's name and fields.<br />

In this case, you need to supply information on the tables to which the entities map.<br />

You'll provide a table name in the portion of the descriptor, and some<br />

properties in the portion:<br />

<br />

CustomerEJB<br />

<br />

CUSTOMER<br />

<br />

<br />

.<br />

.<br />

<br />

CUSTOMER<br />

<br />

datasource<br />

serial://ds/myDatasource<br />

<br />

<br />

Note that the datasource property is called datasource when specified in the <br />

element and ejb.datasource when in the element. If you are using<br />

a database other than JDataStore or Cloudscape and would like to have the <strong>Borland</strong><br />

CMP engine automatically create this table, add the following XML to the <br />

element:<br />

.<br />

.<br />

<br />

CUSTOMER<br />

<br />

create-tables<br />

True<br />

<br />

<br />

Basic Mapping of CMP fields to columns<br />

Basic field mapping is accomplished using the element in the ejbborland.xml<br />

deployment descriptor. In this element, you specify a field name and a<br />

corresponding column to which it maps. Consider the following XML for an entity bean<br />

called LineItem, which maps two fields, orderNumber and line, to two columns,<br />

ORDER_NUMBER and LINE:<br />

<br />

LineItem<br />

<br />

<br />

orderNumber<br />

Chapter 15: Entity Beans and Table Mapping for CMP 2.0 133

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

Saved successfully!

Ooh no, something went wrong!