mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
add multi datasource support
This commit is contained in:
parent
3006ab30da
commit
f0fba210aa
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.mybatisflex.core.datasource;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DataSourceKey {
|
||||
|
||||
private static ThreadLocal<String> keyThreadLocal = new ThreadLocal<>();
|
||||
@ -23,6 +25,24 @@ public class DataSourceKey {
|
||||
keyThreadLocal.set(environmentId);
|
||||
}
|
||||
|
||||
public static <T> T use(String environmentId, Supplier<T> supplier) {
|
||||
try {
|
||||
use(environmentId);
|
||||
return supplier.get();
|
||||
} finally {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void use(String environmentId, Runnable runnable) {
|
||||
try {
|
||||
use(environmentId);
|
||||
runnable.run();
|
||||
} finally {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
keyThreadLocal.remove();
|
||||
}
|
||||
|
||||
@ -93,14 +93,13 @@ public class DataSourceBuilder {
|
||||
|
||||
|
||||
public static String attrToCamel(String string) {
|
||||
String temp = string.toLowerCase();
|
||||
int strLen = temp.length();
|
||||
int strLen = string.length();
|
||||
StringBuilder sb = new StringBuilder(strLen);
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
char c = temp.charAt(i);
|
||||
char c = string.charAt(i);
|
||||
if (c == '-') {
|
||||
if (++i < strLen) {
|
||||
sb.append(Character.toUpperCase(temp.charAt(i)));
|
||||
sb.append(Character.toUpperCase(string.charAt(i)));
|
||||
}
|
||||
} else {
|
||||
sb.append(c);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user