public abstract class TopiaTransactionFilter extends Object implements javax.servlet.Filter
TopiaContext and deal with the complete lifecycle of a topia
transaction while a request.
The injected transaction will be closed (if was really opened) at the end of
the request.
excludeMethods: This parameters configure a set of method names
which should never be called on the proxied transaction.
When a such method is called on the transaction then the filter will pass in
the hook onExcludeMethod(Object, Method, Object[]).
Default implementation of this hook is to throw an exception.
unusedMethods: This parameters configure a set of method names
which should be by-pass when the proxied transaction was not still open (via a TopiaContext.beginTransaction().
When a such method is called on the transaction then the filter will pass in
the hook onUnusedMethod(Object, Method, Object[]).
Default implementation of this hook is to not return null values.
requestAttributeName
(default value is TOPIA_TRANSACTION_REQUEST_ATTRIBUTE) and can be
changed.
A convience method is created here to obtain the transaction getTransaction(ServletRequest) :
TopiaContext tx = TopiaTransactionFilter.getTransaction(ServletRequest);If you prefer to not use this nice method, you can also do this:
TopiaContext tx = (TopiaContext) request.getAttribute(TopiaTransactionFilter#TOPIA_TRANSACTION_REQUEST_ATTRIBUTE);Or
TopiaContext tx = (TopiaContext) request.getAttribute(modifiedAttributeName);
| Modifier and Type | Class and Description |
|---|---|
class |
TopiaTransactionFilter.TopiaTransactionProxyInvocationHandler
Handler of a proxy on a
TopiaContext. |
| Modifier and Type | Field and Description |
|---|---|
static String[] |
DEFAULT_EXCLUDE_METHODS |
static String[] |
DEFAULT_UNUSED_METHODS |
protected Set<String> |
excludeMethods
names of methods to forbid access while using proxy.
|
protected String |
requestAttributeName
Name of the request attribute where to push the transaction.
|
static String |
TOPIA_TRANSACTION_REQUEST_ATTRIBUTE |
protected Set<String> |
unusedMethods
names of methods to by-pass if no transaction opened on proxy.
|
| Constructor and Description |
|---|
TopiaTransactionFilter() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract org.nuiton.topia.TopiaContext |
beginTransaction(javax.servlet.ServletRequest request)
Method to open a new transaction.
|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain) |
Set<String> |
getExcludeMethods() |
static org.nuiton.topia.TopiaContext |
getTransaction(javax.servlet.ServletRequest request) |
Set<String> |
getUnusedMethods() |
void |
init(javax.servlet.FilterConfig filterConfig) |
protected void |
onCloseTransaction(org.nuiton.topia.TopiaContext transaction)
Hook method to close the topia transaction of the request at the end of
the request when all filter has been consumed.
|
protected Object |
onExcludeMethod(Object proxy,
Method method,
Object[] args)
Hook method called when a method with his name in
excludeMethods was invoked on the proxied transaction. |
protected Object |
onUnusedMethod(Object proxy,
Method method,
Object[] args)
Hook method called when a method with his name in
unusedMethods was invoked on the proxied transaction
while the underlying transaction is still not opened. |
void |
setRequestAttributeName(String requestAttributeName)
to change the
requestAttributeName. |
public static final String TOPIA_TRANSACTION_REQUEST_ATTRIBUTE
public static final String[] DEFAULT_EXCLUDE_METHODS
public static final String[] DEFAULT_UNUSED_METHODS
protected Set<String> excludeMethods
protected Set<String> unusedMethods
protected String requestAttributeName
TOPIA_TRANSACTION_REQUEST_ATTRIBUTE.public void setRequestAttributeName(String requestAttributeName)
requestAttributeName.requestAttributeName - new name of the request attribute
where to push the transaction.public static org.nuiton.topia.TopiaContext getTransaction(javax.servlet.ServletRequest request)
protected abstract org.nuiton.topia.TopiaContext beginTransaction(javax.servlet.ServletRequest request)
throws org.nuiton.topia.TopiaRuntimeException
request - incoming requestorg.nuiton.topia.TopiaRuntimeException - if any problem while opening a new transactionpublic void destroy()
destroy in interface javax.servlet.Filterpublic void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
init in interface javax.servlet.Filterjavax.servlet.ServletExceptionpublic void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.FilterIOExceptionjavax.servlet.ServletExceptionprotected Object onExcludeMethod(Object proxy, Method method, Object[] args) throws Throwable
excludeMethods was invoked on the proxied transaction.proxy - proxied transactionmethod - method invokedargs - arguments of the invoked methodThrowable - if any error to do.protected void onCloseTransaction(org.nuiton.topia.TopiaContext transaction)
transaction - the transaction to close (can be null if transaction
was not required while the current request)protected Object onUnusedMethod(Object proxy, Method method, Object[] args) throws Throwable
unusedMethods was invoked on the proxied transaction
while the underlying transaction is still not opened.proxy - the proxy itselfmethod - method invokedargs - arguments of the invoked methodThrowable - if any error to do.Copyright © 2011-2013 CodeLutin. All Rights Reserved.