When using automatic or EJB CMP persistence, EAServer manages all interaction with the remote database. There are two options for database storage when using automatic persistence:
Using mapped fields In the mapped field model, you define a mapping from a database table to fields in your component implementation class. When a write to the database is required, the server reads the field values; after reading new data from the database, the server assigns new field values for each mapped database column. This model corresponds to the container-managed Persistence (CMP) model required by the EJB 2.0 and 1.1 specifications, but has been extended to support other component types.
Using binary storage In this model, you define state-accessor methods and an IDL state type. The server calls your state-accessor methods before writing data to the database and after reading from the database. The state data is stored in an encoded binary form. Because the relational data is encoded, this model does not support finder methods other than findByPrimaryKey.
Identifying the storage technique
The component uses mapped field storage if the value of the
Table field on the Persistence tab begins with
map:
,
for example, map:MyTable
.
The automatic persistence architecture includes:
As for any component, the component’s implementation class and skeleton. The skeleton acts as the interface between EAServer and the implementation class.
For EJB 2.0 entity beans, your implementation class must be an abstract Java class, with abstract accessor methods for the bean’s container-managed fields and abstract declarations of the bean’s ejbSelect methods. For example, if firstName is a container-managed field of type String, you must declare these abstract accessor methods:
public abstract String getFirstName(); public abstract void setFirstName(String value);
EAServer generates the implementation class that executes at runtime. This class extends your abstract EntityBean class and implements the accessor methods for container-managed fields.
A storage component, which stores instance field data to a remote database. The storage component manages all data storage and retrieval, including concurrency control to prevent overlapping updates of the same rows.
The component’s state datatype, which is an IDL structure that contains the data that is to be stored in the database. The state datatype is required to exchange data between the component’s skeleton and the storage component.
The component’s state accessor methods, which the component or skeleton implements to interact with the storage component. When the client calls a business method, the instance fields must be loaded with up-to-date data, so the storage component calls the set method to provide the data. When the business method completes, the storage component calls the get method to obtain and save the changed data.
For EJB entity beans, EAServer generates a skeleton with state accessor methods. For entity components of other types, you must implement accessor methods and specify their names in component properties as described below.
The object cache, which allows in-memory caching of entity instance data to avoid unnecessary database reads to load instance state.
The query cache, which allows in-memory caching of finder and ejbSelect query results to avoid unnecessary database reads to execute finder and ejbSelect methods.
The component’s abstract persistence schema, which defines the names and types of container-managed fields, and (for EJB 2.0 entity beans) container-managed relationships between entity beans. In EAServer, the abstract persistence schema is configured by the component properties, specifically:
The primary key and state datatypes.
Field-mapping properties, to bind component fields to database columns.
Query-mapping properties, to specify the queries required to run finder methods and ejbSelect methods. For EJB 2.0 entity beans, EAServer supports query mappings defined in standard EJB Query Language (EJB-QL).
Table-mapping properties, to further fine tune the database access. For example, table-mapping properties can be defined to allow the use of stored procedures for all database access.
Relationship components, which manage EJB 2.0 entity bean relationships to allow one bean to contain instances of another in a container-managed field. Relationship components are themselves EJB 2.0 entity beans generated entirely by EAServer.
When you import an EJB CMP entity bean from an EJB-JAR file, the importer configures almost all EAServer Manager properties based on the abstract persistence schema defined in the deployment descriptor.
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |