Prev | Current Page 678 | Next

Frank Zammetti

"Practical DWR 2 Projects"


Next up is the addGroupToPortal() method, shown here:
public List addGroupToPortal(final GroupDescriptor inGroup)
throws Exception {
try {
Map tokens = new HashMap();
tokens.put("groupname", inGroup.getGroupName());
tokens.put("description", inGroup.getDescription());
databaseWorker.executeUpdate(SQL_ADD_GROUP_TO_PORTAL, tokens);
return getGroupsList();
} catch (DataIntegrityViolationException dive) {
throw new Exception("Group could not be created. " +
"Does the group already exist?");
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
CHAPTER 7 n ENTER THE ENTERPRISE: A DWR-BASED REPORT PORTAL 396
Oh look! Something new! The catch of the DataIntegrityVoilationException, which is a
Spring abstraction around a SQLException, is there in case a group is added that already exists
(based on groupName). I didn??™t see any way to determine the exact cause of the failure (maybe
someone can e-mail me what I missed), so that??™s why the message returned is framed as a
question (although this should be the only possible cause anyway).
The removeGroupFromPortal() method follows that, and here??™s that code, lest I keep you in
suspense any longer:
@SuppressWarnings("unchecked")
public List removeGroupFromPortal(final String inGroupName)
throws Exception {
try {
Map tokens = new HashMap();
tokens.


Pages:
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690