1
2 package inklings.jgatms.command;
3
4 import java.util.List;
5
6 import net.sf.hibernate.Session;
7 import org.apache.commons.chain.Context;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import inklings.jgatms.ContextKeys;
13 import inklings.jgatms.bean.Question;
14
15 /***
16 * Gets all members registered in the system.
17 *
18 * @author Greg Reddin
19 */
20 public class GetMemberList extends BaseCommand {
21
22 private static Log log = LogFactory.getLog(GetMemberList.class);
23
24 public String getMembersKey() {
25 return ContextKeys.MEMBER_LIST_KEY;
26 }
27
28 public boolean execute(Context context) throws Exception {
29
30 Session session = (Session) context.get(getHibernateSessionKey());
31 if (session == null) {
32 log.error("No Hibernate Session object found.");
33 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH);
34 return true;
35 }
36
37 List members = null;
38 String query = "from member in class inklings.jgatms.bean.Member";
39
40 try {
41 members = session.find(query);
42 context.put(getMembersKey(), members);
43 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH);
44 } catch (Exception e) {
45 log.fatal("Error getting members.", e);
46 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH);
47 return true;
48 } finally {
49 if (session != null)
50 session.close();
51 }
52
53 return false;
54 }
55
56 }
This page was automatically generated by Maven