The
Persistence Layer
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
The
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
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)
No comments:
Post a Comment