fix: 修复 druid 数据源的某些场景下,数据加密无法使用的问题

This commit is contained in:
开源海哥 2023-08-18 09:30:21 +08:00
parent 6eadba4e77
commit 725b3efcd0

View File

@ -15,6 +15,7 @@
*/
package com.mybatisflex.core.datasource;
import com.mybatisflex.core.exception.FlexExceptions;
import com.mybatisflex.core.util.ClassUtil;
import org.apache.ibatis.logging.LogFactory;
@ -42,6 +43,8 @@ public class DataSourceManager {
return;
}
restartDataSource(dataSource);
for (DataSourceProperty property : DataSourceProperty.values()) {
Method getterMethod = ClassUtil.getAnyMethod(dataSource.getClass(), property.getGetterMethods());
if (getterMethod != null) {
@ -57,6 +60,18 @@ public class DataSourceManager {
}
}
static void restartDataSource(DataSource dataSource) {
Method restartMethod = ClassUtil.getFirstMethod(ClassUtil.getUsefulClass(dataSource.getClass())
, method -> "restart".equals(method.getName()));
if (restartMethod != null) {
try {
restartMethod.invoke(dataSource);
} catch (Exception e) {
throw FlexExceptions.wrap(e);
}
}
}
static String invokeMethod(Method method, Object object, Object... params) {
try {