Skip to content

Commit

Permalink
新增插件跳过执行方法.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Dec 11, 2024
1 parent 7edef39 commit eb9bc20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* @author miemie
Expand Down Expand Up @@ -93,6 +94,24 @@ public static IgnoreStrategy getIgnoreStrategy(String key) {
return IGNORE_STRATEGY_CACHE.get(key);
}

/**
* 按指定策略执行指定方法
*
* @param ignoreStrategy 忽略策略
* @param supplier 执行方法
* @param <T> T
* @return 返回值
* @since 3.5.10
*/
public static <T> T execute(IgnoreStrategy ignoreStrategy, Supplier<T> supplier) {
try {
handle(ignoreStrategy);
return supplier.get();
} finally {
clearIgnoreStrategy();
}
}

/**
* 初始化缓存
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.baomidou.mybatisplus.test.tenant;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy;
import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
Expand Down Expand Up @@ -92,6 +94,15 @@ void test() {
Assertions.assertEquals(0, m.deleteById(entity.getId()));
Assertions.assertEquals(1, m.deleteByIdWithIgnore(entity.getId()));
});

doTest(m -> {
Entity entity = new Entity().setName("秋秋").setTenantId(2);
m.insert(entity);
Assertions.assertNull(m.selectById(entity.getId()));
Assertions.assertNotNull(InterceptorIgnoreHelper.execute(IgnoreStrategy.builder().tenantLine(true).build(), () -> m.selectById(entity.getId())));
Assertions.assertEquals(0, m.deleteById(entity.getId()));
Assertions.assertEquals(1, InterceptorIgnoreHelper.execute(IgnoreStrategy.builder().tenantLine(true).build(), () -> m.deleteById(entity.getId())));
});
}

@Override
Expand Down

0 comments on commit eb9bc20

Please sign in to comment.