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:
- You are migrating to a new version of WebSphere Commerce. EJB projects developed to work with previous version of WebSphere Commerce that contain Container Managed Persistence (CMP) 1.x EJB beans need to be migrated to use WebSphere Commerce optimistic locking. Do this after migrating the EJB project to J2EE level 1.4.
- You created new entity beans and want to enable optimistic locking in your new bean. Note that you can manually enable optimistic locking, see Creating new entity beans for more information.
- Open WebSphere Commerce Developer.
- Optional: Validating that CMP entity beans can use optimistic locking
- Expand the EJB Project that you want to migrate.
- For each ejbCreate method in each class in the project:
- Add this.initializeFields(); as the first line in the method.
- 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; }
- Right-click the EJB Project that you want to migrate.
- Select Migrate to WC optimistic locking.
- 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.
- 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.
Validate that CMP entity beans can use optimistic locking
To use WebSphere Commerce optimistic locking, CMP 1.x EJB entity beans must extend from the ECEntityBean class. If the EJB entity bean class defines an ejbLoad method, that method must call super.ejbLoad. If it defines an ejbStore method, that method must call super.ejbStore. Use the WebSphere Commerce optimistic locking validation plug-in for IBM Rational Application Developer to check that the ejbLoad and ejbStore methods of entity beans extend from ECEntityBean or ECAbstractEntityBean:
Previous topic:Create the access bean
Next topic:Related tasks
Validate that CMP entity beans can use optimistic locking
Create new entity beans