web server - Borland Technical Publications
web server - Borland Technical Publications web server - Borland Technical Publications
Container-Managed Persistence in Borland Enterprise Server Note or: where a = b a = b The Container converts a = b to the same where clause, where a = b. However, it leaves unmodified an empty string defined as “” . The empty string makes it easy to specify the findAll() method. When you specify just an empty string, the Container construes that to mean the following: select [values] from [table]; Such a select statement would return all values from a particular table. Parameter substitution Parameter substitution is an important part of the where clause. The Borland EJB Container does parameter substitution wherever it finds the standard SQL substitution prefix colon (:). Each parameter for substitution corresponds to a name of a parameter in the finder specification found in the XML descriptor. For example, in the XML deployment descriptor, you might define the following finder method which takes a parameter balance (note that balance is preceded by a colon): findAccountsLargerThan(float balance) balance > :balance The Container composes a SQL select statement whose where clause is: balance > ? Note that the :balance parameter in the deployment descriptor becomes a question mark (?) in the equivalent SQL statement. When invoked, the Container substitutes the value of the parameter :balance for the ? in the where clause. Compound parameters The Container also supports compound parameters; that is, the name of a table followed by a column within the table. For this, it uses the standard dot (.) syntax, where the table name is separated from the column name by a dot. These parameters are also preceded by a colon. For example, the following finder method has the compound parameters :address.city and :address.state: findByCity(Address address) city = :address.city AND state = :address.state The where clause uses the city and state fields of the address compound object to select particular records. The underlying Address object could have Java Beans-style getter methods that correspond to the attributes city and state. Or, alternatively, it could have public fields that correspond to the attributes. Entity beans as parameters An entity bean can also serve as a parameter in a finder method. You can use an entity bean as a compound type. To do so, you must tell the CMP engine which field to use from the entity bean's passed reference to the SQL query. If you do not use the entity bean as a compound type, then the Container substitutes the bean's primary key in the where clause. For example, suppose you have a set of OrderItems entity beans associated with an Order entity object. You might have the following finder method: Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 117
Container-Managed Persistence in Borland Enterprise Server java.util.Collection OrderItemHome.findByOrder(Order order); This method returns all OrderItems associated with a particular Order. The deployment descriptor entry for its where clause would be: findByOrder(Order order) order_id = :order[ejb/orders] To produce this where clause, the Container substitutes the primary key of the Order object for the string :order[ejb/orders]. The string between the brackets (in this example, ejb/orders) must be the corresponding to the home of the parameter type. In this example, ejb/orders corresponds to an pointing to OrderHome. When you use an EJBObject as a compound type (using the dot notation), you are actually accessing the underlying get method for the field in the definition. For example, the following in the definition: order_id = :order.orderId calls the getOrderId() method on the order EJBObject and uses the result of the call in the selection criterion. Specifying relationships between entities Relational databases (RDBMS) permit records in one table to be associated with records in another table. The RDBMS accomplishes this using foreign keys; that is, a record in one table maintains a field (or column) that is a foreign key or reference to (usually) the primary key of a related record in another table. You can map these same references among entity beans. For the CMP engine to map references among entity beans, you use an entry in the deployment descriptor. The maps field names to their corresponding entities. The CMP engine uses this information in the deployment descriptor to locate the field's associated entity. (Refer to the pigs example for an illustration of the entry.) Any container-managed persistence field can correspond to a foreign key field in the corresponding table. When you look at the entity bean code, these foreign key CMP fields appear as object references. For example, suppose you have two database tables, an address table and a country table. The address table contains a reference to the country table. The SQL create statements for these tables might look as shown below. create table address ( addr_id number(10), addr_street1 varchar2(40), addr_street2 varchar(40), addr_city varchar(30), addr_state varchar(20), addr_zip varchar(10), addr_co_id number(4) * foreign key * ); create table country ( co_id number(4), co_name varchar2(50), co_exchange number(8, 2), co_currency varchar2(10) ); Note that the address table contains the field addr_co_id, which is a foreign key referencing the country table's primary key field, co_id. 118 BES Developer’s Guide
- Page 77 and 78: 66 BES Developer’s Guide
- Page 79 and 80: Web-enabling your CORBA server Impo
- Page 81 and 82: Configuring your Apache web server
- Page 83 and 84: Configuring your Apache web server
- Page 85 and 86: Web Services and Partitions ■ ■
- Page 87 and 88: Web Service providers Java:RPC prov
- Page 89 and 90: How Borland Web Services work
- Page 91 and 92: Packaging Web Service Application A
- Page 93 and 94: Tools Overview Java2WSDL tool Note
- Page 95 and 96: 84 BES Developer’s Guide
- Page 97 and 98: Client view of an enterprise bean L
- Page 99 and 100: Client view of an enterprise bean E
- Page 101 and 102: Managing transactions Managing tran
- Page 103 and 104: Support for JNDI Support for JNDI T
- Page 105 and 106: EJB to CORBA mapping A CORBA progra
- Page 107 and 108: 96 BES Developer’s Guide
- Page 109 and 110: Application Client architecture Pac
- Page 111 and 112: Document Type Definitions (DTDs) my
- Page 113 and 114: Support of references and links The
- Page 115 and 116: Use of Manifest files Use of Manife
- Page 117 and 118: 106 BES Developer’s Guide
- Page 119 and 120: Sessions in secondary storage If yo
- Page 121 and 122: 110 BES Developer’s Guide
- Page 123 and 124: Container-managed persistence and R
- Page 125 and 126: Implementing an entity bean Generat
- Page 127: Container-Managed Persistence in Bo
- Page 131 and 132: Setting Properties Setting Properti
- Page 133 and 134: Setting Properties into a BLOB. The
- Page 135 and 136: Setting Properties Automatic table
- Page 137 and 138: 126 BES Developer’s Guide
- Page 139 and 140: Container-managed persistence and R
- Page 141 and 142: Container-Managed Persistence in Bo
- Page 143 and 144: Container-Managed Persistence in Bo
- Page 145 and 146: Container-Managed Persistence in Bo
- Page 147 and 148: Container-Managed Persistence in Bo
- Page 149 and 150: Container-Managed Persistence in Bo
- Page 151 and 152: Container-Managed Persistence in Bo
- Page 153 and 154: 142 BES Developer’s Guide
- Page 155 and 156: Setting Properties J2EE 1.3 Entity
- Page 157 and 158: Setting Properties Figure 16.2 Edit
- Page 159 and 160: Setting Properties Table 16.1 ejb.m
- Page 161 and 162: Setting Properties Table 16.3 Table
- Page 163 and 164: Setting Properties Security Propert
- Page 165 and 166: Aggregate Functions in EJB-QL Selec
- Page 167 and 168: Support for ORDER BY Support for OR
- Page 169 and 170: Overriding SQL generated from EJB-Q
- Page 171 and 172: Container-managed data access suppo
- Page 173 and 174: 162 BES Developer’s Guide
- Page 175 and 176: Generating primary keys from a cust
- Page 177 and 178: Implementing primary key generation
Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />
java.util.Collection OrderItemHome.findByOrder(Order order);<br />
This method returns all OrderItems associated with a particular Order. The deployment<br />
descriptor entry for its where clause would be:<br />
<br />
findByOrder(Order order)<br />
order_id = :order[ejb/orders]<br />
<br />
To produce this where clause, the Container substitutes the primary key of the Order<br />
object for the string :order[ejb/orders]. The string between the brackets (in this<br />
example, ejb/orders) must be the corresponding to the home of the<br />
parameter type. In this example, ejb/orders corresponds to an pointing to<br />
OrderHome.<br />
When you use an EJBObject as a compound type (using the dot notation), you are<br />
actually accessing the underlying get method for the field in the definition. For<br />
example, the following in the definition:<br />
order_id = :order.orderId<br />
calls the getOrderId() method on the order EJBObject and uses the result of the call in<br />
the selection criterion.<br />
Specifying relationships between entities<br />
Relational databases (RDBMS) permit records in one table to be associated with<br />
records in another table. The RDBMS accomplishes this using foreign keys; that is, a<br />
record in one table maintains a field (or column) that is a foreign key or reference to<br />
(usually) the primary key of a related record in another table. You can map these same<br />
references among entity beans.<br />
For the CMP engine to map references among entity beans, you use an <br />
entry in the deployment descriptor. The maps field names to their<br />
corresponding entities. The CMP engine uses this information in the deployment<br />
descriptor to locate the field's associated entity. (Refer to the pigs example for an<br />
illustration of the entry.)<br />
Any container-managed persistence field can correspond to a foreign key field in the<br />
corresponding table. When you look at the entity bean code, these foreign key CMP<br />
fields appear as object references.<br />
For example, suppose you have two database tables, an address table and a country<br />
table. The address table contains a reference to the country table. The SQL create<br />
statements for these tables might look as shown below.<br />
create table address (<br />
addr_id number(10),<br />
addr_street1 varchar2(40),<br />
addr_street2 varchar(40),<br />
addr_city varchar(30),<br />
addr_state varchar(20),<br />
addr_zip varchar(10),<br />
addr_co_id number(4) * foreign key *<br />
);<br />
create table country (<br />
co_id<br />
number(4),<br />
co_name varchar2(50),<br />
co_exchange number(8, 2),<br />
co_currency varchar2(10)<br />
);<br />
Note that the address table contains the field addr_co_id, which is a foreign key<br />
referencing the country table's primary key field, co_id.<br />
118 BES Developer’s Guide