|
From: Greg R. <gr...@us...> - 2004-04-06 23:02:44
|
Update of /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2862/src/prod/inklings/jgatms/command Modified Files: AddResponseToQuestion.java BaseCommand.java BuildSessionFactory.java GetMemberList.java GetQuestion.java GetQuestions.java GetResponses.java GetSkillsList.java OpenSession.java Added Files: AddMember.java GetSkillLevels.java Log Message: Added keys for AddMember and GetSkillLevels commands --- NEW FILE: GetSkillLevels.java --- package inklings.jgatms.command; import java.util.List; import net.sf.hibernate.Session; import org.apache.commons.chain.Context; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import inklings.jgatms.ContextKeys; import inklings.jgatms.context.JgatmsContext; /** * Gets a list of skill levels and loads it into context. * * @author Greg Reddin */ public class GetSkillLevels extends BaseCommand { private static Log log = LogFactory.getLog(GetSkillsList.class); public String getSkillLevelsKey() { return ContextKeys.SKILL_LEVELS_KEY; } public boolean execute(JgatmsContext context) throws Exception { Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } List skillLevels = null; String query = "from skillLevel in class inklings.jgatms.bean.SkillLevel"; try { skillLevels = session.find(query); context.put(getSkillLevelsKey(), skillLevels); } catch (Exception e) { log.fatal("Error getting skill levels list.", e); context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { if (session != null) session.close(); } return false; } } Index: BaseCommand.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/BaseCommand.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** BaseCommand.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- BaseCommand.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 6,9 **** --- 6,10 ---- import inklings.jgatms.ContextKeys; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 14,27 **** public abstract class BaseCommand implements Command { ! public String getHibernateSessionKey() { ! return ContextKeys.HIBERNATE_SESSION_KEY; ! } ! ! public String getHibernateSessionFactoryKey() { ! return ContextKeys.HIBERNATE_SESSION_FACTORY_KEY; } ! public String getDispatchKey() { ! return ContextKeys.DISPATCH_KEY; ! } } --- 15,26 ---- public abstract class BaseCommand implements Command { ! public boolean execute(Context context) throws Exception { ! if (context instanceof JgatmsContext) { ! return execute((JgatmsContext) context); ! } else { ! return false; ! } } ! public abstract boolean execute(JgatmsContext context) throws Exception; } Index: GetQuestions.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/GetQuestions.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GetQuestions.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- GetQuestions.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- import inklings.jgatms.ContextKeys; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 25,34 **** } ! public boolean execute(Context context) throws Exception { ! Session session = (Session) context.get(getHibernateSessionKey()); if (session == null) { log.error("No Hibernate Session object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 26,35 ---- } ! public boolean execute(JgatmsContext context) throws Exception { ! Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 40,47 **** questions = session.find(query); context.put(getQuestionsKey(), questions); - context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH); } catch (Exception e) { log.fatal("Error getting question list.", e); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } finally { --- 41,47 ---- questions = session.find(query); context.put(getQuestionsKey(), questions); } catch (Exception e) { log.fatal("Error getting question list.", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { Index: GetSkillsList.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/GetSkillsList.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GetSkillsList.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- GetSkillsList.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- import inklings.jgatms.ContextKeys; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 25,34 **** } ! public boolean execute(Context context) throws Exception { ! Session session = (Session) context.get(getHibernateSessionKey()); if (session == null) { log.error("No Hibernate Session object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 26,35 ---- } ! public boolean execute(JgatmsContext context) throws Exception { ! Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 40,47 **** skills = session.find(query); context.put(getSkillsKey(), skills); - context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH); } catch (Exception e) { log.fatal("Error getting skills list.", e); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } finally { --- 41,47 ---- skills = session.find(query); context.put(getSkillsKey(), skills); } catch (Exception e) { log.fatal("Error getting skills list.", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { Index: GetQuestion.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/GetQuestion.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GetQuestion.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- GetQuestion.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 12,15 **** --- 12,16 ---- import inklings.jgatms.ContextKeys; import inklings.jgatms.bean.Question; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 30,39 **** } ! public boolean execute(Context context) throws Exception { ! Session session = (Session) context.get(getHibernateSessionKey()); if (session == null) { log.error("No Hibernate Session object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 31,40 ---- } ! public boolean execute(JgatmsContext context) throws Exception { ! Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 42,46 **** if (questionId == null) { log.error("Can't get question. No questionId present."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 43,47 ---- if (questionId == null) { log.error("Can't get question. No questionId present."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 50,57 **** Question.class, questionId); context.put(getQuestionKey(), question); - context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH); } catch (Exception e) { log.fatal("Error getting question.", e); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } finally { --- 51,57 ---- Question.class, questionId); context.put(getQuestionKey(), question); } catch (Exception e) { log.fatal("Error getting question.", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { --- NEW FILE: AddMember.java --- package inklings.jgatms.command; import net.sf.hibernate.Session; import net.sf.hibernate.Transaction; import org.apache.commons.chain.Context; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import inklings.jgatms.ContextKeys; import inklings.jgatms.bean.Member; import inklings.jgatms.context.JgatmsContext; /** * Adds a member to the JGATMS database. * * @author Greg Reddin */ public class AddMember extends BaseCommand { private static Log log = LogFactory.getLog(AddMember.class); public boolean execute(JgatmsContext context) throws Exception { Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } Member member = context.getMember(); if (member == null) { log.error("No JGATMS member bean found."); context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } Transaction tx = null; try { tx = session.beginTransaction(); session.save(member); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } log.fatal("Could not add response to question.", e); context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { if (session != null) session.close(); } return false; } } Index: OpenSession.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/OpenSession.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** OpenSession.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- OpenSession.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 14,17 **** --- 14,18 ---- import inklings.jgatms.ContextKeys; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 24,35 **** private static Log log = LogFactory.getLog(OpenSession.class); ! public boolean execute(Context context) throws Exception { ! SessionFactory sf = (SessionFactory) ! context.get(getHibernateSessionFactoryKey()); if (sf == null) { log.error( "No Hibernate SessionFactory found in application scope."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 25,35 ---- private static Log log = LogFactory.getLog(OpenSession.class); ! public boolean execute(JgatmsContext context) throws Exception { ! SessionFactory sf = context.getSessionFactory(); if (sf == null) { log.error( "No Hibernate SessionFactory found in application scope."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 38,46 **** if (session == null) { log.error("Cannot add item: unable to create session"); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } ! context.put(getHibernateSessionKey(), session); return false; } --- 38,46 ---- if (session == null) { log.error("Cannot add item: unable to create session"); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } ! context.setSession(session); return false; } Index: BuildSessionFactory.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/BuildSessionFactory.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** BuildSessionFactory.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- BuildSessionFactory.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 14,17 **** --- 14,18 ---- import inklings.jgatms.ContextKeys; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 24,31 **** private static Log log = LogFactory.getLog(BuildSessionFactory.class); ! public boolean execute(Context context) throws Exception { ! SessionFactory sf = (SessionFactory) ! context.get(getHibernateSessionFactoryKey()); if (sf == null) { --- 25,31 ---- private static Log log = LogFactory.getLog(BuildSessionFactory.class); ! public boolean execute(JgatmsContext context) throws Exception { ! SessionFactory sf = context.getSessionFactory(); if (sf == null) { *************** *** 34,44 **** } catch (Exception e) { log.fatal("Unable to initialize database connection", e); ! context.put(ContextKeys.DISPATCH_KEY, ! ContextKeys.FATAL_DISPATCH); return true; } } ! context.put(getHibernateSessionFactoryKey(), sf); return false; } --- 34,43 ---- } catch (Exception e) { log.fatal("Unable to initialize database connection", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } } ! context.setSessionFactory(sf); return false; } Index: GetResponses.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/GetResponses.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GetResponses.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- GetResponses.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- import inklings.jgatms.ContextKeys; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 25,34 **** } ! public boolean execute(Context context) throws Exception { ! Session session = (Session) context.get(getHibernateSessionKey()); if (session == null) { log.error("No Hibernate Session object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 26,35 ---- } ! public boolean execute(JgatmsContext context) throws Exception { ! Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 40,47 **** responses = session.find(query); context.put(getResponsesKey(), responses); - context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH); } catch (Exception e) { log.fatal("Error getting response list.", e); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } finally { --- 41,47 ---- responses = session.find(query); context.put(getResponsesKey(), responses); } catch (Exception e) { log.fatal("Error getting response list.", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { Index: GetMemberList.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/GetMemberList.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GetMemberList.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- GetMemberList.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 12,15 **** --- 12,16 ---- import inklings.jgatms.ContextKeys; import inklings.jgatms.bean.Question; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 26,35 **** } ! public boolean execute(Context context) throws Exception { ! Session session = (Session) context.get(getHibernateSessionKey()); if (session == null) { log.error("No Hibernate Session object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 27,36 ---- } ! public boolean execute(JgatmsContext context) throws Exception { ! Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 41,48 **** members = session.find(query); context.put(getMembersKey(), members); - context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH); } catch (Exception e) { log.fatal("Error getting members.", e); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } finally { --- 42,48 ---- members = session.find(query); context.put(getMembersKey(), members); } catch (Exception e) { log.fatal("Error getting members.", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { Index: AddResponseToQuestion.java =================================================================== RCS file: /cvsroot/jgatms/jgatms-core/src/prod/inklings/jgatms/command/AddResponseToQuestion.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** AddResponseToQuestion.java 29 Jan 2004 23:38:25 -0000 1.1.1.1 --- AddResponseToQuestion.java 6 Apr 2004 22:49:50 -0000 1.2 *************** *** 14,17 **** --- 14,18 ---- import inklings.jgatms.bean.Question; import inklings.jgatms.bean.Response; + import inklings.jgatms.context.JgatmsContext; /** *************** *** 24,33 **** private static Log log = LogFactory.getLog(AddResponseToQuestion.class); ! public boolean execute(Context context) throws Exception { ! Session session = (Session) context.get(getHibernateSessionKey()); if (session == null) { log.error("No Hibernate Session object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 25,34 ---- private static Log log = LogFactory.getLog(AddResponseToQuestion.class); ! public boolean execute(JgatmsContext context) throws Exception { ! Session session = context.getSession(); if (session == null) { log.error("No Hibernate Session object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 36,40 **** if (question == null) { log.error("Cannot add response. No question object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 37,41 ---- if (question == null) { log.error("Cannot add response. No question object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 43,47 **** if (response == null) { log.error("Cannot add response. No response object found."); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } --- 44,48 ---- if (response == null) { log.error("Cannot add response. No response object found."); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } *************** *** 53,57 **** session.update(question); tx.commit(); - context.put(ContextKeys.DISPATCH_KEY, ContextKeys.SUCCESS_DISPATCH); } catch (Exception e) { if (tx != null) { --- 54,57 ---- *************** *** 60,64 **** log.fatal("Could not add response to question.", e); ! context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); return true; } finally { --- 60,64 ---- log.fatal("Could not add response to question.", e); ! context.setDispatch(ContextKeys.FATAL_DISPATCH); return true; } finally { |