mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
feat: RelationManager add auto clear config support
This commit is contained in:
parent
92ac0fab44
commit
7d1d2f3f2f
@ -62,6 +62,12 @@ public class RelationManager {
|
||||
private static ThreadLocal<Set<String>> ignoreRelations = new ThreadLocal<>();
|
||||
|
||||
|
||||
/**
|
||||
* 每次查询是否自动清除 depth extraConditionParams ignoreRelations 的配置
|
||||
*/
|
||||
private static ThreadLocal<Boolean> autoClearConfig = ThreadLocal.withInitial(() -> true);
|
||||
|
||||
|
||||
private static List<AbstractRelation> getRelations(Class<?> clazz) {
|
||||
return MapUtil.computeIfAbsent(classRelations, clazz, RelationManager::doGetRelations);
|
||||
}
|
||||
@ -101,6 +107,11 @@ public class RelationManager {
|
||||
return depthThreadLocal.get();
|
||||
}
|
||||
|
||||
public static void clearMaxDepth() {
|
||||
extraConditionParams.remove();
|
||||
}
|
||||
|
||||
|
||||
public static void setExtraConditionParams(Map<String, Object> params) {
|
||||
extraConditionParams.set(params);
|
||||
}
|
||||
@ -118,6 +129,11 @@ public class RelationManager {
|
||||
return extraConditionParams.get();
|
||||
}
|
||||
|
||||
public static void clearExtraConditionParams() {
|
||||
extraConditionParams.remove();
|
||||
}
|
||||
|
||||
|
||||
public static void setIgnoreRelations(Set<String> ignoreRelations) {
|
||||
RelationManager.ignoreRelations.set(ignoreRelations);
|
||||
}
|
||||
@ -135,6 +151,23 @@ public class RelationManager {
|
||||
return ignoreRelations.get();
|
||||
}
|
||||
|
||||
public static void clearIgnoreRelations() {
|
||||
ignoreRelations.remove();
|
||||
}
|
||||
|
||||
|
||||
public static void setAutoClearConfig(boolean enable) {
|
||||
autoClearConfig.set(enable);
|
||||
}
|
||||
|
||||
public static boolean getAutoClearConfig() {
|
||||
return autoClearConfig.get();
|
||||
}
|
||||
|
||||
public static void clearAutoClearConfig() {
|
||||
autoClearConfig.remove();
|
||||
}
|
||||
|
||||
|
||||
static Object[] getExtraConditionParams(List<String> keys) {
|
||||
if (keys == null || keys.isEmpty()) {
|
||||
@ -155,7 +188,17 @@ public class RelationManager {
|
||||
|
||||
|
||||
public static <Entity> void queryRelations(BaseMapper<?> mapper, List<Entity> entities) {
|
||||
|
||||
doQueryRelations(mapper, entities, 0, depthThreadLocal.get(), ignoreRelations.get());
|
||||
|
||||
Boolean autoClearEnable = autoClearConfig.get();
|
||||
|
||||
//自动清除用户配置
|
||||
if (autoClearEnable != null && autoClearEnable) {
|
||||
depthThreadLocal.remove();
|
||||
extraConditionParams.remove();
|
||||
ignoreRelations.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user