swf-1010
This commit is contained in:
@@ -51,10 +51,10 @@ import org.springframework.webflow.execution.RequestContext;
|
||||
*
|
||||
* The general data access pattern implemented here is:
|
||||
* <ul>
|
||||
* <li> Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
|
||||
* <li> Load some objects into this persistence context
|
||||
* <li> Perform edits to those objects over a series of requests into the flow
|
||||
* <li> On successful flow completion, commit and flush those edits to the database, applying a version check if
|
||||
* <li>Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
|
||||
* <li>Load some objects into this persistence context
|
||||
* <li>Perform edits to those objects over a series of requests into the flow
|
||||
* <li>On successful flow completion, commit and flush those edits to the database, applying a version check if
|
||||
* necessary.
|
||||
* </ul>
|
||||
*
|
||||
@@ -132,9 +132,9 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter
|
||||
}
|
||||
}
|
||||
|
||||
public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
|
||||
public void sessionEnding(RequestContext context, FlowSession session, String outcome, MutableAttributeMap output) {
|
||||
if (isPersistenceContext(session.getDefinition())) {
|
||||
final Session hibernateSession = (Session) session.getScope().remove(PERSISTENCE_CONTEXT_ATTRIBUTE);
|
||||
final Session hibernateSession = getHibernateSession(session);
|
||||
Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
|
||||
if (Boolean.TRUE.equals(commitStatus)) {
|
||||
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||
@@ -148,6 +148,9 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter
|
||||
unbind(hibernateSession);
|
||||
hibernateSession.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
|
||||
if (!session.isRoot()) {
|
||||
FlowSession parent = session.getParent();
|
||||
if (isPersistenceContext(parent.getDefinition())) {
|
||||
|
||||
@@ -50,10 +50,10 @@ import org.springframework.webflow.execution.RequestContext;
|
||||
*
|
||||
* The general data access pattern implemented here is:
|
||||
* <ul>
|
||||
* <li> Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
|
||||
* <li> Load some objects into this persistence context
|
||||
* <li> Perform edits to those objects over a series of requests into the flow
|
||||
* <li> On successful conversation completion, commit and flush those edits to the database, applying a version check if
|
||||
* <li>Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
|
||||
* <li>Load some objects into this persistence context
|
||||
* <li>Perform edits to those objects over a series of requests into the flow
|
||||
* <li>On successful conversation completion, commit and flush those edits to the database, applying a version check if
|
||||
* necessary.
|
||||
* </ul>
|
||||
*
|
||||
@@ -120,9 +120,9 @@ public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
|
||||
public void sessionEnding(RequestContext context, FlowSession session, String outcome, MutableAttributeMap output) {
|
||||
if (isPersistenceContext(session.getDefinition())) {
|
||||
final EntityManager em = (EntityManager) session.getScope().remove(PERSISTENCE_CONTEXT_ATTRIBUTE);
|
||||
final EntityManager em = getEntityManager(session);
|
||||
Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
|
||||
if (Boolean.TRUE.equals(commitStatus)) {
|
||||
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||
@@ -134,6 +134,9 @@ public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter {
|
||||
unbind(em);
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
|
||||
if (!session.isRoot()) {
|
||||
FlowSession parent = session.getParent();
|
||||
if (isPersistenceContext(parent.getDefinition())) {
|
||||
|
||||
@@ -118,6 +118,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
endState.getAttributes().put("commit", Boolean.TRUE);
|
||||
flowSession.setState(endState);
|
||||
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertSessionNotBound();
|
||||
@@ -149,6 +150,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
endState.getAttributes().put("commit", Boolean.TRUE);
|
||||
flowSession.setState(endState);
|
||||
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertFalse(flowSession.getScope().contains("hibernate.session"));
|
||||
@@ -174,6 +176,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
|
||||
endState.getAttributes().put("commit", Boolean.FALSE);
|
||||
flowSession.setState(endState);
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "cancel", null);
|
||||
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertSessionNotBound();
|
||||
@@ -192,6 +195,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
|
||||
flowSession.setState(endState);
|
||||
|
||||
hibernateListener.sessionEnding(context, flowSession, "success", null);
|
||||
hibernateListener.sessionEnded(context, flowSession, "cancel", null);
|
||||
assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertFalse(flowSession.getScope().contains("hibernate.session"));
|
||||
|
||||
@@ -68,6 +68,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
endState.getAttributes().put("commit", Boolean.TRUE);
|
||||
flowSession.setState(endState);
|
||||
|
||||
jpaListener.sessionEnding(context, flowSession, "success", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertSessionNotBound();
|
||||
@@ -99,6 +100,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
endState.getAttributes().put("commit", Boolean.TRUE);
|
||||
flowSession.setState(endState);
|
||||
|
||||
jpaListener.sessionEnding(context, flowSession, "success", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertFalse(flowSession.getScope().contains("hibernate.session"));
|
||||
@@ -123,7 +125,8 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
|
||||
endState.getAttributes().put("commit", Boolean.FALSE);
|
||||
flowSession.setState(endState);
|
||||
jpaListener.sessionEnded(context, flowSession, "cancel", null);
|
||||
jpaListener.sessionEnding(context, flowSession, "cancel", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertSessionNotBound();
|
||||
assertFalse(flowSession.getScope().contains("hibernate.session"));
|
||||
@@ -141,7 +144,8 @@ public class JpaFlowExecutionListenerTests extends TestCase {
|
||||
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
|
||||
flowSession.setState(endState);
|
||||
|
||||
jpaListener.sessionEnded(context, flowSession, "cancel", null);
|
||||
jpaListener.sessionEnding(context, flowSession, "cancel", null);
|
||||
jpaListener.sessionEnded(context, flowSession, "success", null);
|
||||
assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
|
||||
assertFalse(flowSession.getScope().contains("hibernate.session"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user