System News
Enterprise JavaBeans Tutorial
Creating and Testing Session Beans
March 11, 2002,
Volume 49, Issue 2

ForteTM for JavaTM Enterprise Edition includes tools and modules to make the creation and testing of Enterprise JavaBeansTM (EJBTM) components easier and more flexible. Part one of a tutorial on the JavaTM technology Web site introduces the process of creating and testing session beans, both stateless and stateful, with Forte for Java Release 3.0, Enterprise Edition. Developers are provided an opportunity to quickly grasp some of the key concepts and capabilities of this process.

EJB Component Support

The Forte for Java IDE invisibly manages (automates) many tasks that would otherwise have to be programmed by hand. For example, here are a few EJB component-related tasks which the IDE automates:

  • Write method declarations for the basic classes: The IDE generates the necessary classes for each bean and the method declarations within those classes.

  • Provide code to manage transactions and persistence: The application server takes care of those tasks for you.

  • Keep your bean classes, interfaces and methods synchronized: The IDE maintains consistency for you.

  • Write XML code for the deployment descriptor: The IDE generates this file.

  • Manually create a test client to test the enterprise bean: The IDE provides comprehensive, GUI-based support for testing your beans.

  • Search the JavaTM 2 Platform, Enterprise Edition (J2EETM) documentation: The enterprise bean source code generated by the IDE conforms to J2EE platform standards and includes comments.

The EJB Builder wizard is used to generate a basic enterprise bean. The wizard automatically tailors the enterprise bean according to your specifications, whether a session or entity bean, and with options for transaction and persistence management. The wizard guides you through the steps required to create the basic components.

Next, you would typically add methods to the bean, using further features of the EJB Builder, and then the Source Editor to finish coding the bean.

Transaction Support

In the enterprise bean model, transactional behavior is designed to be handled both implicitly and declaratively. When a method is invoked on a bean instance, the EJB container intervenes and manages the transaction automatically. Consequently, as a developer, you don't have to be expert in writing transactions, and you don't have to write or debug the code which controls transaction boundaries.

Sometimes, however, you might need to program transactions explicitly in a session bean. In this case, the IDE enables you to declaratively override the container, and supports the use of the JavaTM DataBase Connectivity (JDBCTM) API, the Java technology transaction API, or the IDE's Transparent Persistence module to manage your beans' transactional behavior.

Persistence Support

As with transaction support, the IDE enables you to either delegate a beans' persistence handling entirely to the EJB container, or to code persistence yourself.

Security Support

If you wish, for example, to restrict access to certain methods in your enterprise bean to users in certain roles, you can add programmatic security to the bean. However, it is not necessary to write full security routines in the bean's source code. Instead, a security reference in your bean code can be matched to a security role which you declare for a method.

For details on the design of enterprise beans and the EJB architecture tier, refer to the Enterprise JavaBeans Specification at the following URL:

http://java.sun.com/products/ejb/docs.html

Other sections of the tutorial include creating a stateless session bean and creating a stateful session bean. For additional technical details:

http://forte.sun.com/ffj/articles/sessionbeans.html

Read More ... [...read more...]

Keywords:

fullsource
 




Other articles in the Developer section of Volume 49, Issue 2:

See all archived articles in the Developer section.





Popular Articles in Vol 184, Issue 2


News and Solutions for Users of Solaris, Java and Oracle's Sun hardware products
Just the news you need, none of what you don't – 42,000+ Members – 24,000+ Articles Published since 1998