Announcement Announcement Module
Collapse
No announcement yet.
Pointcut for nested transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pointcut for nested transaction

    Code:
    <bean id="svcForAOP" class="poc.ServiceForAOP" />
    
    <aop:config>
    	<aop:aspect ref="svcForAOP">
    		<aop:pointcut
    			id="svc1"
    			expression="execution(* poc.IService.*(..))" />
    		<aop:after
    			method="myMethod"
    			pointcut-ref="svc1"/>
    	</aop:aspect>
    </aop:config>
    
        <aop:config>
            <aop:pointcut
                id="svcTxn1"
                expression="execution(* poc.ServiceForAOP.*(..))"       
            />
            <aop:advisor
                pointcut-ref="svcTxn1"
                advice-ref="txAdvice"
            />
        </aop:config>
    
        <aop:config>
            <aop:pointcut
                id="svcTxn2"
                expression="execution(* poc.IService.*(..))"       
            />
            <aop:advisor
                pointcut-ref="svcTxn2"
                advice-ref="txAdvice"
            />
        </aop:config>
    
        <tx:advice id="txAdvice" >
            <tx:attributes>
              <tx:method
                    name="*"
                    read-only="true"
                    propagation="REQUIRED"
                    isolation="READ_COMMITTED"
                    timeout="5"
               />
            </tx:attributes>
        </tx:advice>
    Transaction gets started by calling a method on IService. That method of iService in turn calls poc.ServiceForAOP.myMethod() because of after-returning.

    I cannot make poc.ServiceForAOP.myMethod a part of the same transaction even if I use around, after or any other pointcut.

    My goal is to move some boiler plate transaction code to poc.ServiceForAOP.myMethod(). poc.ServiceForAOP.myMethod() should be able to check transaction status and do bioler plate code. In that way, all the implementation classes if IService do not have to write the bioler plate code.

    Is it possible to interrogate the same transation status (which is new) for a method call on IAocService inside of poc.ServiceForAOP.myMethod() ? In other words, can I get the same new status inside poc.ServiceForAOP.myMethod(), when a method call is made on IAocService? There is no need for poc.ServiceForAOP.myMethod() to be a part of transaction. I need to poc.ServiceForAOP.myMethod() this method (by aop after around or whatever) and need to get status new for transaction inside of poc.ServiceForAOP.myMethod().

  • #2
    Execute advise after 1st line and before last line of a method

    My question is:
    What should be the aop type, if I want to execute advise method after executing the 1st line and before executing the last line of IService method?

    Following is the scenario:
    I want poc.ServiceForAOP.advisingMethod() to be executed AFTER the first line of IService method and BEFORE the last line of IService method. poc.ServiceForAOP.advisingMethod() does not need to be a part of transaction. Only the method in IService has to be a part of transaction.

    I tried using around. It did not execute any line in IService method. It only executed the lines of code in poc.ServiceForAOP.advisingMethod()

    Using after and after-returning executes poc.ServiceForAOP.advisingMethod()AFTER fully finishing the lines of code of IService method.

    Using before executes poc.ServiceForAOP.myMethod() BEFORE entering the code of IService method.

    Can I use around to execute poc.ServiceForAOP.advisingMethod() so that the lines of code in advisingMethod() get executed after the first few lines of IService method and before returning from the code of IService method?

    Code:
    <bean id="svcForAOP" class="poc.ServiceForAOP" />
    
    <aop:config>
    	<aop:aspect ref="svcForAOP">
    		<aop:pointcut
    			id="svc1"
    			expression="execution(* poc.IService.*(..))" />
    		<aop:WHAT KIND OF AOP?
    			method="advisingMethod()"
    			pointcut-ref="svc1"/>
    	</aop:aspect>
    </aop:config>
    
        <aop:config>
            <aop:pointcut
                id="svcTxn"
                expression="execution(* poc.IService.*(..))"       
            />
            <aop:advisor
                pointcut-ref="svcTxn"
                advice-ref="txAdvice"
            />
        </aop:config>
    
        <tx:advice id="txAdvice" >
            <tx:attributes>
              <tx:method
                    name="*"
                    read-only="true"
                    propagation="REQUIRED"
                    isolation="READ_COMMITTED"
                    timeout="5"
               />
            </tx:attributes>
        </tx:advice>

    Following the is code in the method of of a class that Implements IService.
    Code:
        public List methodImplementationOfIService() {
         // Want to execute first, or the first few lines of code of this method body
    
         // want to invoke advice method poc.ServiceForAOP.advisingMethod() 
    
        // Want to continue with the remaining lines of this method body
    
        }
    Just putting aop-around in XML config does not execute any line from the method body of methodImplementationOfIService(). It executes the lines of code of poc.ServiceForAOP.advisingMethod()

    poc.ServiceForAOP.advisingMethod() did not have ProceedingJoinPoint as argument. I have also added ProceedingJoinPoint as an argument as show below. But no luck either.

    Code:
    public void advisingMethod()(ProceedingJoinPoint joinPoint){
    		System.out.println("Inside ServiceForAOP");
    		try {
    			joinPoint.proceed();
    		} catch (Throwable e) {
    			e.printStackTrace();
    		}
    	}

    Comment

    Working...
    X