13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

496Chapter 22Building an EJBwhich, for our example, we can implement as empty methods. A stateless sessi<strong>on</strong>bean never needs an activati<strong>on</strong> or passivati<strong>on</strong> method to do anything—itis pointless to passivate a stateless sessi<strong>on</strong> bean. Why? Since it’s stateless, anyinstance of it is as good as any other, so the instances are interchangeable andthere’s no need to passivate <strong>on</strong>e to get to another—just use the <strong>on</strong>e available.It follows that if a bean is never passivated, it will never have to be activated.But why no body to the ejbCreate() method? Well, our bean isn’t doinganything extra. This would <strong>on</strong>ly be used if our example were more complicatedand we needed to do applicati<strong>on</strong>-specific initializati<strong>on</strong>s. For example, if thebean had to c<strong>on</strong>nect to a database (and did not use entity beans), it might establishthe JDBC c<strong>on</strong>necti<strong>on</strong> in ejbCreate and close it in ejbRemove().Similarly, we can have an empty ejbRemove() method.Next we add our own methods, the <strong>on</strong>es that provide the applicati<strong>on</strong>functi<strong>on</strong>ality. For our M<strong>on</strong>eyBean applicati<strong>on</strong>, we’ll add save() and debt()methods which will use an SAM<strong>on</strong>ey class by calling its save() and debt()methods. Example 22.1 is the listing of the Sessi<strong>on</strong>Bean.Example 22.1 Listing of our implementati<strong>on</strong> of a Sessi<strong>on</strong>Beanpackage com.jadol.budgetpro;import net.multitool.util.*;import javax.ejb.*;/*** Actual implementati<strong>on</strong> of the EJB*/public classM<strong>on</strong>eyEJBeanimplements Sessi<strong>on</strong>Bean{protected Sessi<strong>on</strong>C<strong>on</strong>text sessi<strong>on</strong>C<strong>on</strong>text;// typical; just not used nowpublic Costsave(double amt, double rate, double paymnt)throws java.rmi.RemoteExcepti<strong>on</strong>{return SAM<strong>on</strong>ey.save(amt, rate, paymnt);} // save

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!