refactor: init schema and data
This commit is contained in:
parent
fd32a69566
commit
e622152c20
@ -18,6 +18,7 @@ package com.baomidou.dynamic.datasource.creator;
|
||||
import com.baomidou.dynamic.datasource.ds.ItemDataSource;
|
||||
import com.baomidou.dynamic.datasource.enums.SeataMode;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DatasourceInitProperty;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
|
||||
import com.baomidou.dynamic.datasource.support.ScriptRunner;
|
||||
import com.p6spy.engine.spy.P6DataSource;
|
||||
@ -57,10 +58,11 @@ public abstract class AbstractDataSourceCreator {
|
||||
}
|
||||
|
||||
private void runScrip(DataSource dataSource, DataSourceProperty dataSourceProperty) {
|
||||
String schema = dataSourceProperty.getSchema();
|
||||
String data = dataSourceProperty.getData();
|
||||
DatasourceInitProperty initProperty = dataSourceProperty.getInit();
|
||||
String schema = initProperty.getSchema();
|
||||
String data = initProperty.getData();
|
||||
if (StringUtils.hasText(schema) || StringUtils.hasText(data)) {
|
||||
ScriptRunner scriptRunner = new ScriptRunner(dataSourceProperty.isContinueOnError(), dataSourceProperty.getSeparator());
|
||||
ScriptRunner scriptRunner = new ScriptRunner(initProperty.isContinueOnError(), initProperty.getSeparator());
|
||||
if (StringUtils.hasText(schema)) {
|
||||
scriptRunner.runScript(dataSource, schema);
|
||||
}
|
||||
|
@ -72,14 +72,6 @@ public class DataSourceProperty {
|
||||
* jndi数据源名称(设置即表示启用)
|
||||
*/
|
||||
private String jndiName;
|
||||
/**
|
||||
* 自动运行的建表脚本
|
||||
*/
|
||||
private String schema;
|
||||
/**
|
||||
* 自动运行的数据脚本
|
||||
*/
|
||||
private String data;
|
||||
/**
|
||||
* 是否启用seata
|
||||
*/
|
||||
@ -93,13 +85,10 @@ public class DataSourceProperty {
|
||||
*/
|
||||
private Boolean lazy;
|
||||
/**
|
||||
* 错误是否继续 默认 true
|
||||
* 初始化
|
||||
*/
|
||||
private boolean continueOnError = true;
|
||||
/**
|
||||
* 分隔符 默认 ;
|
||||
*/
|
||||
private String separator = ";";
|
||||
@NestedConfigurationProperty
|
||||
private DatasourceInitProperty init = new DatasourceInitProperty();
|
||||
/**
|
||||
* Druid参数配置
|
||||
*/
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright © 2018 organization baomidou
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.baomidou.dynamic.datasource.spring.boot.autoconfigure;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 动态数据源初始化脚本配置
|
||||
*
|
||||
* @author TaoYu
|
||||
* @since 3.5.0
|
||||
*/
|
||||
@Data
|
||||
public class DatasourceInitProperty {
|
||||
|
||||
/**
|
||||
* 自动运行的建表脚本
|
||||
*/
|
||||
private String schema;
|
||||
/**
|
||||
* 自动运行的数据脚本
|
||||
*/
|
||||
private String data;
|
||||
|
||||
/**
|
||||
* 错误是否继续 默认 true
|
||||
*/
|
||||
private boolean continueOnError = true;
|
||||
/**
|
||||
* 分隔符 默认 ;
|
||||
*/
|
||||
private String separator = ";";
|
||||
}
|
@ -72,6 +72,10 @@ public class DynamicDataSourceProperties {
|
||||
* seata使用模式,默认AT
|
||||
*/
|
||||
private SeataMode seataMode = SeataMode.AT;
|
||||
/**
|
||||
* 全局默认publicKey
|
||||
*/
|
||||
private String publicKey = CryptoUtils.DEFAULT_PUBLIC_KEY_STRING;
|
||||
/**
|
||||
* 每一个数据源
|
||||
*/
|
||||
@ -101,11 +105,6 @@ public class DynamicDataSourceProperties {
|
||||
@NestedConfigurationProperty
|
||||
private Dbcp2Config dbcp2 = new Dbcp2Config();
|
||||
|
||||
/**
|
||||
* 全局默认publicKey
|
||||
*/
|
||||
private String publicKey = CryptoUtils.DEFAULT_PUBLIC_KEY_STRING;
|
||||
|
||||
/**
|
||||
* aop with default ds annotation
|
||||
*/
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright © 2018 organization baomidou
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.baomidou.dynamic.datasource.spring.boot.autoconfigure.event;
|
||||
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||
|
||||
public interface DataSourcePropertyEvent {
|
||||
|
||||
void beforeCreate(DataSourceProperty dataSourceProperty);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user