Search in sources :

Example 1 with RwRouteHandler

use of com.mendmix.mybatis.plugin.rwseparate.RwRouteHandler in project jeesuite-libs by vakinge.

the class JeesuiteMybatisInterceptor method setInterceptorHandlers.

private void setInterceptorHandlers(String[] hanlderNames) {
    for (String name : hanlderNames) {
        if (org.apache.commons.lang3.StringUtils.isBlank(name))
            continue;
        if (CacheHandler.NAME.equals(name)) {
            this.interceptorHandlers.add(new CacheHandler());
            cacheEnabled = true;
        } else if (RwRouteHandler.NAME.equals(name)) {
            this.interceptorHandlers.add(new RwRouteHandler());
            rwRouteEnabled = true;
        } else {
            // 自定义的拦截器
            try {
                Class<?> clazz = Class.forName(name);
                InterceptorHandler handler = (InterceptorHandler) clazz.newInstance();
                this.interceptorHandlers.add(handler);
                logger.info("registered cumstom InterceptorHandler:{}", name);
            } catch (Exception e) {
                logger.error("registered cumstom InterceptorHandler error", e);
            }
        }
    }
    // 排序 分页和数据权限会重写sql,所以不走缓存,所以放在缓存之前
    Collections.sort(this.interceptorHandlers, new Comparator<InterceptorHandler>() {

        @Override
        public int compare(InterceptorHandler o1, InterceptorHandler o2) {
            return Integer.compare(o1.interceptorOrder(), o2.interceptorOrder());
        }
    });
}
Also used : InterceptorHandler(com.mendmix.mybatis.core.InterceptorHandler) RwRouteHandler(com.mendmix.mybatis.plugin.rwseparate.RwRouteHandler) CacheHandler(com.mendmix.mybatis.plugin.cache.CacheHandler)

Aggregations

InterceptorHandler (com.mendmix.mybatis.core.InterceptorHandler)1 CacheHandler (com.mendmix.mybatis.plugin.cache.CacheHandler)1 RwRouteHandler (com.mendmix.mybatis.plugin.rwseparate.RwRouteHandler)1