1 package org.jbpm.webapp.context; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.jbpm.db.JbpmSession; 6 import org.jbpm.db.JbpmSessionFactory; 7 import org.jbpm.identity.hibernate.IdentitySession; 8 9 public class PersistenceContext { 10 11 static JbpmSessionFactory jbpmSessionFactory = JbpmSessionFactory.getInstance(); 12 13 boolean isRollbackOnly; 14 JbpmSession jbpmSession; 15 IdentitySession identitySession; 16 17 public void beginTransaction() { 18 isRollbackOnly = false; 19 log.debug("beginning transaction"); 20 jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction(); 21 identitySession = new IdentitySession(jbpmSession.getSession()); 22 } 23 24 public void endTransaction() { 25 if (isRollbackOnly) { 26 log.debug("rolling back transaction"); 27 jbpmSession.rollbackTransactionAndClose(); 28 } else { 29 log.debug("committing transaction"); 30 jbpmSession.commitTransactionAndClose(); 31 } 32 } 33 34 public void setRollbackOnly() { 35 isRollbackOnly = true; 36 } 37 38 public IdentitySession getIdentitySession() { 39 return identitySession; 40 } 41 42 public JbpmSession getJbpmSession() { 43 return jbpmSession; 44 } 45 46 private static final Log log = LogFactory.getLog(PersistenceContext.class); 47 } 48 | Popular Tags |