• 读写切换切面


    #taskUser读
    taskuser.read=0
    #taskUser写
    taskuser.write=1
    #taskUserData读
    taskuserdata.read=1
    #taskUserData写
    taskuserdata.write=1
    @Aspect
    @Component
    public class TaskUserDaoMapperAspect {
        private static final Logger logger = LoggerFactory.getLogger(TaskUserDaoMapperAspect.class);
        private static final List<String> readList = Lists.newArrayList("find", "poll");
        private static final List<String> writeList = Lists.newArrayList("insert", "update");
    
        @Resource
        private TaskUserDataMapper taskUserDataMapper;
    
        @Resource
        private ConfigService configService;
    
        @Around("execution(* cn.hello.dal.mapper.TaskUserMapper.*(..))")
        public Object around(ProceedingJoinPoint pjp) {
            Object result = null;
            try {
                String methodName = pjp.getSignature().getName();
                logger.info("TaskUserMapper {} {} invoked", methodName, pjp.getArgs());
                if(readList.contains(methodName)){
                    if(configService.isReadTaskUser()){
                        result = pjp.proceed();
                    } else if(configService.isReadTaskUserData()){
                        result = invokeTaskUserDaoMapper(pjp);
                    }
                } else if(writeList.contains(methodName)){
    
                    if(configService.isWriteTaskUser()){
                        result = pjp.proceed();
                    }
                    if(configService.isWriteTaskUserData()){
                        result = invokeTaskUserDaoMapper(pjp);
                    }
                } else {
                    logger.error("unknown TaskUserMapper method {}", methodName);
                    result = pjp.proceed();
                }
            } catch (OctopusException e) {
                throw e;
            } catch (Throwable e) {
                logger.error("failed@AroundDaoAspect.around", e);
                throw new DalException("DAL ERROR", e);
            }
            return result;
        }
    
        private Object invokeTaskUserDaoMapper(ProceedingJoinPoint pjp) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            String methodName = pjp.getSignature().getName();
            Class[] parameterTypes = ((MethodSignature)pjp.getSignature()).getMethod().getParameterTypes();
            Method method = TaskUserDataMapper.class.getMethod(methodName, parameterTypes);
            Object result = method.invoke(taskUserDataMapper, pjp.getArgs());
            return result;
        }
    }
  • 相关阅读:
    echarts属性杂记
    vue工作问题小计
    vue 表单数据修改,导致页面列表数据被同步修改问题的解决。
    利用syslog记录日志的简单日志函数
    1 概述
    PowerDesigner 如何自定义Data Type
    Mybatisplus读取(GeoJson)和保存Postgis geography数据
    【Mybatis】model类通过注解忽略某属性
    如何利用PostGIS正确计算距离和面积
    Linux上编写监控jar包重启脚本
  • 原文地址:https://www.cnblogs.com/exmyth/p/10811474.html
Copyright © 2020-2023  润新知