test: 测试多租户默认字段配置。

This commit is contained in:
Suomm 2023-08-10 09:33:34 +08:00
parent a5fca750c5
commit 105e5b3d97
2 changed files with 19 additions and 24 deletions

View File

@ -16,7 +16,10 @@
package com.mybatisflex.test;
import com.mybatisflex.annotation.*;
import com.mybatisflex.annotation.ColumnMask;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import com.mybatisflex.core.mask.Masks;
import java.util.Date;
@ -34,7 +37,7 @@ public class TenantAccount {
private Date birthday;
@Column(tenantId = true)
// @Column(tenantId = true)
private Long tenantId;
public Long getId() {

View File

@ -18,8 +18,6 @@ package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.tenant.TenantFactory;
import com.mybatisflex.core.tenant.TenantManager;
import com.mybatisflex.mapper.TenantAccountMapper;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
@ -27,10 +25,6 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
import static com.mybatisflex.core.query.QueryMethods.select;
import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT;
import static com.mybatisflex.test.table.TenantAccountTableDef.TENANT_ACCOUNT;
public class TenantTester {
public static void main(String[] args) {
@ -52,24 +46,22 @@ public class TenantTester {
AuditManager.setMessageCollector(new ConsoleMessageCollector());
//配置 tenantFactory
TenantManager.setTenantFactory(new TenantFactory() {
@Override
public Object[] getTenantIds() {
return new Object[]{1, 2};
}
});
TenantManager.setTenantFactory(() -> new Object[]{1, 2});
TenantAccountMapper mapper = MybatisFlexBootstrap.getInstance().getMapper(TenantAccountMapper.class);
TenantAccountMapper mapper = MybatisFlexBootstrap.getInstance()
.getMapper(TenantAccountMapper.class);
mapper.selectListByQuery(QueryWrapper.create()
.select(TENANT_ACCOUNT.ALL_COLUMNS)
.from(TENANT_ACCOUNT.as("c"), ACCOUNT.as("b"))
.where(TENANT_ACCOUNT.ID.eq(ACCOUNT.ID))
.and(TENANT_ACCOUNT.ID.eq(1))
.unionAll(select(TENANT_ACCOUNT.ALL_COLUMNS).from(TENANT_ACCOUNT)
.where(TENANT_ACCOUNT.ID.eq(2))
)
);
mapper.selectAll().forEach(System.out::println);
// mapper.selectListByQuery(QueryWrapper.create()
// .select(TENANT_ACCOUNT.ALL_COLUMNS)
// .from(TENANT_ACCOUNT.as("c"), ACCOUNT.as("b"))
// .where(TENANT_ACCOUNT.ID.eq(ACCOUNT.ID))
// .and(TENANT_ACCOUNT.ID.eq(1))
// .unionAll(select(TENANT_ACCOUNT.ALL_COLUMNS).from(TENANT_ACCOUNT)
// .where(TENANT_ACCOUNT.ID.eq(2))
// )
// );
// mapper.deleteBatchByIds(Arrays.asList(1, 2));