example.cmp.single_table
Class HouseBean

example.cmp.single_table.HouseBean

public abstract class HouseBean

Implementation of the HouseBean. Each instance of HouseBean maps to a table entry of "house", where house is defined as

 CREATE TABLE house (
   name VARCHAR(250),
   points INTEGER
 )
 

The bean implementation is abstract and the get and set methods for the managed fields are abstract to take advantage of Resin-CMP's container-managed persistence. All business methods must be fully implemented. Resin-CMP will create the implementation of the abstract methods.

Resin-CMP will cache the bean instance. Once the instance is loaded, it can avoid calling the database for any further calls.

HouseBean extends the AbstractEntityBean implementation. AbstractEntityBean is a stub EntityBean implementation with default methods to make life a little more sane for simple beans.


Constructor Summary
HouseBean()
           
 
Method Summary
 void addPoints(int delta)
          Business method to add a number of points to the house.
abstract  java.lang.String getName()
          Returns the house name.
abstract  int getPoints()
          Returns the number of points for the house.
abstract  void setName(java.lang.String name)
          Sets the house name.
abstract  void setPoints(int points)
          Sets the number of points for the house.
 

Constructor Detail

HouseBean

public HouseBean()
Method Detail

getName

public abstract java.lang.String getName()
Returns the house name. The name is the primary key.

setName

public abstract void setName(java.lang.String name)
Sets the house name.

In this example, the setName method is optional since it doesn't have a create method. setName would be used in a create method to set the primary key for the new item. Beans must never call setName in any other situation than the create method.

The set methods for the primary key are never exposed in the local interface.

Parameters:
name - the name for a new house instance.

getPoints

public abstract int getPoints()
Returns the number of points for the house. Resin-CMP will fill in the implementation.

With Resin-CMP's caching, this will normally not require a new database call after the first request.


setPoints

public abstract void setPoints(int points)
Sets the number of points for the house. This method is hidden from clients since it's not exposed in the House interface. It is only called by the business method addPoints. Clients must call addPoints to change the house's points.
Parameters:
points - the new number of points for the house.

addPoints

public void addPoints(int delta)
Business method to add a number of points to the house. Changes to database fields will often be encapsulated in a business method.

Because the getPoints and setPoints calls are contained in the same business method call, it's in the same transaction. That means the update will be consistent even with multiple threads.

The automatic transaction is like a synchronize call, but is more efficient and potentially capable of handling distributed updates.

Parameters:
delta - the points to add or subtract.