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
14 /***
15 * Gets a list of all responses.
16 *
17 * @author Greg Reddin
18 */
19 public class GetResponses extends BaseCommand {
20
21 private static Log log = LogFactory.getLog(GetResponses.class);
22
23 public String getResponsesKey() {
24 return ContextKeys.RESPONSE_LIST_KEY;
25 }
26
27 public boolean execute(Context context) throws Exception {
28
29 Session session = (Session) context.get(getHibernateSessionKey());
30 if (session == null) {
31 log.error("No Hibernate Session object found.");
32 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH);
33 return true;
34 }
35
36 List responses = null;
37 String query = "from response in class inklings.jgatms.bean.Response";
38
39 try {
40 responses = session.find(query);
41 context.put(getResponsesKey(), responses);
42 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH);
43 } catch (Exception e) {
44 log.fatal("Error getting response list.", e);
45 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH);
46 return true;
47 } finally {
48 if (session != null)
49 session.close();
50 }
51
52 return false;
53 }
54
55 }
This page was automatically generated by Maven