Chapter 29 Managing Persistent Component State
An entity component is an EJB entity Bean or a component of another type that implements the CtsComponents::ObjectControl interface. Entity components present an object view of relational data to clients; each instance of an entity component maps to a row in a database relation.
Entity components can be EJB entity Beans implemented according to the EJB 1.0 or 1.1 standard (see Chapter 8, "Creating Enterprise JavaBean Components"). You can also implement CORBA entity components by following these requirements:
For an entity component, you can manage persistence using these techniques:
To use component-managed persistence, you must configure the component's persistence properties and implement the required methods from the EntityBean or CtsComponents::ObjectControl interfaces. Display the Component Properties window in Jaguar Manager and configure the following fields on the Persistence tab:
In most cases, no other persistence settings are required. You can delegate to Jaguar's built-in storage components rather than implementing your own database access code. If you do so, configure the Storage Component, Connection Cache, and Table fields (see "Storage components"). Delegation requires that you use the CtsComponents::DataStream and CtsComponents::Storage interfaces. See the generated Interface Repository documentation on your Jaguar server (in the html/ir subdirectory) for descriptions of these interfaces.
When using automatic persistence, Jaguar manages all interaction with the remote database. There are two options for database storage when using automatic persistence:
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
.
To configure automatic persistence:
Display the Component Properties window in Jaguar Manager and configure the following fields on the Persistence tab:
getState,setState
.
Your component implementation must contain these methods, but they should
not be listed in the component's client interfaces. The getState method
returns an instance of the type specified by the State field, and the setState method
accepts a parameter of this type. For example, if the State type
is ShoppingCartState, the getState and setState methods might
be defined as follows in Java:private ShoppingCartState data;
ShoppingCartState getState()
{
return data;
}
void setState(ShoppingCartState state)
{
data = state;
}
map:table
com.sybase.jaguar.component.ts.length
property
to binary(16)
. If the table's primary key maps to a single field in the implementation class (which must be the same type as the component's primary key), display the All Properties tab and configure the properties in the following table:
Property name |
Value |
---|---|
mapField:[key] (For single-column keys only.) |
The database column name. |
|
The name of the component field that the key maps to. |
To map database fields to columns, display the All Properties tab and define properties to map database columns to fields in the implementation class, using the name/value patterns listed in the table below:
You can optionally append a SQL type name to column names, in square brackets. For example, to specify the column type must be varbinary(1024), enter:
icon[varbinary(1024)]
The type name is used during automatic table creation. This feature is useful when a Java type can map to multiple SQL types; in that case, Jaguar defaults to the type with minimal storage requirements when creating the table. Varchar columns default to 100 bytes length, and varbinary columns default to 255 bytes. Specify a type name to override the default.
Each finder method in the component's home interface requires a database query to select a set of primary keys. For example, the findByPrimaryKey method selects the key that matches the input parameter. A findAll method might return all keys in the table.
Jaguar can correctly infer the query required to execute the findByPrimaryKey method.
For other finder methods, you must enter properties to specify the
query. Display the All Properties tab and define new properties
for each finder method. Name each property mapQuery:method
,
where method is the finder method name. For
the value, enter a query to select primary key values with a filter
appropriate for the semantics of the finder method. You can use
the following placeholders to represent column and table names and
parameter values:
The following are examples of queries using placeholders. This query returns all rows in a table:
select [key] from [table]
This query uses the value of the expiryDate parameter to filter a range of closingDate column values:
select [key] from [table] where closingDate < @expiryDate
Copyright © 2000 Sybase, Inc. All rights reserved. |