public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter
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:
PERSISTENCE_CONTEXT_ATTRIBUTE
.
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PERSISTENCE_CONTEXT_ATTRIBUTE
The name of the attribute the flow
persistence context is indexed under. |
Constructor and Description |
---|
JpaFlowExecutionListener(javax.persistence.EntityManagerFactory entityManagerFactory,
org.springframework.transaction.PlatformTransactionManager transactionManager)
Create a new JPA flow execution listener using given JPA Entity Manager factory.
|
Modifier and Type | Method and Description |
---|---|
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.
|
eventSignaled, requestProcessed, requestSubmitted, sessionCreating, sessionStarted, stateEntered, stateEntering, transitionExecuting, viewRendered, viewRendering
public static final java.lang.String PERSISTENCE_CONTEXT_ATTRIBUTE
persistence context
is indexed under.public JpaFlowExecutionListener(javax.persistence.EntityManagerFactory entityManagerFactory, org.springframework.transaction.PlatformTransactionManager transactionManager)
entityManagerFactory
- the entity manager factory to usepublic void sessionStarting(RequestContext context, FlowSession session, MutableAttributeMap input)
FlowExecutionListener
sessionStarting
in interface FlowExecutionListener
sessionStarting
in class FlowExecutionListenerAdapter
context
- the current flow request contextsession
- the session that was createdinput
- a mutable input map - attributes placed in this map are eligible for input mapping by the flow
definition at startuppublic void paused(RequestContext context)
FlowExecutionListener
paused
in interface FlowExecutionListener
paused
in class FlowExecutionListenerAdapter
context
- the current flow request contextpublic void resuming(RequestContext context)
FlowExecutionListener
resuming
in interface FlowExecutionListener
resuming
in class FlowExecutionListenerAdapter
context
- the current flow request contextpublic void sessionEnding(RequestContext context, FlowSession session, java.lang.String outcome, MutableAttributeMap output)
FlowExecutionListener
sessionEnding
in interface FlowExecutionListener
sessionEnding
in class FlowExecutionListenerAdapter
context
- the current flow request contextsession
- the current active session that is endingoutcome
- the outcome reached by the ending session, generally the id of the terminating end-stateoutput
- the flow output produced by the ending session, this map may be modified by this listener to affect
the output returnedpublic void sessionEnded(RequestContext context, FlowSession session, java.lang.String outcome, AttributeMap output)
FlowExecutionListener
sessionEnded
in interface FlowExecutionListener
sessionEnded
in class FlowExecutionListenerAdapter
context
- the current flow request contextsession
- ending flow sessionoutcome
- the outcome reached by the ended session, generally the id of the terminating end-stateoutput
- the flow output returned by the ending sessionpublic void exceptionThrown(RequestContext context, FlowExecutionException exception)
FlowExecutionListener
handler
.exceptionThrown
in interface FlowExecutionListener
exceptionThrown
in class FlowExecutionListenerAdapter
context
- the current flow request contextexception
- the exception that occurred