Tutorials > Content management > Create a content-managed resource > Creating the new resource

< Previous | Next >


Create an entity bean for the new table

The entity bean is created following the steps of the tutorial creating new entity beans.


Procedure

  1. Switch to the Java EE perspective.

  2. In Rational Application Developer, switch to the Enterprise Explorer view.

  3. Expand WebSphereCommerceServerExtensionsData.

  4. Expand Deployment Descriptor :WebSphereCommerceServerExtensionsData.

  5. Right-click Entity Beans and select New > Entity Bean.

  6. In the Create an Enterprise Bean window, create the bean:

    1. Select Entity bean with container-managed persistence (CMP) fields.

    2. In the Bean name field, type ExtendedCatalogDescription.

    3. In the Source folder field, leave the default value, ejbModule.

    4. In the Default package field, type com.mycompany.catalog.objects.

    5. From the CMP vlist, select 1.x.

    6. Click Next.

  7. In the Enterprise Bean Details window, add new CMP attributes for all the columns from the EXTCATALOGDSC table:

    1. Select the default CMP attribute id: java.lang.Integer and click Remove.

    2. Click Add.

      1. In the Name field, type catalog_id.

      2. In the Type field, type java.lang.Long. You must use the java.lang.Long data type, not the long data type.

      3. Select Key Field to indicate that this field is the primary key of the database table.

      4. Click Apply.

      5. In the Name field, type language_id.

      6. In the Type field, type java.lang.Integer. Note: You must use the java.lang.Integer data type, not the integer data type.

      7. Select the Key Field to indicate that this field is the primary key of the database table.

      8. Click Apply.

      9. In the Name field, type lastModified.

      10. In the Type field, type java.sql.Timestamp.

      11. Ensure that Access with getter and setter methods is selected. When you select this option, getter and setter methods are automatically generated for all fields.

      12. Clear the Promote getter and setter methods to remote interface check box. The Make getter read-only check box will be made unavailable. Clearing the promote getter and setter methods to remote interface causes less overhead and better performance. Since the getter and setter methods are not promoted to the remote interface, clients will not be able to access the methods. Instead of using the remote interface, CopyHelper Access Beans exist that contain getters and setters for CMP fields that do not exist on the remote interface. The methods within the CopyHelper Access Beans write data to a hash table that in turn updates the database when commitCopyHelper() is called. The hash table can record multiple database changes then update the database in one transaction, unlike the remote methods which require one transaction per change. There is also a method called refreshCopyHelper(), which does the reverse function of commitCopyHelper(). The method refreshCopyHelper() writes to the hash table from the database. Deselecting the box ensures that the hashtable is used, resulting in the performance increase.

      13. Click Apply.

      14. In the Name field, type frontImg.

      15. Clear the Promote getter and setter methods to remote interface check box.

      16. In the Type field, type java.lang.String.

      17. Ensure that Access with getter and setter methods is selected. When you select this option, getter and setter methods are automatically generated for all fields.

      18. Click Apply.

      19. Repeat steps 14 through 18 for backImg, sideImg, and topImg.

      20. In the Name field, type optCounter. The OPTCOUNTER column is used for optimistic locking, described later in the tutorial.

      21. In the Type field, type short.

      22. Click Apply then Close to close this window.

    3. Ensure that Use the single key attribute type for the key class is not selected, then click Next. Clearing this check box ensures that a key class is created, ensuring consistency with other beans.

  8. In the EJB Java Class Details window:

    1. To select the bean's super class, click Browse.

    2. In the Type Selection window, in the Select a class using: (any) field, type ECEntityBean and click OK.

    3. Specify the interfaces that the remote interface should extend by clicking Add.

    4. In the Type Selection window, in the Select an interface using: (any) field, type Protectable and click OK to select com.ibm.commerce.security.Protectable. This interface is required in order to protect the new resource under access control.

    5. Click Next.

    6. Clear the Add bean to Class Diagram

    7. Click Finish.

  9. Set the isolation level for the new bean.

    1. Expand WebSphereCommerceServerExtensionsData > Deployment Descriptor : WebSphereCommerceServerExtensionsData > Entity Beans.

    2. Double-click the ExtendedCatalogDescription bean to open its deployment descriptor.

    3. Click the Access tab.

    4. Next to the Isolation Level text box, click Add.

    5. In the Add Isolation Level window, select Read committed, then click Next.

    6. From the Beans found list, select the ExtendedCatalogDescription bean, then click Next.

    7. From the Methods found list, select ExtendedCatalogDescription to select all of its methods, and click Finish.

    8. Save the work and keep the editor open.

  10. Set the security identity for the bean

    1. Ensure that you still have the Access tab selected.

    2. In the Security Identity (Method Level) section, click Add.

    3. Select Use identity of EJB server, then click Next. The Use identity of EJB server field ensures that all EJB beans run under the same identity for security.

    4. From the Beans found list, select the ExtendedCatalogDescription bean, then click Next.

    5. From the Methods found list, select ExtendedCatalogDescription to select all of its methods, and click Finish.

    6. Save the work and keep the editor open.

  11. Set the security role for the bean

    1. In the Deployment Descriptor editor, select the Assembly tab.

    2. In the Method Permissions section, click Add.

    3. Select Security Roles then WCSecurityRole and click Next. This is the default security role for all EJB beans in WebSphere Commerce.

    4. From the list of beans found, select ExtendedCatalogDescription and click Next.

    5. In the Method elements page, click Apply to All, then click Finish.

    6. Save the work.

  12. Remove some generated fields and methods

    Rational Application Developer automatically generates some fields and methods related to the entity context; some of these methods must be removed because the ECEntityBean base class provides its own implementation for those methods.

    1. In the Java EE Hierarchy view, expand WebSphereCommerceServerExtensionsData.

    2. Expand Deployment Descriptor: WebSphereCommerceServerExtensionsData > Entity Beans > ExtendedCatalogDescription, and open the ExtendedCatalogDescriptionBean class.

    3. In the Outline view:

      1. Right-click the myEntityCtx field and select Delete.

      2. Right-click the getEntityContext() method and select Delete.

      3. Right-click the setEntityContext(EntityContext) method and select Delete.

      4. Right-click the unsetEntityContext() method and select Delete.

    4. Save the work. Keep the ExtendedCatalogDescription class open.

  13. Add getters and setters for primary keys

    In Rational Application Developer you cannot select the Access with getter and setter methods check box when you add the primary key fields. You add these methods manually.

    1. In the Java EE Hierarchy view, expand WebSphereCommerceServerExtensionsData.

    2. Expand Deployment Descriptor: WebSphereCommerceServerExtensionsData > Entity Beans > ExtendedCatalogDescription, and open the ExtendedCatalogDescriptionBean class.

    3. In the Editor view, add the following methods:

      /**
        * @return Returns the catalog_id.
        */
       public java.lang.Long getCatalog_id() {
        return catalog_id;
       }
       /**
        * @param catalog_id The catalog_id to set.
        */
       public void setCatalog_id(java.lang.Long catalog_id) {
        this.catalog_id = catalog_id;
       }
       /**
        * @return Returns the language_id.
        */
       public java.lang.Integer getLanguage_id() {
        return language_id;
       }
       /**
        * @param language_id The language_id to set.
        */
       public void setLanguage_id(java.lang.Integer language_id) {
        this.language_id = language_id;
       }
      

    4. Save the work. Keep the ExtendedCatalogDescriptionBean class open.

< Previous | Next >


+

Search Tips   |   Advanced Search