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 skills and loads it into context.
16 *
17 * @author Greg Reddin
18 */
19 public class GetSkillsList extends BaseCommand {
20
21 private static Log log = LogFactory.getLog(GetSkillsList.class);
22
23 public String getSkillsKey() {
24 return ContextKeys.SKILL_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 skills = null;
37 String query = "from skill in class inklings.jgatms.bean.Skill";
38
39 try {
40 skills = session.find(query);
41 context.put(getSkillsKey(), skills);
42 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH);
43 } catch (Exception e) {
44 log.fatal("Error getting skills 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