View Javadoc
1 2 3 package inklings.jgatms.command; 4 5 import java.util.List; 6 7 import net.sf.hibernate.Session; 8 import net.sf.hibernate.SessionFactory; 9 10 import org.apache.commons.chain.Context; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 import inklings.jgatms.ContextKeys; 16 17 /*** 18 * Opens a Hibernate session and places it in context. 19 * 20 * @author Greg Reddin 21 */ 22 public class OpenSession extends BaseCommand { 23 24 private static Log log = LogFactory.getLog(OpenSession.class); 25 26 public boolean execute(Context context) throws Exception { 27 28 SessionFactory sf = (SessionFactory) 29 context.get(getHibernateSessionFactoryKey()); 30 if (sf == null) { 31 log.error( 32 "No Hibernate SessionFactory found in application scope."); 33 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); 34 return true; 35 } 36 37 Session session = sf.openSession(); 38 if (session == null) { 39 log.error("Cannot add item: unable to create session"); 40 context.put(ContextKeys.DISPATCH_KEY, ContextKeys.FATAL_DISPATCH); 41 return true; 42 } 43 44 context.put(getHibernateSessionKey(), session); 45 return false; 46 } 47 48 }

This page was automatically generated by Maven