ibm.com/developerWorks
Presented by developerWorks, your source for great tutorials
UserManagementBean
business method
decomposition
Notice that the addUser method takes an e mail, and a password argument. The
method then calls the
LocalUserHome
s create method as follows:
public void addUser(String email, String password) {
LocalUser user = userHome.create(email, password);
The removeUser method uses the e mail argument passed to it to call the
LocalUserHome
s remove method to remove the
UserBean
from the container, that
is, delete the row in the database corresponding to the
UserBean
. Since the e mail
address is the primary key, it can be used to uniquely identify the entity and remove it
with the home interface s remove method. Note that you did not define the remove
method in the home interface it was inherited from javax.ejb.EJBLocalHome interface
and it was implemented by the EJB container.
public void removeUser(String email) {
userHome.remove(email);
The verifyPassword method uses the
LocalUserHome
s
findByPrimaryKey()
method to look up the
UserBean
instance associated with the e mail primary key. The
verifyPassword method then uses the CMP password field of the entity to compare to
the password that was passed as an argument to determine if they match as follows:
public boolean verifyPassword(String email, String password){
LocalUser user = userHome.findByPrimaryKey(email);
return user.getPassword().equals(password);
The business methods of the session bean use the
UserBean
to manage the
instances of the user bean (add, remove), and to verify the password is the same as
the one passed. As far as the
UserManagementBean
session bean is concerned at
this point, there is nothing special about the
UserBean
entity bean.
Page 24 of 48
Introducing EJB CMP/CMR, Part 1 of 2
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved