Search in sources :

Example 16 with GlobalConfig

use of com.baomidou.mybatisplus.core.config.GlobalConfig in project solon by noear.

the class MybatisAdapterPlus method initConfiguration.

/**
 * 初始化配置
 */
@Override
protected void initConfiguration(Environment environment) {
    // for configuration section
    config = new MybatisConfiguration(environment);
    Props cfgProps = dsProps.getProp("configuration");
    if (cfgProps.size() > 0) {
        Utils.injectProperties(config, cfgProps);
    }
    // for globalConfig section
    globalConfig = new GlobalConfig().setDbConfig(new GlobalConfig.DbConfig());
    Props globalProps = dsProps.getProp("globalConfig");
    if (globalProps.size() > 0) {
        // 尝试配置注入
        Utils.injectProperties(globalConfig, globalProps);
    }
    GlobalConfigUtils.setGlobalConfig(config, globalConfig);
}
Also used : MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig)

Example 17 with GlobalConfig

use of com.baomidou.mybatisplus.core.config.GlobalConfig in project solon by noear.

the class MybatisSqlSessionFactoryBuilderNew method build.

@Override
public SqlSessionFactory build(Configuration configuration) {
    GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
    Object identifierGenerator;
    if (null == globalConfig.getIdentifierGenerator()) {
        identifierGenerator = new DefaultIdentifierGenerator();
        globalConfig.setIdentifierGenerator((IdentifierGenerator) identifierGenerator);
    } else {
        identifierGenerator = globalConfig.getIdentifierGenerator();
    }
    IdWorker.setIdentifierGenerator((IdentifierGenerator) identifierGenerator);
    if (globalConfig.isEnableSqlRunner()) {
        (new SqlRunnerInjector()).inject(configuration);
    }
    SqlSessionFactory sqlSessionFactory = super.build(configuration);
    globalConfig.setSqlSessionFactory(sqlSessionFactory);
    Aop.getAsyn(MetaObjectHandler.class, bw -> {
        globalConfig.setMetaObjectHandler(bw.get());
    });
    return sqlSessionFactory;
}
Also used : SqlRunnerInjector(com.baomidou.mybatisplus.core.injector.SqlRunnerInjector) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) DefaultIdentifierGenerator(com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator)

Example 18 with GlobalConfig

use of com.baomidou.mybatisplus.core.config.GlobalConfig in project JBM by numen06.

the class MybatisMapperRefresh method run.

@Override
public void run() {
    final GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
    /*
         * 启动 XML 热加载
         */
    if (enabled) {
        beforeTime = SystemClock.now();
        final MybatisMapperRefresh runnable = this;
        new Thread(new Runnable() {

            @Override
            public void run() {
                if (fileSet == null) {
                    fileSet = new HashSet<>();
                    if (mapperLocations != null) {
                        for (Resource mapperLocation : mapperLocations) {
                            try {
                                if (ResourceUtils.isJarURL(mapperLocation.getURL())) {
                                    String key = new UrlResource(ResourceUtils.extractJarFileURL(mapperLocation.getURL())).getFile().getPath();
                                    fileSet.add(key);
                                    if (jarMapper.get(key) != null) {
                                        jarMapper.get(key).add(mapperLocation);
                                    } else {
                                        List<Resource> resourcesList = new ArrayList<>();
                                        resourcesList.add(mapperLocation);
                                        jarMapper.put(key, resourcesList);
                                    }
                                } else {
                                    fileSet.add(mapperLocation.getFile().getPath());
                                }
                            } catch (IOException ioException) {
                                ioException.printStackTrace();
                            }
                        }
                    }
                }
                try {
                    Thread.sleep(delaySeconds * 1000);
                } catch (InterruptedException interruptedException) {
                    interruptedException.printStackTrace();
                }
                do {
                    try {
                        for (String filePath : fileSet) {
                            File file = new File(filePath);
                            if (file.isFile() && file.lastModified() > beforeTime) {
                                List<Resource> removeList = jarMapper.get(filePath);
                                if (removeList != null && !removeList.isEmpty()) {
                                    for (Resource resource : removeList) {
                                        runnable.refresh(resource);
                                    }
                                } else {
                                    runnable.refresh(new FileSystemResource(file));
                                }
                            }
                        }
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
                    try {
                        Thread.sleep(sleepSeconds * 1000);
                    } catch (InterruptedException interruptedException) {
                        interruptedException.printStackTrace();
                    }
                } while (true);
            }
        }, "mybatis-plus MapperRefresh").start();
    }
}
Also used : GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) UrlResource(org.springframework.core.io.UrlResource) File(java.io.File)

Example 19 with GlobalConfig

use of com.baomidou.mybatisplus.core.config.GlobalConfig in project springboot-templet-start by thedestiny.

the class MybatisPlusConfigSecondDatasource method secSqlSessionFactory.

// sec
@Bean("secSqlSessionFactory")
public SqlSessionFactory secSqlSessionFactory(@Qualifier("secDatasource") DataSource dataSource) throws Exception {
    MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
    sqlSessionFactory.setDataSource(dataSource);
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setCacheEnabled(false);
    sqlSessionFactory.setConfiguration(configuration);
    sqlSessionFactory.setTypeAliasesPackage("com.destiny.hiootamus.entity.second");
    sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/second/*.xml"));
    sqlSessionFactory.setPlugins(plusInterceptor);
    sqlSessionFactory.setGlobalConfig(new GlobalConfig().setBanner(false));
    return sqlSessionFactory.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 20 with GlobalConfig

use of com.baomidou.mybatisplus.core.config.GlobalConfig in project poseidon by muggle0.

the class MybatisPlusConfig method globalConfiguration.

// mybatis plus 全局配置
@Bean(name = "globalConfig")
public GlobalConfig globalConfiguration() {
    log.info("初始化GlobalConfiguration");
    GlobalConfig config = new GlobalConfig();
    // 控制台打印 plus banner
    config.setBanner(false);
    return config;
}
Also used : GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)21 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)13 Bean (org.springframework.context.annotation.Bean)12 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)10 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)7 Resource (org.springframework.core.io.Resource)4 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)4 DbType (com.baomidou.mybatisplus.annotation.DbType)2 IKeyGenerator (com.baomidou.mybatisplus.core.incrementer.IKeyGenerator)2 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)2 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)2 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)2 FieldFill (com.baomidou.mybatisplus.annotation.FieldFill)1 ConfigurationCustomizer (com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer)1 DefaultIdentifierGenerator (com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator)1 AbstractMethod (com.baomidou.mybatisplus.core.injector.AbstractMethod)1 DefaultSqlInjector (com.baomidou.mybatisplus.core.injector.DefaultSqlInjector)1 SqlRunnerInjector (com.baomidou.mybatisplus.core.injector.SqlRunnerInjector)1 TableInfo (com.baomidou.mybatisplus.core.metadata.TableInfo)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1