Skip to content

Commit 1be8573

Browse files
committed
优化大量代码,添加大量单元测试,修复bug increment condition不生效 0.9.38
1 parent c51d3da commit 1be8573

File tree

45 files changed

+942
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+942
-276
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ QQ群:170029046
5252
```xml
5353

5454
<properties>
55-
<easy-query.version>0.9.37</easy-query.version>
55+
<easy-query.version>0.9.38</easy-query.version>
5656
</properties>
5757
<dependency>
5858
<groupId>com.easy-query</groupId>
@@ -65,7 +65,7 @@ QQ群:170029046
6565
```xml
6666

6767
<properties>
68-
<easy-query.version>0.9.37</easy-query.version>
68+
<easy-query.version>0.9.38</easy-query.version>
6969
</properties>
7070
<!-- 提供了以java语法强类型,如果不引用也可以使用只是无法使用lambda表达式来表示属性只能用字符串 -->
7171
<dependency>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>com.easy-query</groupId>
88
<artifactId>easy-query-all</artifactId>
99
<packaging>pom</packaging>
10-
<version>0.9.37</version>
10+
<version>0.9.38</version>
1111
<name>easy-query</name>
1212
<description>java object query distributed connector</description>
1313
<url>https://github.com/xuejmnet/easy-query</url>

samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>easy-query-all</artifactId>
77
<groupId>com.easy-query</groupId>
8-
<version>0.9.37</version>
8+
<version>0.9.38</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

samples/springbootdemo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<dependency>
5656
<groupId>com.easy-query</groupId>
5757
<artifactId>sql-springboot-starter</artifactId>
58-
<version>0.9.37</version>
58+
<version>0.9.38</version>
5959
<scope>compile</scope>
6060
</dependency>
6161
<!-- <dependency>-->

samples/springbootdemo/src/main/java/com/easyquery/springbootdemo/controller/EasyQueryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void test1(){
101101
@GetMapping("/sayHello7")
102102
public Object sayHello7() {
103103
long l = easyQuery.deletable(TestUserMysql0.class)
104-
.whereByIds("123321123321xxx3", "123321123321xxx2").allowDeleteStatement(true).disableLogicDelete()
104+
.whereByIds(Arrays.asList("123321123321xxx3", "123321123321xxx2")).allowDeleteStatement(true).disableLogicDelete()
105105
.noInterceptor().executeRows();
106106

107107
try(Transaction transaction = easyQuery.beginTransaction()){

samples/springbootdemo/src/main/java/com/easyquery/springbootdemo/controller/OrderDsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Object updateTrans() {
6363
@GetMapping("/getTrans")
6464
public Object getTrans() {
6565
List<OrderDsEntity> list = easyQuery.queryable(OrderDsEntity.class)
66-
.whereByIds("1", "2").toList();
66+
.whereByIds(Arrays.asList("1", "2")).toList();
6767

6868
return list;
6969
}

sql-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>easy-query-all</artifactId>
77
<groupId>com.easy-query</groupId>
8-
<version>0.9.37</version>
8+
<version>0.9.38</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

sql-core/src/main/java/com/easy/query/core/basic/api/delete/ClientExpressionDeletable.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,16 @@ default ClientExpressionDeletable<T> where(SQLExpression1<WherePredicate<T>> whe
2020
ClientExpressionDeletable<T> where(boolean condition, SQLExpression1<WherePredicate<T>> whereExpression);
2121

2222

23-
default Deletable<T, ClientExpressionDeletable<T>> whereById(Object id) {
23+
default ClientExpressionDeletable<T> whereById(Object id) {
2424
return whereById(true, id);
2525
}
2626

27-
Deletable<T, ClientExpressionDeletable<T>> whereById(boolean condition, Object id);
27+
ClientExpressionDeletable<T> whereById(boolean condition, Object id);
2828

29-
default Deletable<T, ClientExpressionDeletable<T>> whereByIds(Object... ids) {
30-
return whereByIds(true, ids);
31-
}
3229

33-
Deletable<T, ClientExpressionDeletable<T>> whereByIds(boolean condition, Object... ids);
34-
35-
default <TProperty> Deletable<T, ClientExpressionDeletable<T>> whereByIdCollection(Collection<TProperty> ids) {
36-
return whereByIdCollection(true, ids);
30+
default <TProperty> ClientExpressionDeletable<T> whereByIds(Collection<TProperty> ids) {
31+
return whereByIds(true, ids);
3732
}
3833

39-
<TProperty> Deletable<T, ClientExpressionDeletable<T>> whereByIdCollection(boolean condition, Collection<TProperty> ids);
34+
<TProperty> ClientExpressionDeletable<T> whereByIds(boolean condition, Collection<TProperty> ids);
4035
}

sql-core/src/main/java/com/easy/query/core/basic/api/delete/abstraction/AbstractClientExpressionDeletable.java

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.easy.query.core.basic.api.delete.abstraction;
22

3-
import com.easy.query.core.basic.api.delete.Deletable;
43
import com.easy.query.core.basic.api.delete.ClientExpressionDeletable;
54
import com.easy.query.core.basic.api.internal.AbstractSQLExecuteRows;
65
import com.easy.query.core.basic.jdbc.executor.EntityExpressionExecutor;
@@ -10,7 +9,6 @@
109
import com.easy.query.core.enums.ExecuteMethodEnum;
1110
import com.easy.query.core.enums.MultiTableTypeEnum;
1211
import com.easy.query.core.enums.SQLPredicateCompareEnum;
13-
import com.easy.query.core.exception.EasyQueryException;
1412
import com.easy.query.core.expression.lambda.SQLExpression1;
1513
import com.easy.query.core.expression.parser.core.base.WherePredicate;
1614
import com.easy.query.core.expression.parser.core.base.impl.WherePredicateImpl;
@@ -22,12 +20,9 @@
2220
import com.easy.query.core.expression.sql.builder.EntityTableExpressionBuilder;
2321
import com.easy.query.core.expression.sql.builder.ExpressionContext;
2422
import com.easy.query.core.metadata.EntityMetadata;
25-
import com.easy.query.core.util.EasyClassUtil;
26-
import com.easy.query.core.util.EasyCollectionUtil;
23+
import com.easy.query.core.util.EasySQLExpressionUtil;
2724

28-
import java.util.Arrays;
2925
import java.util.Collection;
30-
import java.util.Collections;
3126
import java.util.function.Function;
3227

3328
/**
@@ -91,52 +86,25 @@ public ClientExpressionDeletable<T> withVersion(boolean condition, Object versio
9186
}
9287

9388
@Override
94-
public Deletable<T, ClientExpressionDeletable<T>> whereById(boolean condition, Object id) {
89+
public ClientExpressionDeletable<T> whereById(boolean condition, Object id) {
9590

9691
if (condition) {
9792
PredicateSegment where = entityDeleteExpressionBuilder.getWhere();
98-
String keyProperty = getSingleKeyPropertyName();
93+
String keyProperty = EasySQLExpressionUtil.getSingleKeyPropertyName(table.getEntityTable());
9994
AndPredicateSegment andPredicateSegment = new AndPredicateSegment();
10095
andPredicateSegment
10196
.setPredicate(new ColumnValuePredicate(table.getEntityTable(), keyProperty, id, SQLPredicateCompareEnum.EQ, entityDeleteExpressionBuilder.getRuntimeContext()));
10297
where.addPredicateSegment(andPredicateSegment);
10398
}
10499
return this;
105100
}
106-
private String getSingleKeyPropertyName(){
107-
Collection<String> keyProperties = table.getEntityMetadata().getKeyProperties();
108-
if(EasyCollectionUtil.isEmpty(keyProperties)){
109-
throw new EasyQueryException("对象:"+ EasyClassUtil.getSimpleName(clazz)+"未找到主键信息");
110-
}
111-
if(EasyCollectionUtil.isNotSingle(keyProperties)){
112-
throw new EasyQueryException("对象:"+ EasyClassUtil.getSimpleName(clazz)+"存在多个主键");
113-
}
114-
return EasyCollectionUtil.first(keyProperties);
115-
}
116-
117-
private Collection<?> extractIds(Object... ids) {
118-
if (ids == null || ids.length == 0) {
119-
return Collections.emptyList();
120-
}
121-
return Arrays.asList(ids);
122-
}
123-
124-
@Override
125-
public Deletable<T, ClientExpressionDeletable<T>> whereByIds(boolean condition, Object... ids) {
126-
if (condition) {
127-
128-
Collection<?> extractIds = extractIds(ids);
129-
return whereByIdCollection(true, extractIds);
130-
}
131-
return this;
132-
}
133101

134102
@Override
135-
public <TProperty> Deletable<T, ClientExpressionDeletable<T>> whereByIdCollection(boolean condition, Collection<TProperty> ids) {
103+
public <TProperty> ClientExpressionDeletable<T> whereByIds(boolean condition, Collection<TProperty> ids) {
136104

137105
if (condition) {
138106
PredicateSegment where = entityDeleteExpressionBuilder.getWhere();
139-
String keyProperty = getSingleKeyPropertyName();
107+
String keyProperty = EasySQLExpressionUtil.getSingleKeyPropertyName(table.getEntityTable());
140108
AndPredicateSegment andPredicateSegment = new AndPredicateSegment();
141109
andPredicateSegment
142110
.setPredicate(new ColumnCollectionPredicate(table.getEntityTable(), keyProperty, ids, SQLPredicateCompareEnum.IN, entityDeleteExpressionBuilder.getRuntimeContext()));

sql-core/src/main/java/com/easy/query/core/basic/api/select/ClientQueryable.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.easy.query.core.basic.api.internal.TableReNameable;
99
import com.easy.query.core.basic.api.select.provider.SQLExpressionProvider;
1010
import com.easy.query.core.enums.sharding.ConnectionModeEnum;
11+
import com.easy.query.core.exception.EasyQueryMultiPrimaryKeyException;
12+
import com.easy.query.core.exception.EasyQueryNoPrimaryKeyException;
1113
import com.easy.query.core.exception.EasyQueryOrderByInvalidOperationException;
1214
import com.easy.query.core.exception.EasyQueryWhereInvalidOperationException;
1315
import com.easy.query.core.expression.lambda.SQLExpression1;
@@ -161,17 +163,35 @@ default ClientQueryable<T1> where(SQLExpression1<WherePredicate<T1>> whereExpres
161163

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

166+
/**
167+
* 根据id查询
168+
*
169+
* @param id
170+
* @return
171+
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
172+
*/
164173
default ClientQueryable<T1> whereById(Object id) {
165174
return whereById(true, id);
166175
}
167176

177+
/**
178+
* 根据id进行查询
179+
*
180+
* @param condition 是否追加条件
181+
* @param id 主键
182+
* @return
183+
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
184+
*/
168185
ClientQueryable<T1> whereById(boolean condition, Object id);
169186

170-
default ClientQueryable<T1> whereByIds(Object... ids) {
171-
return whereByIds(true, ids);
172-
}
173-
174-
ClientQueryable<T1> whereByIds(boolean condition, Object... ids);
187+
/**
188+
* 根据id集合进行查询
189+
*
190+
* @param ids
191+
* @param <TProperty>
192+
* @return
193+
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
194+
*/
175195

176196
default <TProperty> ClientQueryable<T1> whereByIds(Collection<TProperty> ids) {
177197
return whereByIds(true, ids);

0 commit comments

Comments
 (0)