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