Search in sources :

Example 1 with DataSource

use of com.ikoori.vip.common.annotion.DataSource in project vip by guangdada.

the class TestServiceImpl method testGuns.

@Override
@DataSource(name = DSEnum.DATA_SOURCE_GUNS)
public void testGuns() {
    Test test = testMapper.selectById(1);
    test.setId(33);
    test.insert();
}
Also used : Test(com.ikoori.vip.common.persistence.model.Test) DataSource(com.ikoori.vip.common.annotion.DataSource)

Example 2 with DataSource

use of com.ikoori.vip.common.annotion.DataSource in project vip by guangdada.

the class TestServiceImpl method testBiz.

@Override
@DataSource(name = DSEnum.DATA_SOURCE_BIZ)
public void testBiz() {
    Test test = testMapper.selectById(1);
    test.setId(22);
    test.insert();
}
Also used : Test(com.ikoori.vip.common.persistence.model.Test) DataSource(com.ikoori.vip.common.annotion.DataSource)

Example 3 with DataSource

use of com.ikoori.vip.common.annotion.DataSource in project vip by guangdada.

the class MultiSourceExAop method around.

@Around("cut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
    Signature signature = point.getSignature();
    MethodSignature methodSignature = null;
    if (!(signature instanceof MethodSignature)) {
        throw new IllegalArgumentException("该注解只能用于方法");
    }
    methodSignature = (MethodSignature) signature;
    Object target = point.getTarget();
    Method currentMethod = target.getClass().getMethod(methodSignature.getName(), methodSignature.getParameterTypes());
    DataSource datasource = currentMethod.getAnnotation(DataSource.class);
    if (datasource != null) {
        DataSourceContextHolder.setDataSourceType(datasource.name());
        log.debug("设置数据源为:" + datasource.name());
    } else {
        DataSourceContextHolder.setDataSourceType(DSEnum.DATA_SOURCE_GUNS);
        log.debug("设置数据源为:dataSourceCurrent");
    }
    try {
        return point.proceed();
    } finally {
        log.debug("清空数据源信息!");
        DataSourceContextHolder.clearDataSourceType();
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Signature(org.aspectj.lang.Signature) MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) DataSource(com.ikoori.vip.common.annotion.DataSource) Around(org.aspectj.lang.annotation.Around)

Aggregations

DataSource (com.ikoori.vip.common.annotion.DataSource)3 Test (com.ikoori.vip.common.persistence.model.Test)2 Method (java.lang.reflect.Method)1 Signature (org.aspectj.lang.Signature)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1