Creating new session beans
When creating new session beans, create them in the WebSphereCommerceServerExtensionsData project.
About this task
Follow the Enterprise JavaBeans 3.0 (EJB 3) specification to create the necessary classes for the new sessionbean. If Rational Application Developer (RAD) is used, you can use the wizard that is provided within RAD to create the necessary classes for the new session bean. For more information, see Creating enterprise beans using wizards.
com.ibm.commerce.base.helpers.BaseJDBCHelper
class. The superclass
provides methods that allow you to obtain a JDBC connection object from the data source
object used by the HCL Commerce Server, so that the session bean participates
in the same transaction as the other entity beans. The following is an example of code
to demonstrate the functions provided by the superclass:
public class mySessionBean extends
com.ibm.commerce.base.helpers.BaseJDBCHelper {
public Object myMethod()
throws javax.naming.NamingException, SQLException
{
/////////////////////////////////////////////////
// -- your logic, such as initialization -- //
/////////////////////////////////////////////////
try {
// get a connection from the HCL Commerce data source
makeConnection();
PreparedStatement stmt = getPreparedStatement(
"your sql string");
////////////////////////////////////////////////////////////
// -- your logic such as set parameter into the prepared //
// statement -- //
///////////////////////////////////////////////////////////
ResultSet rs = executeQuery(stmt, false);
while(rs.next()) {
/////////////////////////////////////////////////
// -- your logic to process the result set -- //
////////////////////////////////////////////////
}
}
finally {
// return the connection to the HCL Commerce
data source
closeConnection();
}
/////////////////////////////////////////////////////
// -- your logic to return the result --- //
//////////////////////////////////////////////////////
}
}
In
the preceding code example, the executeQuery
method takes two input parameters. The
first is a prepared statement and the second is a Boolean flag related to a cache flush operation.
Set this flag to true
if you need the container to flush all entity objects for the
current transaction from the cache before executing the query. This would be required if you have
performed updates on some entity objects and you need the query to search through these updated
objects. If the flag were set to false
those entity object updates would not be
written to the database until the end of the transaction.
You should limit the use of this
flush operation and generally set the flag to false
, except in those cases where it
is really required. The flush operation is a resource-intensive operation.
According to the EJB 3 specification, the business interface is optional for the
stateless session bean. If you do not define the business interface for your session
bean, the method lookupSessionBean
in class
com.ibm.commerce.ejb.helpers.SessionBeanHelper
can be used to look
up the session bean you created.