package com.elab.core.spring.config;

import com.elab.core.spring.DaoScannerConfigurer;
import com.elab.core.sql.ConfigurableFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

/**
 * 持久层配置
 * 这里为配置文件的环境配置,这里需要关注几个点:
 * jdbc.config.path : jdbc的sql文件的存放目录
 * jdbc.config.scan : 需要扫描接口的包路径
 *
 * @author Liukx
 * @create 2018-04-28 11:54
 * @email liukx@elab-plus.com
 **/
@Configuration
@Import({BasicDaoConfig.class})
public class JdbcBeanConfig {

    @Bean
    public ConfigurableFactory getConfigurableFactory(@Autowired Environment env) {
        ConfigurableFactory configurableFactory = new ConfigurableFactory();
        configurableFactory.setSqlConfigurableLocations(env.getProperty("jdbc.config.path", "sql"));
        return configurableFactory;
    }

    @Bean
//    @Conditional(value = {EnableConditional.class})
    public DaoScannerConfigurer daoScannerConfigurer(@Autowired ConfigurableFactory configurableFactory, @Autowired Environment env) {
        DaoScannerConfigurer daoScannerConfigurer = new DaoScannerConfigurer();
        daoScannerConfigurer.setBasePackage(env.getProperty("jdbc.config.scan", "com.elab.**"));
        daoScannerConfigurer.setBasicBaseDaoName("basicBaseDao");
        daoScannerConfigurer.setConfigurableFactory(configurableFactory);
        return daoScannerConfigurer;
    }

}
