Chapter 29 Managing Persistent Component State


Persistence for entity components

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:

Using component-managed persistence

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.

Using automatic persistence

When using automatic persistence, Jaguar manages all interaction with the remote database. There are two options for database storage when using automatic persistence:

Note   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 .

Steps To configure automatic persistence:

  1. Configure Persistence tab properties.

  2. Specify field to column mapping properties.

  3. Specify finder-method queries.


Configure Persistence tab properties

Display the Component Properties window in Jaguar Manager and configure the following fields on the Persistence tab:

Specify field to column mapping properties

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:

Table 29-1:

Property name

Value

mapField:[key]

(For single-column keys only.)

The database column name.

com.sybase.jaguar.
component.key.field

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:

Table 29-2: Mapping database columns to class fields

For columns of this type

Property name

Value

Key fields (enter one property for each key field)

mapField:field[key]

Where field is the name of the field in the implementation class that this key column maps to.

The database column name.

Non-key fields
(enter one property for each field)

mapField:field

Where field is the name of the field that this key column maps to.

The database column name.

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.

Specify finder-method queries

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:

Placeholder

To indicate

[key]

The table's primary key (which can consist of multiple columns).

[table]

The name of the table.

@param

Reference the value of parameter param in the finder method's IDL signature.

Note   If the component was imported from an EJB JAR file, the parameter names will not match those in the original Java implementation. Instead, they are p0, p1, and so forth.

@param.fieldName

If method parameter param is not a simple type, reference the value of field fieldName.

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.