I would like to create annotation based interceptor which will log the current DB details wherever primary db is failing to server the request and secondary db will start to give support for the application.
I found below code from mentioned link but I could not find the specific orcl annotation which has to be used for the annotation like @Aspect for aop in the below , Please help to find this.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:orcl="http://www.springframework.org/schema/data/orcl"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/data/orcl
http://www.springframework.org/schema/data/orcl/spring-data-orcl-1.0.xsd">
<aop:config>
<aop:advisor pointcut="execution(* *..PetStoreFacade.insertOrder(..))" 1
advice-ref="racFailoverInterceptor" order="1"/>
<aop:advisor pointcut="execution(* *..PetStoreFacade.*(..))" 2
advice-ref="txAdvice"/>
</aop:config>
<orcl:rac-failover-interceptor id="racFailoverInterceptor"/> 3
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="insert*"/>
<tx:method name="update*"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
</beans>
Basically, there is no out of the box "Oracle" annotation which can be used to make rac failover interceptor work. But it is easy to add new custom annotation which will do the work for you.
Provided that the sprig data oracle is at your classpath
Maven pom.xml
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-oracle</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
Just create an marker annotation which you want to use.
package org.example;
public @interface OracleFailover {
// just a marker annotation, no body
}
Configure an advisor for it
<aop:config>
<aop:advisor
pointcut="@annotation(org.example.OracleFailover)"
advice-ref="racFailoverInterceptor" order="1"/>
</aop:config>
<orcl:rac-failover-interceptor id="racFailoverInterceptor"/>
And then use it on your business methods
package org.example;
@Service
public class SomeBusinessService {
@OracleFailover
void doSomethingWithOracle(){
// body goes here
}
}
And remember that the Rac Failover Interceptor should go before your transnational interceptor, that is failover will not work as expected in case failover interception is done when the transaction is already active.