|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.spicefactory.pimento.context.AbstractPersistenceContextPhaseListener
public abstract class AbstractPersistenceContextPhaseListener
Base implementation of Cinnamon's PhaseListener extension point that wraps the service invocations in a transaction. It will be used during processing of entity snapshots sent from the client which might need to be merged onto the full entities before the actual service operation will be invoked. This transaction will remain active for the processing of all messages for a single request. It will remain active for processing any return value which is a persistent entity to avoid lazy initialization exceptions.
It is recommended to use some kind of lazy DataSource to avoid fetching Connections from the
pool unless actually necessary. Since this
PhaseListener will wrap all service invocations it would otherwise also affect invocations
that are either not transactional or that do not hit the database because all entities could be fetched
from the second level cache.
This base implementation must be extended and the five abstract methods that deal directly with transaction management and EntityManager creation must be implemented. They are left abstract in this base class because in most deployment scenarios it would be the best approach to hook into the transaction support of the application framework or server in use.
Pimento comes with a default implementation that uses Spring for transaction management. But this base class does not depend on Spring and should be easy to extend for other application frameworks.
| Constructor Summary | |
|---|---|
AbstractPersistenceContextPhaseListener(EntityManagerFactory emf)
Creates a new instance. |
|
| Method Summary | |
|---|---|
void |
afterDecodingException(Exception ex)
Invoked if decoding of the incoming AMF request failed. |
void |
afterEncoding()
Invoked after encoding of the response has been completed. |
void |
afterProcessing(Envelope request,
Envelope response)
Invoked after processing of messages has been completed but before encoding of the response has started. |
void |
beforeDecoding()
Invoked before decoding of the incoming AMF request starts. |
void |
beforeProcessing(Envelope request)
Invoked after decoding of the request has been completed but before processing the decoded messages. |
protected abstract boolean |
bindEntityManager()
Bind an EntityManager to the current thread. |
protected abstract void |
commitTransaction(Object transactionContext)
Commits the transaction represented by the specified parameter. |
protected boolean |
containsError(Envelope response)
Checks whether the specified Cinnamon response envelope contains any service invocations that led to an error result. |
protected RequestContext |
createRequestContext()
Creates and returns a new RequestContext instance. |
protected abstract Object |
createTransaction()
Creates a transaction and returns a transaction status object. |
protected EntityManagerFactory |
getEntityManagerFactory()
Returns the EntityManagerFactory that this phase listener uses. |
protected void |
releaseRequestContext()
Unbinds the RequestContext from the current thread. |
protected abstract void |
rollbackTransaction(Object transactionContext)
Performs a rollback for the transaction represented by the specified parameter. |
protected abstract void |
unbindEntityManager()
Unbind the EntityManager from the current thread. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AbstractPersistenceContextPhaseListener(EntityManagerFactory emf)
emf - the EntityManagerFactory to use| Method Detail |
|---|
protected EntityManagerFactory getEntityManagerFactory()
public void beforeDecoding()
PhaseListener
beforeDecoding in interface PhaseListenerpublic void afterDecodingException(Exception ex)
PhaseListener
afterDecodingException in interface PhaseListenerex - the Exception that was caught while decoding the requestpublic void beforeProcessing(Envelope request)
PhaseListener
beforeProcessing in interface PhaseListenerrequest - the Envelope containing all messages that will be processed
public void afterProcessing(Envelope request,
Envelope response)
PhaseListener
afterProcessing in interface PhaseListenerrequest - the Envelope containing all request messages that have been processedresponse - the Envelope containing all response messages that will be sent to the clientpublic void afterEncoding()
PhaseListener
afterEncoding in interface PhaseListenerprotected boolean containsError(Envelope response)
response - the Cinnamon envelope to check
protected abstract Object createTransaction()
protected abstract void commitTransaction(Object transactionContext)
createTransaction.
transactionContext - the status object for the transaction to commitprotected abstract void rollbackTransaction(Object transactionContext)
createTransaction.
transactionContext - the status object for the transaction to rollbackprotected abstract boolean bindEntityManager()
protected abstract void unbindEntityManager()
protected RequestContext createRequestContext()
protected void releaseRequestContext()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||