You create and develop EJBs in the context of a Together project. There are two ways you can create EJBs in a project:
Create a Together project for existing EJB source code.
Create a basic model and code skeleton for a new EJB using the "one-click" EJB feature in Class diagrams. You then specify EJB properties and add EJB fields, methods, etc. in the EJB Inspector.
This section explains how to use each of these techniques. See also Overview of EJB Features.
If you have existing EJB source code, you can create one or more Together projects around it. Together creates visual diagrams when it reverse engineers the code, and then keeps the visual model synchronized with subsequent changes to the code, and vice versa. Once the code is part of a Together project, you can quickly and easily generate up-to-date documentation.
Creating a project from existing EJB code is no different from creating any other kind of Java project. See:
Before you create a project for existing EJBs, read Developing and deploying EJBs: Configuring Together for EJB development.
When your Together license enables EJB support, two EJB icons display in the Class diagram toolbar:
|
|
Entity bean: Creates elements in the visual model, and generates the underlying source code, for a default implementation of a persistent entity EJB with skeleton declarations for:
|
|
|
Session bean: Creates elements in the visual model, and generates the underlying source code, for a default implementation of a nonpersistent session EJB with skeleton declarations for:
|
No properties or Business Methods are declared. There are several ways to add them:
Add them visually in the diagram using the implementation class's New speedmenu.
Add them visually using the EJB Inspector (speedmenu | Properties)
Write the declarations in source code in the Editor pane when the implementation class icon is selected.
Home and Remote interfaces are hidden in the diagram by default, but you can see them in the Explorer (see Configuring for EJBs for more information). The interface names are automatically synced with the name of the implementation class.
To create a "one-click" EJB:
Create or open a Together project and create or navigate to the desired package.
Create or open a Class diagram in the desired package.
On the Class diagram toolbar,
click the Entity EJB
icon
(to create that type) or the Session
EJB icon
(to create that type)
Click the diagram background to generate the EJB elements as described above.
The default code generated by one-click EJBs should be an adequate starting point for many developers. However, the default code is customizable by modifying the appropriate Code Template. You can customize the templates for Entity Bean class, Session Bean class, PrimaryKey class, Home Interface, and Remote Interface. For information on modifying these templates, see Using Code Templates.
Once you have a skeleton created by the on-click feature, you can use the EJB Inspector to edit it's properties.
To use the EJB Inspector:
Select the EJB in the diagram or the Explorer.
Press Alt - Enter or choose Properties from the speedmenu to display the EJB Inspector.
You can develop EJB's visually using the EBJ Inspector for bean classes (speedmenu | Properties). The Inspector has pages common to all classes, but adds some specifically for working with EJBs.
For Entity EJBs, pay attention to the Entity
EJB page.
For Session EJBs, pay attention to the Session EJB page.
The type-specific pages display a lower tabset that provide the means of specifying general properties, adding and removing business methods, defining references, and specifying bean type specific properties. Inspector for Entity EJB also has pages for defining Create and Finder methods.
|
|
|
|
Entity and Session EJB Inspectors |
You can optionally share the same set of home and remote interfaces between two or more EJB implementation classes of the same type (Session or Entity). You may want such capability in cases where you need to deploy differing implementations of the same interfaces on different servers.
In a case of shared interfaces, you should develop one complete implementation with home and remote interfaces. You can then create a second implementation class, refactor it into an EJB implementation, and specify the home and remote interfaces from the first bean in the properties of the new one.
To create a second implementation class:
Create or
open a Class diagram to show the new class.
Create a new class in the diagram and name it as desired.
To refactor the class to an EJB implementation:
Right-click and choose Choose Pattern from the speedmenu to display the Choose Pattern dialog.
Locate the EJB Implementation folder and expand it.
Select the Session EJB implementation or Entity EJB Implementation pattern and click Finish.
You can now begin developing the implementation, or you can proceed to specify the home and remote interfaces for the new bean class using the home/remote interfaces from the first implementation.
Note: In version 4.2 the EJB implementation patterns are missing from the Choose Pattern dialog. You must invoke the pattern from the Inspector field named Apply EJB Pattern.
To reuse the first implementations home/remote interfaces:
In the properties Inspector for the new class, select the xxxEJB page (where xxx is either Session or Entity depending on the type of EJB).
Choose the Do not synchronize names option button.
In the Remote Name field, click the browse button to display the Select Element dialog.
Use the Model node of the treeview to locate and select the remote interface belonging to the first implementation... that is, the remote interface that you want the bean you are working on to share.
Click OK to accept the selection. Respond Yes to the Change Class? prompt.
Do the same thing in the Home Name field, selecting the home interface for the first implementation in the Select Element dialog.
If the second implementation class in the same Class diagram as the first, Implementation links are automatically drawn from the interfaces to the second implementation class. If the two implementations are in different Class diagrams, you mmay want to show the second implementation class in the Class diagram for the first implementation.
To show a linked second implementation class:
Select the remote interface for the first implementation class.
Choose Add Linked from the interface speedmenu. Linked elements are shown in the Add Linked tab of the Message pane.
Select the second implementation class in the Message pane, right-click and choose Add.
A Class icon for the second implementation class is added to the diagram. You can now work on the second implementation class from either Class diagram.
Normally, if you delete an EJB implementation class, home and remote interfaces are deleted along with the implementation class, both in source ond in the diagram. In cases where interfaces have been shared with another implementation class, deleting elements from the diagram does not automatically result in deletion of the relevant source code files... only the visual diagram elements are deleted.
You must explicitly delete implementation classes, and home/remote interfaces by selecting them in the Model tab of the Explorer and choosing Delete from the speedmenu.
Note: you can find an animated demoguide at www.togethercommunity.com.
See also: