Search in sources :

Example 1 with GeneralSqlGenerator

use of com.mendmix.mybatis.crud.GeneralSqlGenerator in project jeesuite-libs by vakinge.

the class JeesuiteMybatisEnhancer method handle.

public static void handle(String group, Configuration configuration) throws Exception {
    if ("tkMapper".equals(MybatisConfigs.getCrudDriver())) {
        Class<?> helperClazz = Class.forName("tk.mybatis.mapper.mapperhelper.MapperHelper");
        Object helper = helperClazz.newInstance();
        Class<?> configClazz = Class.forName("tk.mybatis.mapper.entity.Config");
        Object config = configClazz.newInstance();
        Method method = configClazz.getDeclaredMethod("setNotEmpty", boolean.class);
        method.invoke(config, false);
        method = helperClazz.getDeclaredMethod("setConfig", configClazz);
        method.invoke(helper, config);
        method = helperClazz.getDeclaredMethod("registerMapper", Class.class);
        List<MapperMetadata> mappers = MybatisMapperParser.getMapperMetadatas(group);
        for (MapperMetadata mapper : mappers) {
            method.invoke(helper, mapper.getMapperClass());
        }
        method = helperClazz.getDeclaredMethod("processConfiguration", Configuration.class);
        method.invoke(helper, configuration);
    } else {
        new GeneralSqlGenerator(group, configuration).generate();
    }
    // pageHelper
    try {
        Class<?> pageHelperClazz = Class.forName("com.github.pagehelper.PageInterceptor");
        Interceptor pageInterceptor = (Interceptor) pageHelperClazz.newInstance();
        configuration.addInterceptor(pageInterceptor);
    } catch (Exception e) {
    }
    // 注册拦截器
    String[] hanlderNames = MybatisConfigs.getHandlerNames(group);
    JeesuiteMybatisInterceptor interceptor = new JeesuiteMybatisInterceptor(group, hanlderNames);
    configuration.addInterceptor(interceptor);
    interceptor.afterRegister();
    logger.info(">> JeesuiteMybatisEnhancer finshed -> group:{},hanlderNames:{}", group, hanlderNames);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Method(java.lang.reflect.Method) MapperMetadata(com.mendmix.mybatis.metadata.MapperMetadata) JeesuiteMybatisInterceptor(com.mendmix.mybatis.plugin.JeesuiteMybatisInterceptor) Interceptor(org.apache.ibatis.plugin.Interceptor) JeesuiteMybatisInterceptor(com.mendmix.mybatis.plugin.JeesuiteMybatisInterceptor) GeneralSqlGenerator(com.mendmix.mybatis.crud.GeneralSqlGenerator)

Aggregations

GeneralSqlGenerator (com.mendmix.mybatis.crud.GeneralSqlGenerator)1 MapperMetadata (com.mendmix.mybatis.metadata.MapperMetadata)1 JeesuiteMybatisInterceptor (com.mendmix.mybatis.plugin.JeesuiteMybatisInterceptor)1 Method (java.lang.reflect.Method)1 Interceptor (org.apache.ibatis.plugin.Interceptor)1 Configuration (org.apache.ibatis.session.Configuration)1