!310 remove:整理 @Deprecated 标记的 API

Merge pull request !310 from 王帅/main
This commit is contained in:
Michael Yang 2023-08-25 08:14:52 +00:00 committed by Gitee
commit 36021c9c2d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 28 additions and 194 deletions

View File

@ -15,10 +15,8 @@
*/
package com.mybatisflex.core.query;
import com.mybatisflex.core.util.ClassUtil;
import com.mybatisflex.core.util.StringUtil;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
@ -38,59 +36,38 @@ public class If {
* 判断对象是否非空
*/
public static boolean notNull(Object object) {
return !isNull(object);
return object != null;
}
/**
* 查看某个对象是否为空支持数组集合map
*
* @param object
* @deprecated 无泛型 instanceof 判断
*/
@Deprecated
public static boolean notEmpty(Object object) {
if (object == null) {
return false;
public static <T> boolean isEmpty(T[] array) {
return array != null && array.length == 0;
}
if (object instanceof Collection) {
return !((Collection<?>) object).isEmpty();
public static <T> boolean isNotEmpty(T[] array) {
return !isEmpty(array);
}
if (ClassUtil.isArray(object.getClass())) {
return Array.getLength(object) > 0;
public static boolean isEmpty(Map<?, ?> map) {
return map != null && map.isEmpty();
}
if (object instanceof Map) {
return !((Map<?, ?>) object).isEmpty();
public static boolean isNotEmpty(Map<?, ?> map) {
return !isEmpty(map);
}
if (object instanceof String) {
return StringUtil.isNotBlank((String) object);
}
return true;
public static boolean isEmpty(Collection<?> collection) {
return collection != null && collection.isEmpty();
}
/**
* 查看某个对象是否为空数据 或者 null
*
* @param object
* @deprecated 无泛型 instanceof 判断
*/
@Deprecated
public static boolean isEmpty(Object object) {
return !notEmpty(object);
public static boolean isNotEmpty(Collection<?> collection) {
return !isEmpty(collection);
}
/**
* 查看某个 string 对象是否有文本内容
*
* @param object
*/
public static boolean hasText(Object object) {
return object != null && StringUtil.isNotBlank((String) object);
public static boolean hasText(String string) {
return StringUtil.isNotBlank(string);
}
}

View File

@ -18,13 +18,9 @@ package com.mybatisflex.core.query;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.mybatis.Mappers;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.table.TableInfo;
import com.mybatisflex.core.table.TableInfoFactory;
import java.util.List;
import java.util.Optional;
/**
* {@link QueryWrapper} 链式调用
*
@ -58,70 +54,6 @@ public class QueryChain<T> extends QueryWrapperAdapter<QueryChain<T>> implements
return this;
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public T oneWithRelations() {
return baseMapper.selectOneWithRelationsByQuery(this);
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public <R> R oneWithRelationsAs(Class<R> asType) {
return baseMapper.selectOneWithRelationsByQueryAs(this, asType);
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public Optional<T> oneWithRelationsOpt() {
return Optional.ofNullable(baseMapper.selectOneWithRelationsByQuery(this));
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public <R> Optional<R> oneWithRelationsAsOpt(Class<R> asType) {
return Optional.ofNullable(baseMapper.selectOneWithRelationsByQueryAs(this, asType));
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public List<T> listWithRelations() {
return baseMapper.selectListWithRelationsByQuery(this);
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public <R> List<R> listWithRelationsAs(Class<R> asType) {
return baseMapper.selectListWithRelationsByQueryAs(this, asType);
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public Page<T> pageWithRelations(Page<T> page) {
return baseMapper.paginateWithRelations(page, this);
}
/**
* @deprecated 该方法将在 1.6.0 版本移除
*/
@Deprecated
public <R> Page<R> pageWithRelationsAs(Page<R> page, Class<R> asType) {
return baseMapper.paginateWithRelationsAs(page, this, asType);
}
@Override
public String toSQL() {
TableInfo tableInfo = TableInfoFactory.ofMapperClass(baseMapper.getClass());

View File

@ -27,7 +27,6 @@ import com.mybatisflex.core.util.StringUtil;
import java.lang.reflect.Array;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
public class QueryCondition implements CloneSupport<QueryCondition> {
@ -126,38 +125,6 @@ public class QueryCondition implements CloneSupport<QueryCondition> {
return this;
}
/**
* <p>动态条件构造
*
* <p>推荐将 {@link Predicate} 推断写在填写的值的后面以确保泛型对应例如
* <pre>{@code
* ACCOUNT.ID.in(idList, CollectionUtil::isNotEmpty);
* }</pre>
*
* @see #when(boolean)
* @see #when(BooleanSupplier)
* @deprecated 由于 {@link QueryCondition} 中属性 {@link #value} 的类型为 Object
* 类型没有使用泛型所以该方法泛型推断可能会出现问题
*/
@Deprecated
@SuppressWarnings("unchecked")
public <T> QueryCondition when(Predicate<T> fn) {
Object val = this.value;
if ((SqlConsts.LIKE.equals(logic) || SqlConsts.NOT_LIKE.equals(logic))
&& val instanceof String) {
String valStr = (String) val;
if (valStr.startsWith(SqlConsts.PERCENT_SIGN)) {
valStr = valStr.substring(1);
}
if (valStr.endsWith(SqlConsts.PERCENT_SIGN)) {
valStr = valStr.substring(0, valStr.length() - 1);
}
val = valStr;
}
this.effective = fn.test((T) val);
return this;
}
public boolean checkEffective() {
return effective;
}

View File

@ -41,12 +41,9 @@ import java.util.stream.Collectors;
public class DbChain extends QueryWrapperAdapter<DbChain> implements PropertySetter<DbChain> {
private String schema;
private String tableName;
private final String tableName;
private Row rowData;
private DbChain() {
}
private DbChain(String tableName) {
this.tableName = tableName;
}
@ -56,22 +53,12 @@ public class DbChain extends QueryWrapperAdapter<DbChain> implements PropertySet
this.tableName = tableName;
}
/**
* 覆盖 {@link QueryWrapper} 的静态方法仅用于查询必须使用 {@code from(...)} 方法指定表
*
* @deprecated 使用 {@code table(...)} 方法创建
*/
@Deprecated
public static DbChain create() {
return new DbChain();
throw new UnsupportedOperationException("please use DbChain#table(...)");
}
/**
* @deprecated 覆盖 {@link QueryWrapper} 的静态方法
*/
@Deprecated
public static DbChain create(Object entity) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("please use DbChain#table(...)");
}
public static DbChain table(String tableName) {

View File

@ -93,34 +93,6 @@ public interface IService<T> {
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::insertSelective));
}
/**
* <p>批量保存实体类对象数据
*
* @param entities 实体类对象
* @return {@code true} 保存成功{@code false} 保存失败
* @deprecated 为保持 Service API 一致性默认方法都是忽略实体类 {@code null} 属性的数据
* 另外该方法将在 1.6.0 版本被移除
*/
@Deprecated
default boolean saveBatchSelective(Collection<T> entities) {
return saveBatchSelective(entities, DEFAULT_BATCH_SIZE);
}
/**
* <p>批量保存实体类对象数据
*
* @param entities 实体类对象
* @param batchSize 每次保存切分的数量
* @return {@code true} 保存成功{@code false} 保存失败
* @deprecated 为保持 Service API 一致性默认方法都是忽略实体类 {@code null} 属性的数据
* 另外该方法将在 1.6.0 版本被移除
*/
@Deprecated
default boolean saveBatchSelective(Collection<T> entities, int batchSize) {
Class<BaseMapper<T>> usefulClass = (Class<BaseMapper<T>>) ClassUtil.getUsefulClass(getMapper().getClass());
return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::insertSelective));
}
/**
* <p>保存或者更新实体类对象数据
*

View File

@ -17,7 +17,6 @@
package com.mybatisflex.coretest;
import com.mybatisflex.core.query.*;
import com.mybatisflex.core.util.CollectionUtil;
import com.mybatisflex.core.util.StringUtil;
import org.junit.Test;
@ -52,7 +51,7 @@ public class DynamicConditionTest {
String sql = QueryWrapper.create()
.from(ACCOUNT)
.where(ACCOUNT.ID.in(idList).when(false))
.where(ACCOUNT.ID.in(idList, CollectionUtil::isNotEmpty))
.where(ACCOUNT.ID.in(idList, If::isNotEmpty))
.where(ACCOUNT.ID.in(idList).when(idList::isEmpty))
.toSQL();

View File

@ -134,13 +134,13 @@ public class EntityTestStarter {
.from(Article.class)
// .leftJoin(Account.class).as("a").on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID))
.leftJoin(Account.class).as("a").on(wrapper -> wrapper.where(Account::getId).eq(Article::getAccountId))
.where(Account::getId).ge(100, If::notEmpty)
.where(Account::getId).ge(100, If::notNull)
.and(wrapper -> {
wrapper.where(Account::getId).ge(100)
.or(Account::getAge).gt(200)
.and(Article::getAccountId).eq(200)
.or(wrapper1 -> {
wrapper1.where(Account::getId).like("a", If::notEmpty);
wrapper1.where(Account::getId).like("a", If::hasText);
})
;
});