fix: fix some global config
This commit is contained in:
parent
a18395a323
commit
f891c631cb
@ -69,13 +69,13 @@ public class DruidDataSourceCreator implements DataSourceCreator {
|
||||
private static void fetchMethod() {
|
||||
Class<DruidDataSource> aClass = DruidDataSource.class;
|
||||
try {
|
||||
configMethod = aClass.getMethod("configFromPropeties", DruidDataSource.class);
|
||||
configMethod = aClass.getMethod("configFromPropeties", Properties.class);
|
||||
return;
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
configMethod = aClass.getMethod("configFromPropety", DruidDataSource.class);
|
||||
configMethod = aClass.getMethod("configFromPropety", Properties.class);
|
||||
return;
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.toolkit;
|
||||
|
||||
public abstract class DsStrUtils {
|
||||
|
@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Setter
|
||||
public class DataSourceGlobalProperty {
|
||||
public class DataSourceGlobalConfig {
|
||||
|
||||
/**
|
||||
* 是否懒加载数据源
|
@ -41,7 +41,7 @@ public class DefaultDataSourceCreator {
|
||||
|
||||
private List<DataSourceCreator> creators;
|
||||
|
||||
private DataSourceGlobalProperty properties;
|
||||
private DataSourceGlobalConfig config;
|
||||
private DataSourceInitEvent dataSourceInitEvent;
|
||||
|
||||
public DataSource createDataSource(DataSourceProperty dataSourceProperty) {
|
||||
@ -57,19 +57,28 @@ public class DefaultDataSourceCreator {
|
||||
}
|
||||
String publicKey = dataSourceProperty.getPublicKey();
|
||||
if (StringUtils.isEmpty(publicKey)) {
|
||||
publicKey = properties.getPublicKey();
|
||||
dataSourceProperty.setPublicKey(publicKey);
|
||||
if (config != null) {
|
||||
publicKey = config.getPublicKey();
|
||||
dataSourceProperty.setPublicKey(publicKey);
|
||||
}
|
||||
}
|
||||
Boolean lazy = dataSourceProperty.getLazy();
|
||||
if (lazy == null) {
|
||||
lazy = properties.getLazy();
|
||||
dataSourceProperty.setLazy(lazy);
|
||||
if (config != null) {
|
||||
lazy = config.getLazy();
|
||||
dataSourceProperty.setLazy(lazy);
|
||||
}
|
||||
}
|
||||
if (dataSourceInitEvent != null) {
|
||||
dataSourceInitEvent.beforeCreate(dataSourceProperty);
|
||||
}
|
||||
dataSourceInitEvent.beforeCreate(dataSourceProperty);
|
||||
DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty);
|
||||
dataSourceInitEvent.afterCreate(dataSource);
|
||||
if (dataSourceInitEvent != null) {
|
||||
dataSourceInitEvent.afterCreate(dataSource);
|
||||
}
|
||||
this.runScrip(dataSource, dataSourceProperty);
|
||||
return wrapDataSource(dataSource, dataSourceProperty);
|
||||
return dataSource;
|
||||
// return wrapDataSource(dataSource, dataSourceProperty);
|
||||
}
|
||||
|
||||
private void runScrip(DataSource dataSource, DataSourceProperty dataSourceProperty) {
|
||||
@ -91,14 +100,14 @@ public class DefaultDataSourceCreator {
|
||||
String name = dataSourceProperty.getPoolName();
|
||||
DataSource targetDataSource = dataSource;
|
||||
|
||||
Boolean enabledP6spy = properties.getP6spy() && dataSourceProperty.getP6spy();
|
||||
Boolean enabledP6spy = config.getP6spy() && dataSourceProperty.getP6spy();
|
||||
if (enabledP6spy) {
|
||||
targetDataSource = new P6DataSource(dataSource);
|
||||
log.debug("dynamic-datasource [{}] wrap p6spy plugin", name);
|
||||
}
|
||||
|
||||
Boolean enabledSeata = properties.getSeata() && dataSourceProperty.getSeata();
|
||||
SeataMode seataMode = properties.getSeataMode();
|
||||
Boolean enabledSeata = config.getSeata() && dataSourceProperty.getSeata();
|
||||
SeataMode seataMode = config.getSeataMode();
|
||||
if (enabledSeata) {
|
||||
if (SeataMode.XA == seataMode) {
|
||||
targetDataSource = new DataSourceProxyXA(targetDataSource);
|
||||
|
Loading…
x
Reference in New Issue
Block a user