Modifying Existing Beans & their Interfaces
Overview
Pramati Studio enables component reuse strategy by allowing modification of existing beans and their interfaces. This document describes how to modify business methods, create methods, CMFs, CMRs, Finder methods and Queries, ejbSelect methods for CMP 2.0 beans, table mappings, primary key, abstract schema names, and references for beans.
Adding business methods
To add business methods, or the get/set methods for CMPs/CMR(s),
- Open the bean class in Editor
- Add or modify the required method; save and compile it.
- Select Tools > Interface Wizard from the main menu. Choose the methods to be exposed in respective interfaces.
Checking the option, Auto-Interface generation, available under File > IDE Options > General automatically generates interfaces and adds new public methods in the bean source of both Local and Remote interfaces after the bean is compiled. By default this option is checked. Step -3 need not be performed if Auto- Interface generation option is checked except when you want to manually control the way methods are exposed in the interfaces.
Adding create methods
Create methods are similar to business methods, except that the return type should be same as the PK class type while writing ejbCreateXXX() method in the source. This method should also contain a corresponding ejbPostCreateXXX() method. If the return type of ejbCreate method is incorrect or ejbPostCreate method signature is missing, Studio considers it to be a validation error. For more information, read `J2EE Coding Aids'. To avoid deploy time and runtime problems, Studio ignores the ejbCreate method. Checking the Auto-Interface generation option available in IDE Options panel recognizes the new create methods and adds them to Home interfaces of the bean.
Modifying container managed persistent fields
Follow the given procedure to modify CMFs for CMP 2.0 beans:
- To edit CMFs of the bean, open the bean class in Editor and modify as required. To remove existing CMFs from the bean, delete the corresponding abstract get/set methods. To include new CMFs, add the corresponding abstract get/set methods.
- Compile the bean so that corresponding bean properties XML is updated.
- When the Auto-interface generation option is selected in IDE Options panel, the interfaces get updated automatically.
- OR mapping also needs to be modified. Select a OR mapping node in Bean Properties dialog and modify as per changes made in CMFs.
To modify CMFs for CMP 1.1 beans:
- Open the bean class in Editor and make changes as required. To remove existing CMFs from the bean, delete corresponding fields. To add new CMFs, add corresponding fields to the code.
- Compile the bean.
- Open Bean Properties dialog, select the CMF node and select the added CMF fields.
- To change OR mappings, click the OR mapping node in Bean Properties dialog. Modify mapping depending on the changes made in CMFs.
Configuring Container Managed Relationships
To modify, add, or delete CMRs follow a procedure similar to modifying e CMFs:
- Open the bean class file in Editor and modify the code as required. To remove existing CMRs, delete corresponding get/set methods. To add new CMRs, add corresponding get/set methods.
- Compile the modified bean class so that the corresponding Bean Properties XML gets updated. If the option, Auto-Interface generation is checked in IDE Options 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 the corresponding queries:
- Edit the Java code for the local or 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 field type, the signatures of the get/set methods of that field must be changed accordingly in the bean class file 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.