mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
05b417fa70
@ -31,6 +31,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public class QueryTable implements CloneSupport<QueryTable> {
|
||||
|
||||
|
||||
protected String schema;
|
||||
protected String name;
|
||||
protected String alias;
|
||||
|
||||
@ -64,4 +64,8 @@ public class SelectQueryTable extends QueryTable {
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return queryWrapper.toSQL();
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,14 @@ import java.util.function.Function;
|
||||
* @author 王帅
|
||||
* @since 2024-03-11
|
||||
*/
|
||||
public abstract class TableDef extends QueryTable {
|
||||
public class TableDef extends QueryTable {
|
||||
|
||||
private static final Map<String, TableDef> CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <V extends TableDef> V getCache(String key, Function<String, V> mappingFunction) {
|
||||
return MapUtil.computeIfAbsent((Map<String, V>) CACHE, key, mappingFunction);
|
||||
}
|
||||
|
||||
protected TableDef(String schema, String tableName) {
|
||||
super(schema, tableName);
|
||||
@ -48,11 +55,9 @@ public abstract class TableDef extends QueryTable {
|
||||
return name;
|
||||
}
|
||||
|
||||
private static final Map<String, TableDef> CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <V extends TableDef> V getCache(String key, Function<String, V> mappingFunction) {
|
||||
return MapUtil.computeIfAbsent((Map<String, V>) CACHE, key, mappingFunction);
|
||||
public TableDef as(String alias) {
|
||||
String key = getNameWithSchema() + "." + alias;
|
||||
return getCache(key, k -> new TableDef(this.schema, this.name, alias));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,9 +23,8 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.*;
|
||||
import static com.mybatisflex.coretest.table.AccountTableDef.ACCOUNT;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static com.mybatisflex.core.query.QueryMethods.*;
|
||||
|
||||
/**
|
||||
* Lambda 构建 SQL 测试。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user