Enterprise applications revolve mostly around three aspects of data: transfer of data, retrieval of data and transformation of data by applying the business rules of a particular organization. Since these three aspects are specific to an organization, Enterprise Java Beans (EJB) are known as Business Specific Components. Even among the three aspects, the former two are more generic in nature whereas the latter is closer to the policies of a given organization.
Session Beans in EJB 3.0 - Session Beans in the Real World (Page 4 of 4 )
In the last part I had developed a Stateless Session Bean. Now let's see the Stateful version of it. The application consists of three main components:
Calculator- The Business Interface of the Stateful Bean
StatefulCalculator - The Bean implementation of the Business Interface.
Client - the JSP file that calls the Bean's instance method.
Here is the first component. It is the Business Interface:
packageexamples.session.stateful; import java.util.ArrayList; public interface Calculator {
public double calculate (int start, int end, double growthrate, double saving);
public ArrayList <Integer> getStarts (); public ArrayList <Integer> getEnds (); public ArrayList <Double> getGrowthrates (); public ArrayList <Double> getSavings (); public ArrayList <Double> getResults ();
}
It uses the ArrayList object as a part of the Conversational State. Next is the Bean implementation:
@Stateful public class StatefulCalculator implements Calculator, Serializable {
public ArrayList <Integer> starts = new ArrayList <Integer> (); public ArrayList <Integer> ends = new ArrayList <Integer> (); public ArrayList <Double> growthrates = new ArrayList <Double> (); public ArrayList <Double> savings = new ArrayList <Double> (); public ArrayList <Double> results = new ArrayList <Double> ();
The JSP file takes the input and calculates the result. Apart from that, it shows all the previous results calculated. Thus it takes the advantage of statefulness of the Bean. That brings us to the end of this discussion. The next time I take up this topic I will discuss the basics of the Entity Bean and the process of deploying Beans in JBoss. Till then...
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.