Using EJB activation and passivation  Chapter 29: Configuring Persistence Mechanisms

Chapter 28: Configuring Persistence for Stateful Session Components

Using automatic persistence

To use automatic persistence, you must define a state datatype to hold your component’s instance state, implement accessor methods, and choose a storage component.

StepsConfiguring a stateful component to use automatic persistence

  1. Display the component’s properties, then click the Persistence tab. Configure the Persistence/General tab settings as follows:




    Choose Automatic Persistent State.


    Enter the name of an IDL structure that contains your component’s state data, for example:


    “Defining the IDL state type” describes how to create this structure.

    State methods

    Enter the names of the component methods that retrieve and apply an instance’s state data. If you specify no value, the default is getState,setState. Your component implementation must contain these methods, but they should not be listed in the component’s client interfaces. “Accessing the state data in the implementation” describes how to implement these methods.

    Storage component

    Specify the name of the storage component, as described in “Storage components”.

    Connection cache

    If using database storage, enter the name of a JDBC connection cache that connects to the database. The cache must have by-name access enabled.


    If using database storage, enter the name of a database table where the serialized data is to be stored. If you use Sybase Adaptive Server Enterprise or Adaptive Server Anywhere, EAServer creates the table if it does not exist. When using another data server, you or your database administrator (DBA) must create the table manually. The table must have the schema described in “Table schema for binary storage”.

  2. Define the IDL state type as described below.

  3. Add code to retrieve, apply, and modify the state data as described below.

  4. Regenerate stubs and skeletons for the component—this step will generate the Java classes for the IDL state types.

  5. If using in-memory storage, configure the component’s Mirror Cache properties and cluster to support in-memory failover, as described in “Requirements for in-memory stateful failover”.

Defining the IDL state type

The IDL state type is a structure that must hold all the session data for the bean. The following IDL module shows example types used for a shopping cart component:

module TheCart
  // This is the state type, an IDL structure that holds customer data 
  // and the collection (sequence) of items in the cart.
  struct CartState
    string name;
    string address;
    string phone;
    ::TheCart::ShoppingCartItems items;

  // "ShoppingCartItems" is the sequence to hold items in the cart:
  typedef sequence < ::TestInMemoryFailvoer::ShoppingCartItem > ShoppingCartItems;

  // "ShoppingCartItem" holds the data for one item in the cart:
  struct ShoppingCartItem
    string item;
    long quantity;

In the State field on the Persistence/General tab, you can enter the name of an IDL structure that does not exist. EAServer Manager creates the structure when you close the Component Properties dialog box. Afterwards, navigate to the module definition under the top-level IDL folder and edit the structure definition. For information on editing IDL in EAServer Manager, see Chapter 5, “Defining Component Interfaces.”

Accessing the state data in the implementation

Make the following changes to the component implementation:

Copyright © 2005. Sybase Inc. All rights reserved. Chapter 29: Configuring Persistence Mechanisms