Modifying Existing Beans & its interfaces
Pramati Studio enables component reuse strategy by allowing existing beans and interfaces to be modified. The following are the modifications that can be made to the beans:
- Business methods
- Create Methods
- Container Managed Fields
- Container Managed Relationships
- Finder Methods and queries
- EjbSelect Methods for CMP 2.0 beans
- Table Mappings
- Primary Key
- Abstract Schema Names
- References
Business Methods
To add business methods, or the get/set methods for CMPs/CMR(s),
- Open the bean class and add or modify the required method, save and compile it.
- Open the Interface Wizard from the main menu and choose the methods that are to be exposed in the respective interfaces.
Note: Checking the option, Auto-Interface generation, available under File >> Preferences automatically generates the interfaces and adds the new (public) methods in the bean source of both the local and remote interfaces (if present), after the bean is compiled. By default this option is checked. The second process therefore need not be performed in case the Auto interface option is checked, except when you want to restrict or control the way the methods are exposed in the interfaces manually.
Create Methods
These methods are similar to Business methods, except that the return type should be should be the same as the PK Class Type while writing the "ejbCreateXXX" method in the source. This method should also contain a corresponding "ejbPostCreateXXX" method.
In case the return type of "ejbCreate" method is incorrect or the "ejbPostCreateXXX" method signature is missing/incorrect, Studio ignores the create method as an invalid method. This is done to avoid deploy/run-time problems.
Checking the Auto-Interface generation option available in File Preferences dialog recognizes the new Create methods and also adds them to the home interfaces of the bean.
Container Managed Persistent Fields
Follow the given procedure to modify the container managed fields for CMP 2.0 beans:
- To edit the container managed fields of the bean, open the Bean class in the editor and edit it. To delete existing CMFs from the bean, delete the corresponding abstract get/set methods. To add new CMFs, add the corresponding abstract get/set methods.
- After making the required changes to the code, compile the bean immediately, so that the corresponding xml files of the bean properties xml files is corrected.
- When the auto interface generation option is checked in the File Preferences dialog, the interfaces get updated automatically.
- The OR Mappings also need to be changed. To do this, select the OR Mapping node in the Bean Properties dialog, and modify the mappings as required, depending on the changes made in the CMFs.
Follow the given procedure to modify the container managed fields for CMP 1.1 beans:
- To edit the container managed fields of the bean, open the Bean class in the editor and edit it. To delete existing CMFs from the bean, delete the corresponding fields. To add new CMFs, add the corresponding fields.
- After making the required changes to the code, compile the bean immediately.
- Open the Bean Properties dialog, select the Container Managed Fields node and check the added CMF fields.
- The OR Mappings also need to be changed. To do this, select the OR Mapping node in the Bean Properties dialog, and modify the mappings as required, depending on the changes made in the CMFs.
Container Managed Relationships
To modify, add or delete container managed relationships, follow the given procedure, which is similar to the container managed fields procedure:
- To edit the relationship, open the bean class file and edit the Java code. To delete existing CMRs, delete the corresponding get/set methods. To add new CMRs, add the corresponding get/set methods.
- Compile the modified bean class immediately after modifying the bean class file, so that the corresponding Bean Properties xml file gets corrected.
If the option, auto-interface generation, was checked in the File Preferences dialog, the interfaces get updated automatically.
- Double click on the corresponding Bean Properties node. This opens the Bean Properties dialog. Select the CMR node, and make the required changes to the CMR resolutions. In case of bi-directional relations and some special cases, you may also have to edit the target Bean Properties file. Add the necessary JOIN conditions also in the same panel.
Adding new Finder Methods and queries
Follow the given procedure for Finder Methods and its queries:
- Edit the Java code for the local home interface. Add the finder method signature in the interface code.
- Compile the bean and its interfaces.
- In case of CMP 1.1 beans, open the Bean Properties file by double clicking on the node, select the Finders node, and edit the query using the link to the Query Wizard. In case of CMP 2.0 beans, open the Bean Properties node, select the Finder/Select Methods node, and edit the query using the link to the EJB-QL dialog.
Adding EjbSelect Methods for CMP 2.0 beans
Follow the given procedure for modifying the EjbSelect methods for CMP beans:
- Add the EjbSelect methods to the bean class file. The bean source file is edited as the EjbSelect method is not added to the interfaces.
- Compile the bean immediately after editing the bean class file.
- Open the Bean Properties node by double clicking on the specific node, select the Finder/Select Methods node, and edit the query using the link to the EJB-QL dialog.
Table Mappings
Open the Bean Properties file by double clicking on the node on the Desk, select the OR Mapping node in the tree, and change the mappings as required.
Primary Key
To change the Primary Key's fields type, the signatures of the get/set methods of that field must be changed accordingly in the bean class file's code. The changed files then have to be compiled, and on compilation these changes are automatically updated in the xml files. To change the PK field itself or the compound PK field, open the Bean Properties file and make the required change.
Abstract Schema Names
Double click on the Bean Properties file and open it. Change the abstract schema name of the bean in the APS Field. The abstract schema also needs to be modified in all the EJB-QL Queries, where it has been used.
Adding References
Open the Bean Properties file, click on the References node, and make the required changes. To add the lookup code along with the necessary code, and the references automatically to the xml files, use the J2EE Assistant available from the main menu. Refer the relevant chapter for more details.