mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 17:18:24 +08:00
optimize: 统一原生 SQL 片段处理类的命名。
This commit is contained in:
parent
b3dba71604
commit
54afe053b2
@ -19,7 +19,7 @@ package com.mybatisflex.core.activerecord.query;
|
||||
import com.mybatisflex.core.query.CPI;
|
||||
import com.mybatisflex.core.query.Join;
|
||||
import com.mybatisflex.core.query.QueryCondition;
|
||||
import com.mybatisflex.core.query.RawFragment;
|
||||
import com.mybatisflex.core.query.RawQueryCondition;
|
||||
|
||||
/**
|
||||
* Lambda joins 构建器。
|
||||
@ -43,7 +43,7 @@ public class JoinBuilder<R extends QueryModel<R>> {
|
||||
}
|
||||
|
||||
public R on(String on) {
|
||||
join.on(new RawFragment(on));
|
||||
join.on(new RawQueryCondition(on));
|
||||
return queryModel;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ public class Joiner<M> {
|
||||
}
|
||||
|
||||
public M on(String on) {
|
||||
join.on(new RawFragment(on));
|
||||
join.on(new RawQueryCondition(on));
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
@ -149,11 +149,11 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
||||
|
||||
|
||||
public QueryCondition and(String sql) {
|
||||
return and(new RawFragment(sql));
|
||||
return and(new RawQueryCondition(sql));
|
||||
}
|
||||
|
||||
public QueryCondition and(String sql, Object... params) {
|
||||
return and(new RawFragment(sql, params));
|
||||
return and(new RawQueryCondition(sql, params));
|
||||
}
|
||||
|
||||
public QueryCondition and(QueryCondition nextCondition) {
|
||||
@ -161,11 +161,11 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
||||
}
|
||||
|
||||
public QueryCondition or(String sql) {
|
||||
return or(new RawFragment(sql));
|
||||
return or(new RawQueryCondition(sql));
|
||||
}
|
||||
|
||||
public QueryCondition or(String sql, Object... params) {
|
||||
return or(new RawFragment(sql, params));
|
||||
return or(new RawQueryCondition(sql, params));
|
||||
}
|
||||
|
||||
public QueryCondition or(QueryCondition nextCondition) {
|
||||
@ -208,8 +208,8 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
||||
.append(SqlConsts.BRACKET_RIGHT);
|
||||
}
|
||||
//原生sql
|
||||
else if (value instanceof RawFragment) {
|
||||
sql.append(((RawFragment) value).getContent());
|
||||
else if (value instanceof RawQueryCondition) {
|
||||
sql.append(((RawQueryCondition) value).getContent());
|
||||
}
|
||||
//正常查询,构建问号
|
||||
else {
|
||||
@ -251,7 +251,7 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
|
||||
|| SqlConsts.IS_NOT_NULL.equals(logic)
|
||||
|| value instanceof QueryColumn
|
||||
|| value instanceof QueryWrapper
|
||||
|| value instanceof RawFragment) {
|
||||
|| value instanceof RawQueryCondition) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
|
||||
@ -2628,14 +2628,14 @@ public class QueryMethods {
|
||||
* 构建原生查询条件。
|
||||
*/
|
||||
public static QueryCondition raw(String raw) {
|
||||
return new RawFragment(raw);
|
||||
return new RawQueryCondition(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建原生查询条件,并附带参数。
|
||||
*/
|
||||
public static QueryCondition raw(String raw, Object... params) {
|
||||
return new RawFragment(raw, params);
|
||||
return new RawQueryCondition(raw, params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -23,9 +23,20 @@ import com.mybatisflex.core.dialect.DialectFactory;
|
||||
import com.mybatisflex.core.table.TableDef;
|
||||
import com.mybatisflex.core.table.TableInfo;
|
||||
import com.mybatisflex.core.table.TableInfoFactory;
|
||||
import com.mybatisflex.core.util.*;
|
||||
import com.mybatisflex.core.util.ArrayUtil;
|
||||
import com.mybatisflex.core.util.ClassUtil;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.LambdaGetter;
|
||||
import com.mybatisflex.core.util.LambdaUtil;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
@ -240,12 +251,12 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
}
|
||||
|
||||
public QueryWrapper where(String sql) {
|
||||
this.setWhereQueryCondition(new RawFragment(sql));
|
||||
this.setWhereQueryCondition(new RawQueryCondition(sql));
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryWrapper where(String sql, Object... params) {
|
||||
this.setWhereQueryCondition(new RawFragment(sql, params));
|
||||
this.setWhereQueryCondition(new RawQueryCondition(sql, params));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -270,12 +281,12 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
}
|
||||
|
||||
public QueryWrapper and(String sql) {
|
||||
this.addWhereQueryCondition(new RawFragment(sql), SqlConnector.AND);
|
||||
this.addWhereQueryCondition(new RawQueryCondition(sql), SqlConnector.AND);
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryWrapper and(String sql, Object... params) {
|
||||
this.addWhereQueryCondition(new RawFragment(sql, params), SqlConnector.AND);
|
||||
this.addWhereQueryCondition(new RawQueryCondition(sql, params), SqlConnector.AND);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -319,12 +330,12 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
}
|
||||
|
||||
public QueryWrapper or(String sql) {
|
||||
this.addWhereQueryCondition(new RawFragment(sql), SqlConnector.OR);
|
||||
this.addWhereQueryCondition(new RawQueryCondition(sql), SqlConnector.OR);
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryWrapper or(String sql, Object... params) {
|
||||
this.addWhereQueryCondition(new RawFragment(sql, params), SqlConnector.OR);
|
||||
this.addWhereQueryCondition(new RawQueryCondition(sql, params), SqlConnector.OR);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -766,7 +777,7 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
||||
}
|
||||
for (String queryOrderBy : orderBys) {
|
||||
if (StringUtil.isNotBlank(queryOrderBy)) {
|
||||
addOrderBy(new StringQueryOrderBy(queryOrderBy));
|
||||
addOrderBy(new RawQueryOrderBy(queryOrderBy));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
||||
@ -22,14 +22,16 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义字符串列,用于扩展
|
||||
* 原生列。
|
||||
*
|
||||
* @author michael
|
||||
* @author 王帅
|
||||
*/
|
||||
public class RawQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
|
||||
protected String content;
|
||||
protected Object[] params;
|
||||
|
||||
|
||||
public RawQueryColumn(Object content, Object... params) {
|
||||
this.content = String.valueOf(content);
|
||||
this.params = params;
|
||||
@ -53,6 +55,14 @@ public class RawQueryColumn extends QueryColumn implements HasParamsColumn {
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public Object[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawQueryColumn clone() {
|
||||
return (RawQueryColumn) super.clone();
|
||||
|
||||
@ -22,19 +22,20 @@ import com.mybatisflex.core.util.StringUtil;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SQL 原生片段
|
||||
* 原生条件。
|
||||
*
|
||||
* @author michael
|
||||
* @author 王帅
|
||||
*/
|
||||
public class RawFragment extends QueryCondition {
|
||||
|
||||
public class RawQueryCondition extends QueryCondition {
|
||||
|
||||
protected String content;
|
||||
|
||||
|
||||
public RawFragment(String content) {
|
||||
public RawQueryCondition(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public RawFragment(String content, Object... paras) {
|
||||
public RawQueryCondition(String content, Object... paras) {
|
||||
this.content = content;
|
||||
this.setValue(paras);
|
||||
}
|
||||
@ -72,13 +73,19 @@ public class RawFragment extends QueryCondition {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawFragment clone() {
|
||||
return (RawFragment) super.clone();
|
||||
public String toString() {
|
||||
return "RawQueryCondition{" +
|
||||
"content='" + content + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawQueryCondition clone() {
|
||||
return (RawQueryCondition) super.clone();
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,25 +22,45 @@ import com.mybatisflex.core.util.SqlUtil;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
* 原生排序字段。
|
||||
*
|
||||
* @author michael
|
||||
* @author 王帅
|
||||
*/
|
||||
public class StringQueryOrderBy extends QueryOrderBy {
|
||||
public class RawQueryOrderBy extends QueryOrderBy {
|
||||
|
||||
private final String orderBy;
|
||||
protected String content;
|
||||
|
||||
public StringQueryOrderBy(String orderBy) {
|
||||
SqlUtil.keepOrderBySqlSafely(orderBy);
|
||||
this.orderBy = orderBy;
|
||||
public RawQueryOrderBy(String content) {
|
||||
this(content, true);
|
||||
}
|
||||
|
||||
public RawQueryOrderBy(String content, boolean checkAvailable) {
|
||||
if (checkAvailable) {
|
||||
SqlUtil.keepOrderBySqlSafely(content);
|
||||
}
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||
return orderBy;
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringQueryOrderBy clone() {
|
||||
return (StringQueryOrderBy) super.clone();
|
||||
public String toString() {
|
||||
return "RawQueryOrderBy{" +
|
||||
"content='" + content + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawQueryOrderBy clone() {
|
||||
return (RawQueryOrderBy) super.clone();
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,7 +29,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public class RawQueryTable extends QueryTable {
|
||||
|
||||
private final String content;
|
||||
protected String content;
|
||||
|
||||
public RawQueryTable(String content) {
|
||||
this.content = content;
|
||||
@ -60,6 +60,10 @@ public class RawQueryTable extends QueryTable {
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RawQueryTable clone() {
|
||||
return (RawQueryTable) super.clone();
|
||||
|
||||
@ -98,7 +98,7 @@ class WrapperUtil {
|
||||
Object value = condition.getValue();
|
||||
if (value == null
|
||||
|| value instanceof QueryColumn
|
||||
|| value instanceof RawFragment) {
|
||||
|| value instanceof RawQueryCondition) {
|
||||
getValues(condition.next, params);
|
||||
return;
|
||||
}
|
||||
@ -133,8 +133,8 @@ class WrapperUtil {
|
||||
static String buildValue(Object value) {
|
||||
if (value instanceof Number || value instanceof Boolean) {
|
||||
return String.valueOf(value);
|
||||
} else if (value instanceof RawFragment) {
|
||||
return ((RawFragment) value).getContent();
|
||||
} else if (value instanceof RawQueryCondition) {
|
||||
return ((RawQueryCondition) value).getContent();
|
||||
} else if (value instanceof QueryColumn) {
|
||||
return ((QueryColumn) value).toConditionSql(null, DialectFactory.getDialect());
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user