Announcement Announcement Module
No announcement yet.
transactionAttributes if single entry method Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • transactionAttributes if single entry method

    All the services of my business tier have the same signature:

    public class myFacade extends BusinessFacade {
      public void myService1(BusinessRequest req, BusinessReponse resp) throws BusinessException;
      public void myService2(BusinessRequest req, BusinessReponse resp) throws BusinessException;
    In the abstract ancestor of business facades, I have defined a single entry method which is a dispatcher to the appropriate service (ie "myServiceX) :

    public abstract class BusinessFacade {
      public void invokeService(BusinessRequest req, BusinessReponse resp) throws BusinessException {
      // invoke in concrete class the method named <req.getRequestedService&#40;&#41;> - eg "myService1"
    Now, I would like to define the transaction attributes of every concrete service (myService1, myService2) :

    <bean id="..." class="...TransactionProxyFactoryBean">
    <property name="transactionAttributes">
        <prop key="invokeService">PROPAGATION_REQUIRED</prop>
        <prop key="myService1">PROPAGATION_REQUIRED</prop>
        <prop key="myService2">PROPAGATION_REQUIRED,readOnly</prop>
    But as the generic method invokeService() is supposed to be THE - only - "normal" way of calling business service (although you could invoke directly myService1), it is always that front method that is first called on the TransactionProxy. Therefore I cannot reasonnably set it to "ReadOnly". The subsequent call/forward to the wanted service (myService1) is done on the concrete facade - no more on the proxy , making so unnecessary my settings for myService1 & myService2...

    How could I ensure a read-only transaction for myService2 knowing that myService2 is actually a (so to say) nested service of the non read-only primary invokeService service ?

    Thanks in advance,


  • #2
    It would tie your ancestor class slightly to Spring, but in your ancestor class you could have a method:

    Object getThis() {
    return AopContext.currentProxy();

    and use this to get the current proxy for the class you are in, and dispatch through that. Note that you have to set your transaction proxies (via the related property) to expose the current proxy as a threadlocal.