WebSphere Commerce commands can't interact directly with entity beans but it does it through access beans .Access beans acts as a simpler interface to clients, caching of the home object, and reduced call traffic to the enterprise bean.Access beans is similar to like Java beans, and it hides all enterprise bean-specific programming interfaces from the client, like the JNDI, home and remote interfaces.
Advantages of using AccessBeans
During run time the access bean caches the enterprise bean home object to avoid look ups to the home object as it is expensive.Access bean implements a copyHelper object which reduces the number of calls to the enterprise bean when commands get and set enterprise bean attributes. Only a single call is required for multiple attributes.In the access bean, the get and set methods are not automatically cached. Only the methods that are part of the copy helper object are cached.
Types of Access beans are:
1. Copy Helper methods.
2. Finder methods.
3. EJB methods.
The access bean implements a copyHelper object that reduces the number of calls to the enterprise bean when commands get and set enterprise bean attributes. Only a single call to the enterprise bean is required when reading or writing multiple bean attributes.The copy helper object is stored inside the access bean.A getter and setter method is delegated to the local copy helper object instead of the remote enterprise bean object.To commit the changes in the copy helper to the remote enterprise bean or to refresh the local copy helper from the remote enterprise bean, your client program must call commitCopyHelper() and refreshCopyHelper() respectively.
There are 2 types of Copy Helper methods:
refreshCopyHelper(): refresh copy helper is treated as "find for update” and it locks that particular row unless or until you are done with entire transaction. So you read something with refreshcopyHelper and you keep doing no of things and when you are finally done then only these locks are released.
commitCopyHelper(): commitCopyHelper() takes the current state of the access bean and updates the database with it.
Finding data using an access bean
Finding data by primary key
//create a new access bean
UserProfileAccessBean userProfileAccessBean = new UserProfileAccessBean();
// set the primary key
userProfileAccessBean.setInitKey_UserId(getUserId().toString());
//call getter to get the DisplayName.
String myDisplayName = userProfileAccessBean getDisplayName();
When to use refreshCopyHelper()
Use the refreshCopyHelper method to retrieve information from the database and populate the access bean. You do not need to use the refreshCopyHelper() if you are using a getter method to retrieve specific data from the access bean. You only need to use it to explicitly tell the access bean to populate itself.
//Create a new access bean
UserProfileAccessBean userProfileAccBean = new UserProfileAccessBean();
//Set the primary key
userProfileAccBean.setInitKey_UserId(getUserId().toString());
//Call refreshCopyHelper to populate it with data
userProfileAccBean.refreshCopyHelper();
Finding data using a finder method
These methods will return you an Enumeration of access beans that match the find criteria. If records are found, there will be one or more fully populated access beans in the Enumeration. If the result of the finder is empty, the finder method will throw javax.ejb.ObjectNotFoundException.
AddressAccessBean addressAccessBean = new AddressAccessBean().findByNickname("nickname", new Long("10001"));
Where nickname is the search term used for the nick name.
Inserting data using access beans
You can access beans to create new data as part of your business logic.To create new data, use any access bean constructor with one or more arguments. You can then set any additional data on the bean using the provided setters, and call the commitCopyHelper() method.
//Create a new fulfillment center record.
FulfillmentCenterAccessBean fulfillmentCenterAccessBean = new FulfillmentCenterAccessBean(ownerId, fflname);
//Set additional data on the access bean.
fulfillmentCenterAccessBean .setInventoryOperationFlags(flags);
//Commit the inventory operation flags update
fulfillmentCenterAccessBean .commitCopyHelper();
No need to call commitCopyHelper() if you create the record using only the constructor, and do not call additional setters.
Deleting data using an access bean
You can delete data from the WebSphere Commerce database in your business logic using the remove() method on the access bean's EJB remote interface.The EJB remote interface can be obtained by using the getEJBRef() method on the access bean.
// Delete record using an AccessBean
try
{
testAccessBean.getEJBRef().remove();
}
catch( ObjectNotFoundException e) {
// Tried to delete a record that does not exist
}
EJB files to be committed in SVN(Repository) after creating \ updating EJB (Using IBM DB2 DataBase v9.7)
Below are the list of files to be committed to repository after create\update an EJB
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogKey.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogHome.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogFactory.java.
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogBean.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogAccessBeanData.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogAccessBean.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLog.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogHome.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogFactory.java.
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogBean.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogAccessBeanData.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLogAccessBean.java
WebSphereCommerceServerExtensionsData\ejbModule\com\abc\member\data\objects\EXLog.java
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\backends\DB2UDBNT_V97_1\Map.mapxmi
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\backends\DB2UDBNT_V97_1\ProfileDBSchema.dbm
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ejb-jar.xml
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ibm-ejb-access-bean.xmi
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ibm-ejb-jar-bnd.xmi
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ibm-ejb-jar-ext.xmi
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\backends\DB2UDBNT_V97_1\ProfileDBSchema.dbm
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ejb-jar.xml
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ibm-ejb-access-bean.xmi
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ibm-ejb-jar-bnd.xmi
WebSphereCommerceServerExtensionsData\ejbModule\META-INF\ibm-ejb-jar-ext.xmi
No comments:
Post a Comment