Spring Web Flow

org.springframework.webflow.persistence
Class JpaFlowExecutionListener

java.lang.Object
  extended by org.springframework.webflow.execution.FlowExecutionListenerAdapter
      extended by org.springframework.webflow.persistence.JpaFlowExecutionListener
All Implemented Interfaces:
FlowExecutionListener

public class JpaFlowExecutionListener
extends FlowExecutionListenerAdapter

A FlowExecutionListener that implements the Flow Managed Persistence Context (FMPC) pattern using the standard Java Persistence API (JPA).

This implementation uses standard JPA APIs. The general pattern is as follows:

The general data access pattern implemented here is:

Note: All data access except for the final commit will, by default, be non-transactional. However, a flow may call into a transactional service layer to fetch objects during the conversation in the context of a read-only system transaction if the underlying JPA Transaction Manager supports this. Spring's JPA TransactionManager does support this when working with a Hibernate JPA provider, for example. In that case, Spring will handle setting the FlushMode to MANUAL to ensure any in-progress changes to managed persistent entities are not flushed, while reads of new objects occur transactionally.

Care should be taken to prevent premature commits of flow data while the flow is in progress. You would generally not want intermediate flushing to happen, as the nature of a flow implies a transient, isolated resource that can be canceled before it ends. Generally, the only time a read-write transaction should be started is upon successful completion of the flow, triggered by reaching a 'commit' end state.

Author:
Keith Donald, Juergen Hoeller

Field Summary
static java.lang.String PERSISTENCE_CONTEXT_ATTRIBUTE
          The name of the attribute the flow persistence context is indexed under.
 
Constructor Summary
JpaFlowExecutionListener(javax.persistence.EntityManagerFactory entityManagerFactory, org.springframework.transaction.PlatformTransactionManager transactionManager)
          Create a new JPA flow execution listener using given JPA Entity Manager factory.
 
Method Summary
 void exceptionThrown(RequestContext context, FlowExecutionException exception)
          Called when an exception is thrown during a flow execution, before the exception is handled by any registered handler.
 void paused(RequestContext context)
          Called when a flow execution is paused, for instance when it is waiting for user input (after event processing).
 void resuming(RequestContext context)
          Called after a flow execution is successfully reactivated after pause (but before event processing).
 void sessionEnded(RequestContext context, FlowSession session, java.lang.String outcome, AttributeMap<?> output)
          Called when a flow execution session ends.
 void sessionEnding(RequestContext context, FlowSession session, java.lang.String outcome, MutableAttributeMap<?> output)
          Called when the active flow execution session has been asked to end but before it has ended.
 void sessionStarting(RequestContext context, FlowSession session, MutableAttributeMap<?> input)
          Called after a new flow session has been created but before it starts.
 
Methods inherited from class org.springframework.webflow.execution.FlowExecutionListenerAdapter
eventSignaled, requestProcessed, requestSubmitted, sessionCreating, sessionStarted, stateEntered, stateEntering, transitionExecuting, viewRendered, viewRendering
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERSISTENCE_CONTEXT_ATTRIBUTE

public static final java.lang.String PERSISTENCE_CONTEXT_ATTRIBUTE
The name of the attribute the flow persistence context is indexed under.

See Also:
Constant Field Values
Constructor Detail

JpaFlowExecutionListener

public JpaFlowExecutionListener(javax.persistence.EntityManagerFactory entityManagerFactory,
                                org.springframework.transaction.PlatformTransactionManager transactionManager)
Create a new JPA flow execution listener using given JPA Entity Manager factory.

Parameters:
entityManagerFactory - the entity manager factory to use
Method Detail

sessionStarting

public void sessionStarting(RequestContext context,
                            FlowSession session,
                            MutableAttributeMap<?> input)
Description copied from interface: FlowExecutionListener
Called after a new flow session has been created but before it starts. Useful for setting arbitrary attributes in the session before the flow starts.

Specified by:
sessionStarting in interface FlowExecutionListener
Overrides:
sessionStarting in class FlowExecutionListenerAdapter
Parameters:
context - the current flow request context
session - the session that was created
input - a mutable input map - attributes placed in this map are eligible for input mapping by the flow definition at startup

paused

public void paused(RequestContext context)
Description copied from interface: FlowExecutionListener
Called when a flow execution is paused, for instance when it is waiting for user input (after event processing).

Specified by:
paused in interface FlowExecutionListener
Overrides:
paused in class FlowExecutionListenerAdapter
Parameters:
context - the current flow request context

resuming

public void resuming(RequestContext context)
Description copied from interface: FlowExecutionListener
Called after a flow execution is successfully reactivated after pause (but before event processing).

Specified by:
resuming in interface FlowExecutionListener
Overrides:
resuming in class FlowExecutionListenerAdapter
Parameters:
context - the current flow request context

sessionEnding

public void sessionEnding(RequestContext context,
                          FlowSession session,
                          java.lang.String outcome,
                          MutableAttributeMap<?> output)
Description copied from interface: FlowExecutionListener
Called when the active flow execution session has been asked to end but before it has ended.

Specified by:
sessionEnding in interface FlowExecutionListener
Overrides:
sessionEnding in class FlowExecutionListenerAdapter
Parameters:
context - the current flow request context
session - the current active session that is ending
outcome - the outcome reached by the ending session, generally the id of the terminating end-state
output - the flow output produced by the ending session, this map may be modified by this listener to affect the output returned

sessionEnded

public void sessionEnded(RequestContext context,
                         FlowSession session,
                         java.lang.String outcome,
                         AttributeMap<?> output)
Description copied from interface: FlowExecutionListener
Called when a flow execution session ends. If the ended session was the root session of the flow execution, the entire flow execution also ends.

Specified by:
sessionEnded in interface FlowExecutionListener
Overrides:
sessionEnded in class FlowExecutionListenerAdapter
Parameters:
context - the current flow request context
session - ending flow session
outcome - the outcome reached by the ended session, generally the id of the terminating end-state
output - the flow output returned by the ending session

exceptionThrown

public void exceptionThrown(RequestContext context,
                            FlowExecutionException exception)
Description copied from interface: FlowExecutionListener
Called when an exception is thrown during a flow execution, before the exception is handled by any registered handler.

Specified by:
exceptionThrown in interface FlowExecutionListener
Overrides:
exceptionThrown in class FlowExecutionListenerAdapter
Parameters:
context - the current flow request context
exception - the exception that occurred

Spring Web Flow