Migrate EJB projects to use optimistic locking

Use the optimistic locking migration plug-in to enable optimistic locking in an EJB project.

The optimistic locking plug-in can be used in the following scenarios:

  1. Open WebSphere Commerce Developer.

  2. Optional: Validating that CMP entity beans can use optimistic locking

  3. Expand the EJB Project that you want to migrate.

  4. For each ejbCreate method in each class in the project:

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

    2. Add this.initializeOptCounter(primaryKey); as the last line in the method before the return statement, where primaryKey is the key generated by the key class. This method must be called after the primary key is set.

      The resulting method should look similar to the following example, in which memberId is the primary key:

      public com.ibm.commerce.extension.objects.BonusKey ejbCreate(java.lang.Long memberId,java.lang.Integer bonusPoint) 
      throws javax.ejb.CreateException
      {     
           this.initializeFields();
           _initLinks();
           this.memberId=memberId;
           this.bonusPoint=bonusPoint;
           BonusKey myNewBonusKey = new BonusKey (memberId);
           this.initializeOptCounter(myNewBonusKey);
           return null; }
      

  5. Right-click the EJB Project that you want to migrate.

  6. Select Migrate to WC optimistic locking.

  7. When the migration is complete, click Details. A report of the files migrated displays. Check to see which files were changed, and whether any errors were found. If store the migration results, you can select the results, right-click and select Copy and paste it into a text editor before clicking OK.

  8. Remember to re-deploy the EJB project for the changes to take effect.

The optimistic locking plug-in changes the following files:

File Changed File Type Changes Made
ejb-jar.xml EJB bean definitions A new CMP field named "optCounter" is added, if it does not already exist, to all EJB 1.x entity beans whose primary key starts with "java.lang", or ends with "<class-name>Key", where <class-name> is the name of the EJB 1.x entity bean class.
ibm-ejb-jar-ext.xmi IBM WebSphere EJB bean extensions. For each ejbExtensions element where xmi:type="ejbext:ContainerManagedEntityExtension", the plugin sets concurrencyControl="optimistic" and sets isolationLevel="READ_COMMITTED" on the isolationLevelAttributes element.
Map.mapxmi Mappings from EJB bean attribute definitions to database table schema column definitions For EJB 1.x entity beans, the plugin creates a mapping with optimistic="true", if it doesn't already exist, from the "optCounter" CMP field to the "OPTCOUNTER" table schema column.
*.tblxmi Database table schema column definitions If a mapping was created, in the previous step, in the Map.mapxmi file, for the "OPTCOUNTER" column, the plugin creates a new column definition for the "OPTCOUNTER" column, if it is not already defined.

When the plug-in detects that a change is required to a file, it writes the information from the original file in a file with the same name in the same directory but with an added extension of ".orig". It then replaces the original file with the migrated information. For example, the original information from the ejb-jar.xml file is written to a file named ejb-jar.xml.orig, and then the migrated information replaces the contents of the ejb-jar.xml file. Use a file differencing tool to see the changes that were made.


Previous topic:

Create the access bean
Next topic:

Generating deployed code

Related tasks

Validate that CMP entity beans can use optimistic locking
Create new entity beans