-----Mensagem original-----
De: Alex Karasulu [mailto:[EMAIL PROTECTED]
Enviada em: segunda-feira, 16 de fevereiro de 2004 16:35
> More on the idea
> =================
>
> For example consider implementing transactions. A service interceptor
> (might be same interceptor) in the before chain starts a transaction. The
> after interceptor commits it. And the exceptional (on failure) chain's
> interceptor for the txn service does a rollback. You can do many things
> here but 3 separate chains makes it complete and capable of handling every
> kind of construct Java can throw at you. Essentially the triad of
> interceptor chains are designed around the nature of Java and exception
> handling this way.
I think pipelines are great, but I disagree with your example. Transaction
handling depends on strategies like:
- Requires
- Requires New
- Supports
- Not Support
- Never
Each one should know how to begin/rollback/commit based on its type. Also,
nested transactions should be considered. Then break down transaction
handling in different pipelines sounds bad to me.
Right now I have some code that handles a 'Requires Transaction' mode:
public Object invoke(Object target, MethodMetadata metadata, Method
method, Object[] args)
throws Throwable
{
boolean weAreTransactionRoot = false;
Current cur = Current.getCurrent();
if (cur.getTransaction() == null)
{
weAreTransactionRoot = true;
cur.begin();
}
Object ret = null;
try
{
ret = method.invoke(target, args); // Real method invocation
}
catch(Exception e)
{
// Failed
if (weAreTransactionRoot)
{
cur.rollback();
}
throw e;
}
// Succeeded
if (weAreTransactionRoot)
{
cur.commit();
}
return ret;
}
Hence, an execution pipeline that fits my needs would need a reference to
the next entry in the chain:
try
{
ret = nextInChain.invoke(target, args); // Delegation to the
next one
}
catch(Exception e)
{
...
The last one in the calling chain should be the one that would really invoke
the method.
How do you like that? :-)
regards,
hammett
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]