Skip to content

Commit

Permalink
优化大量代码,添加大量单元测试,修复bug increment condition不生效 0.9.38
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed Jun 9, 2023
1 parent c51d3da commit 1be8573
Show file tree
Hide file tree
Showing 45 changed files with 942 additions and 276 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ QQ群:170029046
```xml

<properties>
<easy-query.version>0.9.37</easy-query.version>
<easy-query.version>0.9.38</easy-query.version>
</properties>
<dependency>
<groupId>com.easy-query</groupId>
Expand All @@ -65,7 +65,7 @@ QQ群:170029046
```xml

<properties>
<easy-query.version>0.9.37</easy-query.version>
<easy-query.version>0.9.38</easy-query.version>
</properties>
<!-- 提供了以java语法强类型,如果不引用也可以使用只是无法使用lambda表达式来表示属性只能用字符串 -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.easy-query</groupId>
<artifactId>easy-query-all</artifactId>
<packaging>pom</packaging>
<version>0.9.37</version>
<version>0.9.38</version>
<name>easy-query</name>
<description>java object query distributed connector</description>
<url>https://github.com/xuejmnet/easy-query</url>
Expand Down
2 changes: 1 addition & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>easy-query-all</artifactId>
<groupId>com.easy-query</groupId>
<version>0.9.37</version>
<version>0.9.38</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion samples/springbootdemo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>com.easy-query</groupId>
<artifactId>sql-springboot-starter</artifactId>
<version>0.9.37</version>
<version>0.9.38</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void test1(){
@GetMapping("/sayHello7")
public Object sayHello7() {
long l = easyQuery.deletable(TestUserMysql0.class)
.whereByIds("123321123321xxx3", "123321123321xxx2").allowDeleteStatement(true).disableLogicDelete()
.whereByIds(Arrays.asList("123321123321xxx3", "123321123321xxx2")).allowDeleteStatement(true).disableLogicDelete()
.noInterceptor().executeRows();

try(Transaction transaction = easyQuery.beginTransaction()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Object updateTrans() {
@GetMapping("/getTrans")
public Object getTrans() {
List<OrderDsEntity> list = easyQuery.queryable(OrderDsEntity.class)
.whereByIds("1", "2").toList();
.whereByIds(Arrays.asList("1", "2")).toList();

return list;
}
Expand Down
2 changes: 1 addition & 1 deletion sql-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>easy-query-all</artifactId>
<groupId>com.easy-query</groupId>
<version>0.9.37</version>
<version>0.9.38</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@ default ClientExpressionDeletable<T> where(SQLExpression1<WherePredicate<T>> whe
ClientExpressionDeletable<T> where(boolean condition, SQLExpression1<WherePredicate<T>> whereExpression);


default Deletable<T, ClientExpressionDeletable<T>> whereById(Object id) {
default ClientExpressionDeletable<T> whereById(Object id) {
return whereById(true, id);
}

Deletable<T, ClientExpressionDeletable<T>> whereById(boolean condition, Object id);
ClientExpressionDeletable<T> whereById(boolean condition, Object id);

default Deletable<T, ClientExpressionDeletable<T>> whereByIds(Object... ids) {
return whereByIds(true, ids);
}

Deletable<T, ClientExpressionDeletable<T>> whereByIds(boolean condition, Object... ids);

default <TProperty> Deletable<T, ClientExpressionDeletable<T>> whereByIdCollection(Collection<TProperty> ids) {
return whereByIdCollection(true, ids);
default <TProperty> ClientExpressionDeletable<T> whereByIds(Collection<TProperty> ids) {
return whereByIds(true, ids);
}

<TProperty> Deletable<T, ClientExpressionDeletable<T>> whereByIdCollection(boolean condition, Collection<TProperty> ids);
<TProperty> ClientExpressionDeletable<T> whereByIds(boolean condition, Collection<TProperty> ids);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.easy.query.core.basic.api.delete.abstraction;

import com.easy.query.core.basic.api.delete.Deletable;
import com.easy.query.core.basic.api.delete.ClientExpressionDeletable;
import com.easy.query.core.basic.api.internal.AbstractSQLExecuteRows;
import com.easy.query.core.basic.jdbc.executor.EntityExpressionExecutor;
Expand All @@ -10,7 +9,6 @@
import com.easy.query.core.enums.ExecuteMethodEnum;
import com.easy.query.core.enums.MultiTableTypeEnum;
import com.easy.query.core.enums.SQLPredicateCompareEnum;
import com.easy.query.core.exception.EasyQueryException;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.parser.core.base.WherePredicate;
import com.easy.query.core.expression.parser.core.base.impl.WherePredicateImpl;
Expand All @@ -22,12 +20,9 @@
import com.easy.query.core.expression.sql.builder.EntityTableExpressionBuilder;
import com.easy.query.core.expression.sql.builder.ExpressionContext;
import com.easy.query.core.metadata.EntityMetadata;
import com.easy.query.core.util.EasyClassUtil;
import com.easy.query.core.util.EasyCollectionUtil;
import com.easy.query.core.util.EasySQLExpressionUtil;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Function;

/**
Expand Down Expand Up @@ -91,52 +86,25 @@ public ClientExpressionDeletable<T> withVersion(boolean condition, Object versio
}

@Override
public Deletable<T, ClientExpressionDeletable<T>> whereById(boolean condition, Object id) {
public ClientExpressionDeletable<T> whereById(boolean condition, Object id) {

if (condition) {
PredicateSegment where = entityDeleteExpressionBuilder.getWhere();
String keyProperty = getSingleKeyPropertyName();
String keyProperty = EasySQLExpressionUtil.getSingleKeyPropertyName(table.getEntityTable());
AndPredicateSegment andPredicateSegment = new AndPredicateSegment();
andPredicateSegment
.setPredicate(new ColumnValuePredicate(table.getEntityTable(), keyProperty, id, SQLPredicateCompareEnum.EQ, entityDeleteExpressionBuilder.getRuntimeContext()));
where.addPredicateSegment(andPredicateSegment);
}
return this;
}
private String getSingleKeyPropertyName(){
Collection<String> keyProperties = table.getEntityMetadata().getKeyProperties();
if(EasyCollectionUtil.isEmpty(keyProperties)){
throw new EasyQueryException("对象:"+ EasyClassUtil.getSimpleName(clazz)+"未找到主键信息");
}
if(EasyCollectionUtil.isNotSingle(keyProperties)){
throw new EasyQueryException("对象:"+ EasyClassUtil.getSimpleName(clazz)+"存在多个主键");
}
return EasyCollectionUtil.first(keyProperties);
}

private Collection<?> extractIds(Object... ids) {
if (ids == null || ids.length == 0) {
return Collections.emptyList();
}
return Arrays.asList(ids);
}

@Override
public Deletable<T, ClientExpressionDeletable<T>> whereByIds(boolean condition, Object... ids) {
if (condition) {

Collection<?> extractIds = extractIds(ids);
return whereByIdCollection(true, extractIds);
}
return this;
}

@Override
public <TProperty> Deletable<T, ClientExpressionDeletable<T>> whereByIdCollection(boolean condition, Collection<TProperty> ids) {
public <TProperty> ClientExpressionDeletable<T> whereByIds(boolean condition, Collection<TProperty> ids) {

if (condition) {
PredicateSegment where = entityDeleteExpressionBuilder.getWhere();
String keyProperty = getSingleKeyPropertyName();
String keyProperty = EasySQLExpressionUtil.getSingleKeyPropertyName(table.getEntityTable());
AndPredicateSegment andPredicateSegment = new AndPredicateSegment();
andPredicateSegment
.setPredicate(new ColumnCollectionPredicate(table.getEntityTable(), keyProperty, ids, SQLPredicateCompareEnum.IN, entityDeleteExpressionBuilder.getRuntimeContext()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.easy.query.core.basic.api.internal.TableReNameable;
import com.easy.query.core.basic.api.select.provider.SQLExpressionProvider;
import com.easy.query.core.enums.sharding.ConnectionModeEnum;
import com.easy.query.core.exception.EasyQueryMultiPrimaryKeyException;
import com.easy.query.core.exception.EasyQueryNoPrimaryKeyException;
import com.easy.query.core.exception.EasyQueryOrderByInvalidOperationException;
import com.easy.query.core.exception.EasyQueryWhereInvalidOperationException;
import com.easy.query.core.expression.lambda.SQLExpression1;
Expand Down Expand Up @@ -161,17 +163,35 @@ default ClientQueryable<T1> where(SQLExpression1<WherePredicate<T1>> whereExpres

ClientQueryable<T1> where(boolean condition, SQLExpression1<WherePredicate<T1>> whereExpression);

/**
* 根据id查询
*
* @param id
* @return
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
*/
default ClientQueryable<T1> whereById(Object id) {
return whereById(true, id);
}

/**
* 根据id进行查询
*
* @param condition 是否追加条件
* @param id 主键
* @return
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
*/
ClientQueryable<T1> whereById(boolean condition, Object id);

default ClientQueryable<T1> whereByIds(Object... ids) {
return whereByIds(true, ids);
}

ClientQueryable<T1> whereByIds(boolean condition, Object... ids);
/**
* 根据id集合进行查询
*
* @param ids
* @param <TProperty>
* @return
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
*/

default <TProperty> ClientQueryable<T1> whereByIds(Collection<TProperty> ids) {
return whereByIds(true, ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import com.easy.query.core.context.QueryRuntimeContext;
import com.easy.query.core.enums.*;
import com.easy.query.core.enums.sharding.ConnectionModeEnum;
import com.easy.query.core.exception.EasyQueryException;
import com.easy.query.core.exception.EasyQueryFirstOrNotNullException;
import com.easy.query.core.exception.EasyQueryOrderByInvalidOperationException;
import com.easy.query.core.exception.EasyQueryWhereInvalidOperationException;
import com.easy.query.core.exception.*;
import com.easy.query.core.expression.func.ColumnFunction;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.lambda.SQLExpression2;
Expand Down Expand Up @@ -370,7 +367,7 @@ public ClientQueryable<T1> whereById(boolean condition, Object id) {

PredicateSegment where = entityQueryExpressionBuilder.getWhere();
TableAvailable table = entityQueryExpressionBuilder.getTable(0).getEntityTable();
String keyProperty = getSingleKeyPropertyName(table);
String keyProperty = EasySQLExpressionUtil.getSingleKeyPropertyName(table);
AndPredicateSegment andPredicateSegment = new AndPredicateSegment();
andPredicateSegment
.setPredicate(new ColumnValuePredicate(table, keyProperty, id, SQLPredicateCompareEnum.EQ, entityQueryExpressionBuilder.getRuntimeContext()));
Expand All @@ -379,34 +376,13 @@ public ClientQueryable<T1> whereById(boolean condition, Object id) {
return this;
}


private String getSingleKeyPropertyName(TableAvailable table) {
Collection<String> keyProperties = table.getEntityMetadata().getKeyProperties();
if (EasyCollectionUtil.isEmpty(keyProperties)) {
throw new EasyQueryException("对象:" + EasyClassUtil.getSimpleName(t1Class) + "未找到主键信息");
}
if (EasyCollectionUtil.isNotSingle(keyProperties)) {
throw new EasyQueryException("对象:" + EasyClassUtil.getSimpleName(t1Class) + "存在多个主键");
}
return EasyCollectionUtil.first(keyProperties);
}

@Override
public ClientQueryable<T1> whereByIds(boolean condition, Object... ids) {
if (condition) {
Collection<?> extractIds = extractIds(ids);
return whereByIds(true, extractIds);
}
return this;
}

@Override
public <TProperty> ClientQueryable<T1> whereByIds(boolean condition, Collection<TProperty> ids) {

if (condition) {
PredicateSegment where = entityQueryExpressionBuilder.getWhere();
TableAvailable table = entityQueryExpressionBuilder.getTable(0).getEntityTable();
String keyProperty = getSingleKeyPropertyName(table);
String keyProperty = EasySQLExpressionUtil.getSingleKeyPropertyName(table);
AndPredicateSegment andPredicateSegment = new AndPredicateSegment();
andPredicateSegment
.setPredicate(new ColumnCollectionPredicate(table, keyProperty, ids, SQLPredicateCompareEnum.IN, entityQueryExpressionBuilder.getRuntimeContext()));
Expand All @@ -415,14 +391,6 @@ public <TProperty> ClientQueryable<T1> whereByIds(boolean condition, Collection<
return this;
}


private Collection<?> extractIds(Object... ids) {
if (ids == null || ids.length == 0) {
return Collections.emptyList();
}
return Arrays.asList(ids);
}

/**
* 匹配
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ default ClientExpressionUpdatable<T> whereById(Object id) {

ClientExpressionUpdatable<T> whereById(boolean condition, Object id);


default ClientExpressionUpdatable<T> whereByIds(Object... ids) {
return whereByIds(true, ids);
}

ClientExpressionUpdatable<T> whereByIds(boolean condition, Object... ids);

default <TProperty> ClientExpressionUpdatable<T> whereByIds(Collection<TProperty> ids) {
return whereByIds(true, ids);
}
Expand Down
Loading

0 comments on commit 1be8573

Please sign in to comment.