feat: 新增 MyBatisFlexInitializer.java 方便用户对 MyBatisFlex 进行初始化配置

This commit is contained in:
开源海哥 2023-06-24 11:04:35 +08:00
parent 039ef607b3
commit 037f0efc78
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.spring.boot;
/**
* MyBatisFlex 初始化监听器
* 一般可以用于去初始化
*
* 1自定义主键生成器
* 2FlexGlobalConfig 的全局配置
* 3多租户配置
* 4动态表名配置
* 5逻辑删除处理器配置
* 6自定义脱敏规则
* 7SQL 审计配置
* 8SQL 打印配置
* 9数据源解密器配置
* 10自定义数据方言配置
* ...
*/
public interface MyBatisFlexInitializer {
void onInitBefore();
}

View File

@ -121,6 +121,9 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
//多租户 //多租户
protected final TenantFactory tenantFactory; protected final TenantFactory tenantFactory;
//初始化监听
protected final MyBatisFlexInitializer myBatisFlexInitializer;
public MybatisFlexAutoConfiguration(MybatisFlexProperties properties, ObjectProvider<Interceptor[]> interceptorsProvider, public MybatisFlexAutoConfiguration(MybatisFlexProperties properties, ObjectProvider<Interceptor[]> interceptorsProvider,
ObjectProvider<TypeHandler[]> typeHandlersProvider, ObjectProvider<LanguageDriver[]> languageDriversProvider, ObjectProvider<TypeHandler[]> typeHandlersProvider, ObjectProvider<LanguageDriver[]> languageDriversProvider,
@ -130,7 +133,8 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
ObjectProvider<DataSourceDecipher> dataSourceDecipherProvider, ObjectProvider<DataSourceDecipher> dataSourceDecipherProvider,
ObjectProvider<DynamicTableProcessor> dynamicTableProcessorProvider, ObjectProvider<DynamicTableProcessor> dynamicTableProcessorProvider,
ObjectProvider<DynamicSchemaProcessor> dynamicSchemaProcessorProvider, ObjectProvider<DynamicSchemaProcessor> dynamicSchemaProcessorProvider,
ObjectProvider<TenantFactory> tenantFactoryProvider ObjectProvider<TenantFactory> tenantFactoryProvider,
ObjectProvider<MyBatisFlexInitializer> myBatisFlexInitializerProvider
) { ) {
this.properties = properties; this.properties = properties;
this.interceptors = interceptorsProvider.getIfAvailable(); this.interceptors = interceptorsProvider.getIfAvailable();
@ -150,6 +154,9 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
//多租户 //多租户
this.tenantFactory = tenantFactoryProvider.getIfAvailable(); this.tenantFactory = tenantFactoryProvider.getIfAvailable();
//初始化监听器
this.myBatisFlexInitializer = myBatisFlexInitializerProvider.getIfAvailable();
} }
@Override @Override
@ -174,6 +181,11 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
if (tenantFactory != null) { if (tenantFactory != null) {
TenantManager.setTenantFactory(tenantFactory); TenantManager.setTenantFactory(tenantFactory);
} }
//初始化监听器
if (myBatisFlexInitializer != null) {
myBatisFlexInitializer.onInitBefore();
}
} }
private void checkConfigFileExists() { private void checkConfigFileExists() {