Data beans:
Data beans implement one or all of the following Java interfaces:
- com.ibm.commerce.SmartDataBean
- com.ibm.commerce.CommandDataBean
- com.ibm.commerce.InputDataBean (optional)
Instantiating databean in JSP
<wcbase:useBean id="offersDatabean" classname="com.shc.ecom.offercenter.databean.OffersDataBean"> <c:set value=β${offerId}β property=βofferIdβ/> </wcbase:useBean>
Instantiating databean in Java
DataBeanManager.activate(data_bean, request, response)
Access Beans:
Access beans are wrappers over the entity beans.
Finding data by primary key
UserProfileAccessBean abUserProfile = new UserProfileAccessBean(); // set the primary key abUserProfile.setInitKey_UserId(getUserId().toString()); //call getter to get the DisplayName. Populate the access bean with data. String myDisplayName = abUserProfile.getDisplayName();
Using a refreshcopyhelper method
Do not need to use the refreshCopyHelper() if we are using a getter method to retrieve specific data from the access bean.Need to use it to explicitly tell the access bean to populate itself.
UserProfileAccessBean abUserProfile = new UserProfileAccessBean(); abUserProfile.setInitKey_UserId(getUserId().toString()); abUserProfile.refreshCopyHelper();
Finding data using a finder method
Access beans may also provide specific finder methods for commonly needed “find” operations.Returns an Enumeration of access beans that match the find criteria.Will throw javax.ejb.ObjectNotFoundException if no data matches with the finder criteria.
OrderAttributeValueAccessBean orderAttribute = new OrderAttributeValueAccessBean(); orderAttribute.findByOrderIdAndAttrName(orderId, attribute);
Creating new data using constructor
To create new data, we can initialize access bean constructor with one or more arguments.
//Create a new fullment center record. FulfillmentCenterAccessBean fcab = new FulfillmentCenterAccessBean(ownerId, fflname);
Then set any additional data on the bean using the provided setters, and call the commitCopyHelper() method.
fcab.setInventoryOperationFlags(flags); fcab.commitCopyHelper();
It is not required to call commitCopyHelper() to create the record using only the constructor.
Deleting a record using remove
To delete a record in the database using Access Beans, remove() method defined on the access bean’s.
// EJB remote interface. // Delete record using an AccessBean try { myAccessBean.getEJBRef().remove(); } catch( ObjectNotFoundException e) { //Exception }
The Persistence Layer OR Enterprise beans
The persistence layer within the WebSphere Commerce architecture is defined by EJB.
Types of enterprise beans
- Entity Beans
- Session Beans
Types of Entity Beans
- Container-managed persistence
- Bean-managed persistence
Types of Session Bean
- Stateless Session Bean: It doesn’t maintain state of a client between multiple method calls.
- Stateful Session Bean: It maintains state of a client across multiple requests.
- Singleton Session Bean: One instance per application, it is shared between clients and supports concurrent access.
Please let me know if you have any doubts on the above explanation. You can also check how to create an Entity bean here .
Awesome post! Keep up the great work! π
Great content! Super high-quality! Keep it up! π