Thank you very much for your explanation and code sample, Mr. Christian Köberl
I will try it.

On Sun, Dec 12, 2010 at 10:34 PM, Christian Köberl
<tapestry.christian.koeb...@gmail.com> wrote:
>
>
> Yohan Yudanara-2 wrote:
>>
>> So, in my conclusion (CMIIW), if I'm using JDBC instead of Hibernate,
>> I'd better stick with service/dao in spring bean. Because in spring
>> bean, I can use spring declarative transaction and also JdbcTemplate.
>> If I want to use tapestry service instead of spring bean, I need to
>> write code for accessing database (using JDBC) and managing
>> transaction from scratch.
>>
>
> No, that's not really true. You could use the advise out of my first post on
> this thread and apply that to all your Tapestry services accessing the
> database. You could do this by searching for an annotation - you can even
> use the Spring @Transacational annotation but it's probably better to have
> your own (since semantics won't be completely the same).
>
> Here's how the advisor could look like (see other post for
> TransactionalAdvise).
>
> public interface TransactionAdvisor
> {
>    void addTransactionAdvice(MethodAdviceReceiver receiver);
> }
>
> public class TransactionAdvisorImpl implements TransactionAdvisor
> {
>    private final PlatformTransactionManager manager; // this is the Spring
> transaction manager
>
>    private final Map<Propagation, MethodAdvice> transactionalAdvises;
>
>    public TransactionAdvisorImpl (PlatformTransactionManager manager)
>    {
>        this.manager = manager;
>
>        transactionalAdvises = new HashMap<Propagation, MethodAdvice>();
>        for (Propagation propagation : Propagation.values())
>        {
>                transactionalAdvises.put(propagation, new
> TransactionalAdvise(manager, propagation.value()));
>        }
>    }
>
>    public void addTransactionAdvice(MethodAdviceReceiver receiver)
>    {
>        for (Method m : receiver.getInterface().getMethods())
>        {
>            Transactional txAnnotation =
> m.getAnnotation(Transactional.class);
>
>            if (txAnnotation != null)
>            {
>                receiver.adviseMethod(m,
> transactionalAdvises.get(txAnnotation.propagation()));
>            }
>        }
>    }
> }
>
> In your module you have to bind the services and advise your DAOs:
>   �...@match("*DAO")
>    public static void adviseTransactions(TransactionAdvisor advisor,
> MethodAdviceReceiver receiver)
>    {
>        advisor.addTransactionAdvice(receiver);
>    }
>
> This advice method is configured to match against any service whose id ends
> with "DAO", such as "PersonDAO".
> --
> View this message in context: 
> http://tapestry-users.832.n2.nabble.com/T5-2-Need-Advice-on-JDBC-and-Transaction-Mgmt-tp5825768p5828294.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to