ejb

What is an Application Server?

Historically, when an enterprise Java developer talked about deploying an application server, the idea being that they are taking enterprise application archive (EAR-file) and serving it to install WebSphere or JBoss, or make some other manufacturers in the Java EE framework. Application server, where it was received compile JavaServer Pages Servlet loaded, Enterprise JavaBeans managed, and(…)

Home Interface

The home interface defines the methods that allow a client to create and find an entity bean. The SavingsAccountHome interface follows: import java.util.Collection; import java.math.BigDecimal; import java.rmi.RemoteException; import javax.ejb.*; public interface SavingsAccountHome extends EJBHome { public SavingsAccount create(String id, String firstName, String lastName, BigDecimal balance) throws RemoteException, CreateException; public SavingsAccount findByPrimaryKey(String id) throws FinderException, RemoteException; public Collection(…)

Business Methods

The business methods contain the business logic that you want to encapsulate within the entity beans. Usually, the business methods do not access the database, allowing you to separate the business logic from the database access code. The SavingsAccountBean class contains the following business methods: public void debit(BigDecimal amount) throws InsufficientBalanceException { if (balance.compareTo(amount) == -1) {(…)

Finder Methods

The finder methods allow clients to locate entity beans. The SavingsAccountClient program locates entity beans with three finder methods: SavingsAccount jones = home.findByPrimaryKey(“836”); … Collection c = home.findByLastName(“Smith”); … Collection c = home.findInRange(20.00, 99.00); For every finder method available to a client, the entity bean class must implement a corresponding method that begins with the prefix ejbFind. The SavingsAccountBean class,(…)

EntityBean Interface

The Entity Beans interface extends the EnterpriseBean interface, which extends the Serializable interface. The EntityBean interface declares a number of methods, such asejbActivate and ejbLoad, which you must implement in your entity bean class. These methods are discussed in later sections. The ejbCreate Method When the client invokes a create method, the EJB container invokes the corresponding ejbCreate method. Typically, an ejbCreate method in an entity bean performs the following tasks: Inserts(…)

Entity Beans

The sample entity bean class is called SavingsAccountBean. As you look through its code, note that it meets the requirements of any entity bean with bean-managed persistence. First of all, it implements the following: EntityBean interface Zero or more ejbCreate and ejbPostCreate methods Finder methods Business methods Home methods In addition, an entity bean class with bean-managed persistence has these requirements:(…)

The SavingsAccountEJB Example

The entity bean illustrated in this section represents a simple bank account. The state of SavingsAccountEJB is stored in the savingsaccount table of a relational database. Thesavingsaccount table is created by the following SQL statement: CREATE TABLE savingsaccount (id VARCHAR(3) CONSTRAINT pk_savingsaccount PRIMARY KEY, firstname VARCHAR(24), lastname VARCHAR(24), balance NUMERIC(10,2)); The SavingsAccountEJB example requires the following code: Entity bean class (SavingsAccountBean) Home(…)