java - Multiple transaction managers with @Transactional annotation -


  1. we have base generic manager inherited managers. base manager annotated @transactional annotations.

  2. there 2 groups of transactional services:

    • x.y.service1.* - have managed transactionmanager1
    • x.y.service2.* - have managed transactionmanager2

how can transactions configured without nessesity override transactional methods , specify transaction manager?

@transactional(readonly = true) public abstract class genericmanagerimpl<d extends igenericdao, t extends baseobject, pk extends serializable>         implements igenericmanager<t, pk> {      protected d dao;      @autowired     public void setdao(d dao) {         this.dao = dao;     }       @transactional(readonly = false)     public void save(t object) {         dao.save(object);     }      @transactional(readonly = false)     public void remove(t object) {         dao.remove(object);     }   } 

@service class usermanagerimpl         extends genericmanagerimpl<iuserdao, user, long>         implements iusermanager {  // ok. user managed txmanager1  } 

@service class billingmanagerimpl         extends genericmanagerimpl<ibillingdao, billing, long>         implements ibillingmanager {      @override     @transactional(readonly = false, value="txmanager2") // <--have override method specify txmanager     public void save(final billing billing ) {         super.save(billing);     }      @override     @transactional(readonly = false, value="txmanager2") // <--have override method specify txmanager     public void remove(final billing billing ) {         super.remove(billing);     } } 

most need combine aop @transactional annotation.
actually, want is:
1) able configure transactions (read flag, propogation, isolation etc) @transactional annotation.
2) define strategy choose transaction manager outside of classes (using aop, example)
x.y.service1.* -> use txmanager1
x.y.service2.* -> use txmanager2

is possible?

there possibility create own annotations shortcuts @transactional(value="tx1"). (these can used @ class or method level)

from reference documentation:

for example, defining following annotations

@target({elementtype.method, elementtype.type}) @retention(retentionpolicy.runtime) @transactional("order") public @interface ordertx { }  @target({elementtype.method, elementtype.type}) @retention(retentionpolicy.runtime) @transactional("account") public @interface accounttx { }   

allows write example previous section as

public class transactionalservice {      @ordertx     public void setsomething(string name) { ... }      @accounttx     public void dosomething() { ... }   } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -