Merge remote-tracking branch 'origin/main'

This commit is contained in:
Suomm 2024-04-26 10:22:41 +08:00
commit 05b417fa70
4 changed files with 17 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import java.util.Objects;
*/
public class QueryTable implements CloneSupport<QueryTable> {
protected String schema;
protected String name;
protected String alias;

View File

@ -64,4 +64,8 @@ public class SelectQueryTable extends QueryTable {
return clone;
}
@Override
public String toString() {
return queryWrapper.toSQL();
}
}

View File

@ -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));
}
}

View File

@ -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 测试