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

< Previous | Next >


Enable optimistic locking for the entity bean


Procedure

  1. Enable optimistic locking in the deployment descriptor:

    1. In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsData > Deployment Descriptor : WebSphereCommerceServerExtensionsData.

    2. Open the deployment descriptor for editing.

    3. In the Bean tab, select the ExtendedCatalogDescription.

    4. In the lower right pane, scroll down to the Concurrency Control section.

    5. Select Enable optimistic locking.

    6. Save the changes and close the EJB Deployment Descriptor editor.

  2. Set the optimistic predicate value of the optcounter field:

    1. In the Enterprise Explorer view, navigate to WebSphereCommerceServerExtensionsData > ejbModule > META-INF > backends > database_type, where database_type is the type of database you are using.

    2. Open the Map.mapxmi file for editing.

    3. In the Overview section, in the Enterprise Beans pane, select optcounter : short.

    4. Select the Properties view, and select true from the OptimisticPredicate list. Your screen should resemble the following screen capture:

  3. Edit methods to call optimistic locking classes. In the ExtendedCatalogDescriptionBean class make the following changes:

    1. In the Outline view, select ejbLoad() and add the following code as the first line in the method: super.ejbLoad();

    2. In the Outline view, select ejbStore() and add the following code as the first line in the method: super.ejbStore();

    3. In the Outline view, select ejbCreate(EntityBeanCreationData data) and add the following code:

      1. Add this.initializeFields(); as the first line in the method.

      2. Add

        ExtendedCatalogDescriptionKey myNewKey = new ExtendedCatalogDescriptionKey (catalog_id, language_id);
        this.initializeOptCounter(myNewKey);
        
        

        as the last two lines before the return statement.

      The resulting method should look like the following snippet:

      public com.mycompany.catalog.objects.ExtendedCatalogDescriptionKey ejbCreate(EntityBeanCreationData data)
         throws javax.ejb.CreateException {
            this.initializeFields();
            _initLinks();
            ...
            ExtendedCatalogDescriptionKey myNewKey = new ExtendedCatalogDescriptionKey (catalogId, languageId);
            this.initializeOptCounter(myNewKey);
            return null;
      }
      

  4. Comment out the optCounter variable in the ExtendedCatalogDescriptionBean class.

    Both the ECEntityBean and ExtendedCatalogDescriptionBean classes define a variable called optCounter, and each class maintains its own copy.

    To ensure that both classes use the same optCounter variable, comment out the one defined in ExtendedCatalogDescriptionBean.

    • Search for private short optCounter;; Comment out the variable as shown:

      //private short optCounter;
      

  5. Save the changes.

< Previous | Next >


+

Search Tips   |   Advanced Search