web server - Borland Technical Publications
web server - Borland Technical Publications web server - Borland Technical Publications
Container-Managed Persistence in Borland Enterprise Server Container-Managed Persistence in Borland Enterprise Server The Borland Enterprise Server's EJB Container is fully J2EE 1.3 compliant. The bean provider designs persistence schemas for their entity beans, determined the methods for accessing container-managed fields and relationships, and defines these in the beans' deployment descriptor. The deployer maps this persistence schema to the database and creates any other necessary classes for the beans' maintenance. Information on J2EE 1.3 entity beans and CMP 2.0 is found in Chapter 16, “Using BES Properties for CMP 2.x.” BES CMP engine's CMP 1.1 implementation While you don't have to be an expert on all aspects of the Borland CMP engine to use it effectively, it is helpful to have some knowledge of certain areas. This section provides information on the areas that users of the CMP engine should understand. In particular, it focuses on the deployment descriptor file and the XML statements contained within the file. Before continuing, there are some key things to note in the implementation of an entity bean that uses 1.1 container-managed persistence: ■ ■ ■ ■ ■ The entity bean has no implementations for finder methods. The EJB Container provides the finder method implementations for entity beans with containermanaged persistence. Rather than providing the implementation for finder methods in the bean's class, the deployment descriptor contains information that enables the container to implement these finder methods. The entity bean declares all fields public that are managed by the container for the bean. The CheckingAccount bean declares name and balance to be public fields. The entity bean class implements the seven methods declared in the EntityBean interface: ejbActivate(), ebjPassivate(), ejbLoad(), ejbStore(), ejbRemove(), setEntityContext(), and unsetEntityContext(). However, the entity bean is required to provide only skeletal implementations of these methods, though it is free to add application-specific code where appropriate. The CheckingAccount bean saves the context returned by setEntityContext() and releases the reference in unsetEntityContext(). Otherwise, it adds no additional code to the EntityBean interface methods. There is an implementation of the ejbCreate() method (because this entity bean allows callers of the bean to create new checking accounts), and the implementation initializes the instance's two variables, account name and balance amount, to the argument values. The ejbCreate() method returns a null value because, with container-managed persistence, the container creates the appropriate reference to return to the client. The entity bean provides the minimal implementation for the ejbPostCreate() method, though this method could have performed further initialization work if needed. For beans with container-managed persistence, it is sufficient to provide just the minimal implementation for this method because ejbPostCreate() serves as a notification callback. Note that the same rule applies to the methods inherited from the EntityBean interface as well. Providing CMP metadata to the Container According to the EJB Specification, the deployer must provide CMP metadata to the EJB container. The Borland Container captures the CMP-relevant metadata in the XML deployment descriptor. Specifically, the Borland Container uses the vendor-specific portion of the deployment descriptor for the CMP metadata. Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 115
Container-Managed Persistence in Borland Enterprise Server This section illustrates some of the information that needs to be provided for containermanaged finder methods, particularly if you are constructing container-managed finder methods at the command line level. Because it is not an exhaustive reference, you should refer to the DTD of the deployment descriptor for the detailed syntax. Look for the syntax for the finder methods and Object-Relation (OR) mapping metadata. Constructing finder methods When you construct a finder method, you are actually constructing an SQL select statement with a where clause. The select statement includes a clause that states what records or data are to be found and returned. For example, you might want to find and return checking accounts in a bank. The where clause of the select statement sets limits on the selection process; that is, you might want to find only those checking accounts with a balance greater than some specified amount, or accounts with a certain level of activity per month. When the Container uses container-managed persistence, you must specify the terms of the where clause in the deployment descriptor. For example, suppose you have a finder method called findAccountsLargerThan(int balance) and you are using container-managed persistence. This finder method attempts to find all bank accounts with a balance greater than the specified value. When the Container executes this finder method, it actually executes a select statement whose where clause tests the account balances against the int value passed as a parameter to the method. Because we're using container-managed persistence, the deployment descriptor needs to specify the conditions of the where clause; otherwise, the Container does not know how to construct the complete select statement. The value of the where clause for the findAccountsLargerThan(int balance)method is “balance > :balance“. In English, this translates to: “the value of the balance column is greater than the value of the parameter named balance.” (Note that there is only one argument to the finder method, an int value.) The default container-managed persistence implementation supports this finder method by constructing the complete SQL select statement, as follows: select * from Accounts where ? > balance The CMP engine then substitutes “?” with the int parameter. Lastly, the engine converts the result set into either an Enumeration or Collection of primary keys, as required by the EJB Specification. It is possible to inspect the various SQL statements that the CMP implementation constructs. To do this, enable the EJBDebug flag on the container. When that flag is enabled, it prints the exact statements constructed by the Container. While other EJB Container products use code generation to support CMP, the Borland Container does not use code generation because it has serious limitations. For example, code generation makes it difficult to support a “tuned update” feature, because of the great number of different update statements to container-managed fields that are required. Constructing the where clause The where clause is a necessary part of select statements when you want to delimit the extent of the returned records. Because the where clause syntax can be fairly complex, you must follow certain rules in the XML deployment descriptor file so that the EJB Container can correctly construct this clause. To begin with, you are not obligated to use the literal “where” in your . You can construct a where clause without this literal and rely on the Container to supply it. However, the Container only does this if the is not an empty string; it leaves empty strings empty. For example, you could define a where clause as either: 116 BES Developer’s Guide
- Page 75 and 76: Setting up your web container with
- 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: Implementing an entity bean Generat
- Page 129 and 130: 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
Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />
Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />
The <strong>Borland</strong> Enterprise Server's EJB Container is fully J2EE 1.3 compliant. The bean<br />
provider designs persistence schemas for their entity beans, determined the methods<br />
for accessing container-managed fields and relationships, and defines these in the<br />
beans' deployment descriptor. The deployer maps this persistence schema to the<br />
database and creates any other necessary classes for the beans' maintenance.<br />
Information on J2EE 1.3 entity beans and CMP 2.0 is found in Chapter 16, “Using BES<br />
Properties for CMP 2.x.”<br />
BES CMP engine's CMP 1.1 implementation<br />
While you don't have to be an expert on all aspects of the <strong>Borland</strong> CMP engine to use<br />
it effectively, it is helpful to have some knowledge of certain areas. This section<br />
provides information on the areas that users of the CMP engine should understand. In<br />
particular, it focuses on the deployment descriptor file and the XML statements<br />
contained within the file.<br />
Before continuing, there are some key things to note in the implementation of an entity<br />
bean that uses 1.1 container-managed persistence:<br />
■<br />
■<br />
■<br />
■<br />
■<br />
The entity bean has no implementations for finder methods. The EJB Container<br />
provides the finder method implementations for entity beans with containermanaged<br />
persistence. Rather than providing the implementation for finder methods<br />
in the bean's class, the deployment descriptor contains information that enables the<br />
container to implement these finder methods.<br />
The entity bean declares all fields public that are managed by the container for the<br />
bean. The CheckingAccount bean declares name and balance to be public fields.<br />
The entity bean class implements the seven methods declared in the EntityBean<br />
interface: ejbActivate(), ebjPassivate(), ejbLoad(), ejbStore(), ejbRemove(),<br />
setEntityContext(), and unsetEntityContext(). However, the entity bean is required<br />
to provide only skeletal implementations of these methods, though it is free to add<br />
application-specific code where appropriate. The CheckingAccount bean saves the<br />
context returned by setEntityContext() and releases the reference in<br />
unsetEntityContext(). Otherwise, it adds no additional code to the EntityBean<br />
interface methods.<br />
There is an implementation of the ejbCreate() method (because this entity bean<br />
allows callers of the bean to create new checking accounts), and the implementation<br />
initializes the instance's two variables, account name and balance amount, to the<br />
argument values. The ejbCreate() method returns a null value because, with<br />
container-managed persistence, the container creates the appropriate reference to<br />
return to the client.<br />
The entity bean provides the minimal implementation for the ejbPostCreate()<br />
method, though this method could have performed further initialization work if<br />
needed. For beans with container-managed persistence, it is sufficient to provide<br />
just the minimal implementation for this method because ejbPostCreate() serves as<br />
a notification callback. Note that the same rule applies to the methods inherited from<br />
the EntityBean interface as well.<br />
Providing CMP metadata to the Container<br />
According to the EJB Specification, the deployer must provide CMP metadata to the<br />
EJB container. The <strong>Borland</strong> Container captures the CMP-relevant metadata in the XML<br />
deployment descriptor. Specifically, the <strong>Borland</strong> Container uses the vendor-specific<br />
portion of the deployment descriptor for the CMP metadata.<br />
Chapter 14: Entity Beans and CMP 1.1 in <strong>Borland</strong> Enterprise Server 115