|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON WebLogic Server EJB
EJB
By: Dave Cooke
Jun. 20, 2002 12:00 AM
This month, we'll study for the EJB portion of the BEA WebLogic Server 6.0 Certification Test. Now, I know I was also supposed to talk about JDBC this month, but I just didn't have enough room to squeeze it in. EJB is by far the most widely covered topic on the test, and I didn't want to take any attention away from it. I'll be sure to cover JDBC next month. Let me say it again: EJB is the biggest topic of the test. With that said, it should be the topic that you know best. I'll try to summarize the portions of EJB that you should be familiar with. We'll start with the general interfaces you need to build EJBs. For the purposes of the test, there are four primary interfaces to know when building Enterprise JavaBeans. These interfaces are the Remote interface, the Home interface, the MessageListener interface, and the implementation class interface. To implement the Remote interface, you need to implement the EJBObject interface. The aptly named EJBHome interface must be implemented to create the Home interface. The MessageListener interface is used only for message-driven beans. It informs the bean that a message has been received from a JMS Queue or Topic. Since each type of EJB performs a different job, there are different types of interfaces for the implementation class interface. More details about how all of these interfaces work for each type of EJB are discussed below.
Entity Beans
Create the Home interface by extending EJBHome. Please note: you must provide a findByPrimaryKey() method and may provide zero or more createXXX() or findXXX() methods (where XXX is anything). In order to create the implementation class, you must implement the EntityBean interface. You must make sure the class is public - not marked as static, final, or abstract - and does not contain a finalizer method. The class must provide an implementation of every method listed in the Remote interface and an ejbFindByPrimaryKey() method that corresponds to the findByPrimaryKey() method in the Home interface. In addition, it must provide an implementation of every creation and finder method listed in the Home interface. Be sure to review Table 1, which lists some entity bean methods of note.
Stateless Session Beans
Create the Home interface by extending EJBHome. Please note: you must provide a create() method. This method must not contain any input parameters and cannot be overloaded. To create the implementation class, you must implement the SessionBean interface and make sure your class is public - not marked as static, final, or abstract - and doesn't contain a finalizer method. The class must provide an implementation of every method listed in the Remote interface and an ejbCreate() method that corresponds to the create() method in the Home interface. Table 2 lists some stateless session bean methods of note.
Stateful Session Beans
In order to create the implementation class, you must implement the SessionBean interface. Again, make sure the class is public, not marked as static, final or abstract. It should not contain a finalizer method and should provide an implementation of every business method listed in the Remote interface. The class should also contain an ejbCreateXXX() method that corresponds to each createXXX() method in the Home interface. Table 3 lists some stateful session bean methods you should know for the test.
Message-Driven Beans
Also, unlike the other EJBs, a message-driven bean doesn't have a Remote or Home interface, because it's never invoked directly by the client. Given this, the methods of a message-driven bean do not have return values or propagate exceptions back to the client. The MessageListener interface provides the ability for the bean to realize that it has consumed a message. The onMessage() method takes an input of type Message, which can be a BytesMessage, ObjectMessage, TextMessage, StreamMessage, or MapMessage. To create the implementation class, you must implement the MessageDrivenBean interface. As with all the other implementation classes, make sure the class is public - not marked as static, final, or abstract - and doesn't contain a finalizer method. Table 4 lists message-driven bean methods of importance.
EJB Exceptions
EJB Utility Classes
The SessionContext interface allows the session bean to access properties of the EJB container. Understanding that SessionContext is passed into a Session Bean at creation time and is maintained until the bean is destroyed is important. Similarly, the EntityContext interface allows the entity bean to access properties of the EJB container. The EntityContext is passed into an entity bean at creation time and is maintained until the bean is destroyed. The last utility class to know for the test is the SessionSynchronization interface. This interface notifies a session bean of important transaction-related events. Table 6 summarizes the events.
Deployment
The ejb-jar.xml and weblogic-ejb-jar.xml files must reside in the \META-INF subdirectory of the jar file. The class (or java) files should reside in the package-relative location. Table 7 shows the structure of an EJB application. The ejb-jar.xml file contains a large number of deployment descriptors, which are important to know for the test. Some of these are listed in Table 8; a sample ejb-jar.xml file is shown in Listing 1. The weblogic-ejb-jar.xml file contains more information about the EJBs being deployed. The information in this file is specific to WebLogic Server. Some important descriptors are listed in Table 9 and a sample file is shown in Listing 2. Next month, I'll look at JDBC in addition to the transactions and clustering topics of the test. Before you take the sample test, though, I'd like to mention another resource to help you study for the test! Be sure to check out the BEA WebLogic Server 6.1 Bible; it can be used as a valuable study aid for the test. Good luck on the test!
Sample Test
2. An EJB created using EJB version 2.0 must throw what type
of exception?
3. Which interface are you most likely to use to retrieve properties of a session bean's EJB container?
4. What statement illustrates a difference between creating an entity bean and a session bean?
5. Which subdirectory does the ejb-jar.xml file reside in?
6. What is a good reason to use a message-driven bean instead of
a session bean?
7. What interface do you extend to create the EJB's remote
interface?
8. What interface do you extend to create a stateful session bean's implementation class?
9. What interface do you extend to create a stateless session bean's implementation class?
10. What interfaces do you need to implement to build a message- driven bean?
Answer Key
BEA WEBLOGIC LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS BREAKING NEWS FROM THE WIRES
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||