Skip to content

Commit 3def772

Browse files
author
talhadilber
committed
CriteriaType renamed to CriteriaOperator
1 parent 5662706 commit 3def772

File tree

9 files changed

+115
-111
lines changed

9 files changed

+115
-111
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<groupId>io.github.tdilber</groupId>
1515
<artifactId>spring-jpa-dynamic-query</artifactId>
16-
<version>0.3.0</version>
16+
<version>0.3.1</version>
1717
<packaging>jar</packaging>
1818
<name>Spring Jpa Dynamic Query</name>
1919
<description>Spring Jpa Dynamic Query Project</description>

src/main/java/com/beyt/dto/Criteria.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.beyt.dto;
22

33

4-
import com.beyt.dto.enums.CriteriaType;
4+
import com.beyt.dto.enums.CriteriaOperator;
55
import lombok.Getter;
66
import lombok.Setter;
77

@@ -17,23 +17,27 @@
1717
@Setter
1818
public class Criteria implements Serializable {
1919
protected String key;
20-
protected CriteriaType operation;
20+
protected CriteriaOperator operation;
2121
protected List<Object> values;
2222

23-
public static Criteria of(String key, CriteriaType operation, Collection<Object> values) {
23+
public static Criteria of(String key, CriteriaOperator operation, Collection<Object> values) {
2424
return new Criteria(key, operation, values);
2525
}
2626

27-
public static Criteria of(String key, CriteriaType operation, Object... values) {
27+
public static Criteria of(String key, CriteriaOperator operation, Object... values) {
2828
return new Criteria(key, operation, values);
2929
}
3030

31-
public Criteria(String key, CriteriaType operation, Object... values) {
31+
public Criteria(String key, CriteriaOperator operation, Object... values) {
3232
this.key = key;
3333
this.operation = operation;
3434
this.values = values != null ? Arrays.asList(values) : null;
3535
}
3636

37+
public static Criteria OR() {
38+
return Criteria.of("", CriteriaOperator.OR);
39+
}
40+
3741
public Criteria() {
3842

3943
}

src/main/java/com/beyt/dto/CriteriaList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.beyt.dto;
22

3-
import com.beyt.dto.enums.CriteriaType;
3+
import com.beyt.dto.enums.CriteriaOperator;
44
import lombok.extern.slf4j.Slf4j;
55

66
import java.io.Serializable;
@@ -27,7 +27,7 @@ public static CriteriaList of(Collection<Criteria> criteria) {
2727
return criteriaList;
2828
}
2929

30-
public List<Criteria> getCriteriaListByKeyAndOperation(String key, CriteriaType operation) {
30+
public List<Criteria> getCriteriaListByKeyAndOperation(String key, CriteriaOperator operation) {
3131
ArrayList<Criteria> criterias = new ArrayList<>();
3232

3333
for (Criteria criteria : this) {

src/main/java/com/beyt/dto/enums/CriteriaType.java renamed to src/main/java/com/beyt/dto/enums/CriteriaOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* Created by tdilber at 15-Sep-19
66
*/
7-
public enum CriteriaType {
7+
public enum CriteriaOperator {
88
CONTAIN(1, "İçeriyor (String)"),
99
DOES_NOT_CONTAIN(2, "İçermiyor (String)"),
1010
END_WITH(3, "İle bitiyor (String)"),
@@ -22,7 +22,7 @@ public enum CriteriaType {
2222
private int value = -1;
2323
private String meaning;
2424

25-
CriteriaType(int value, String meaning) {
25+
CriteriaOperator(int value, String meaning) {
2626
this.value = value;
2727
this.meaning = meaning;
2828
}

src/main/java/com/beyt/query/DynamicQueryManager.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.beyt.dto.Criteria;
44
import com.beyt.dto.DynamicQuery;
5-
import com.beyt.dto.enums.CriteriaType;
5+
import com.beyt.dto.enums.CriteriaOperator;
66
import com.beyt.query.rule.specification.*;
77
import com.beyt.repository.DynamicSpecificationRepositoryImpl;
88
import com.beyt.util.ApplicationContextUtil;
@@ -39,22 +39,22 @@
3939
@Slf4j
4040
public class DynamicQueryManager {
4141

42-
public final static Map<CriteriaType, ISpecificationFilterRule> specificationRuleMap = new HashMap<>();
42+
public final static Map<CriteriaOperator, ISpecificationFilterRule> specificationRuleMap = new HashMap<>();
4343

4444
static {
45-
specificationRuleMap.put(CriteriaType.CONTAIN, new SpecificationFilterDoubleLikeRule());
46-
specificationRuleMap.put(CriteriaType.DOES_NOT_CONTAIN, new SpecificationFilterDoesNotContainRule());
47-
specificationRuleMap.put(CriteriaType.END_WITH, new SpecificationFilterLeftLikeRule());
48-
specificationRuleMap.put(CriteriaType.START_WITH, new SpecificationFilterRightLikeRule());
49-
specificationRuleMap.put(CriteriaType.SPECIFIED, new SpecificationFilterSpecifiedRule());
50-
specificationRuleMap.put(CriteriaType.EQUAL, new SpecificationFilterEqualRule());
51-
specificationRuleMap.put(CriteriaType.NOT_EQUAL, new SpecificationFilterNotEqualRule());
52-
specificationRuleMap.put(CriteriaType.GREATER_THAN, new SpecificationFilterGreaterThanRule());
53-
specificationRuleMap.put(CriteriaType.GREATER_THAN_OR_EQUAL, new SpecificationFilterGreaterThanOrEqualToRule());
54-
specificationRuleMap.put(CriteriaType.LESS_THAN, new SpecificationFilterLessThanRule());
55-
specificationRuleMap.put(CriteriaType.LESS_THAN_OR_EQUAL, new SpecificationFilterLessThanOrEqualToRule());
56-
specificationRuleMap.put(CriteriaType.OR, null);
57-
specificationRuleMap.put(CriteriaType.PARENTHES, null);
45+
specificationRuleMap.put(CriteriaOperator.CONTAIN, new SpecificationFilterDoubleLikeRule());
46+
specificationRuleMap.put(CriteriaOperator.DOES_NOT_CONTAIN, new SpecificationFilterDoesNotContainRule());
47+
specificationRuleMap.put(CriteriaOperator.END_WITH, new SpecificationFilterLeftLikeRule());
48+
specificationRuleMap.put(CriteriaOperator.START_WITH, new SpecificationFilterRightLikeRule());
49+
specificationRuleMap.put(CriteriaOperator.SPECIFIED, new SpecificationFilterSpecifiedRule());
50+
specificationRuleMap.put(CriteriaOperator.EQUAL, new SpecificationFilterEqualRule());
51+
specificationRuleMap.put(CriteriaOperator.NOT_EQUAL, new SpecificationFilterNotEqualRule());
52+
specificationRuleMap.put(CriteriaOperator.GREATER_THAN, new SpecificationFilterGreaterThanRule());
53+
specificationRuleMap.put(CriteriaOperator.GREATER_THAN_OR_EQUAL, new SpecificationFilterGreaterThanOrEqualToRule());
54+
specificationRuleMap.put(CriteriaOperator.LESS_THAN, new SpecificationFilterLessThanRule());
55+
specificationRuleMap.put(CriteriaOperator.LESS_THAN_OR_EQUAL, new SpecificationFilterLessThanOrEqualToRule());
56+
specificationRuleMap.put(CriteriaOperator.OR, null);
57+
specificationRuleMap.put(CriteriaOperator.PARENTHES, null);
5858
}
5959

6060
public static <Entity> List<Entity> findAll(JpaSpecificationExecutor<Entity> repositoryExecutor,
@@ -330,7 +330,7 @@ protected static <Entity> Class<Entity> getEntityClass(JpaSpecificationExecutor<
330330
}
331331
}
332332

333-
protected static <M extends Map<CriteriaType, ?>> List<Criteria> getMapSpecificRules(M map, List<Criteria> searchCriteriaList) {
333+
protected static <M extends Map<CriteriaOperator, ?>> List<Criteria> getMapSpecificRules(M map, List<Criteria> searchCriteriaList) {
334334
List<Criteria> result = new ArrayList<>();
335335

336336
for (Criteria criteria : searchCriteriaList) {

src/main/java/com/beyt/query/DynamicSpecification.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.beyt.query;
22

33
import com.beyt.dto.Criteria;
4-
import com.beyt.dto.enums.CriteriaType;
4+
import com.beyt.dto.enums.CriteriaOperator;
55
import com.beyt.dto.enums.JoinType;
66
import com.beyt.exception.*;
77
import com.beyt.util.ApplicationContextUtil;
@@ -39,15 +39,15 @@ public Predicate toPredicate(Root<Entity> root, CriteriaQuery<?> query, Criteria
3939
List<Predicate> predicateAndList = new ArrayList<>();
4040
List<Predicate> predicateOrList = new ArrayList<>();
4141
for (int i = 0; i < criteriaList.size(); i++) {
42-
if (criteriaList.get(i).getOperation() == CriteriaType.PARENTHES) {
42+
if (criteriaList.get(i).getOperation() == CriteriaOperator.PARENTHES) {
4343
SpecificationUtil.checkHasFirstValue(criteriaList.get(i));
4444
try {
4545
predicateAndList.add(new DynamicSpecification<Entity>(((List<Criteria>) (criteriaList.get(i).getValues().get(0))), joinMap).toPredicate(root, query, builder));
4646
} catch (Exception e) {
4747
throw new DynamicQueryNoAvailableParenthesesOperationUsageException(
4848
"There is No Available Paranthes Operation Usage in Criteria Key: " + criteriaList.get(i).getKey());
4949
}
50-
} else if (criteriaList.get(i).getOperation() == CriteriaType.OR) {
50+
} else if (criteriaList.get(i).getOperation() == CriteriaOperator.OR) {
5151
if (i == 0 || i + 1 == criteriaList.size()) {
5252
throw new DynamicQueryNoAvailableOrOperationUsageException(
5353
"There is No Available OR Operation Usage in Criteria Key: " + criteriaList.get(i).getKey());
@@ -117,7 +117,7 @@ public static String getFieldName(String key) {
117117
}
118118

119119
protected Predicate addPredicate(Path<?> root, CriteriaBuilder builder, Criteria criteria) {
120-
if (!criteria.getOperation().equals(CriteriaType.SPECIFIED)) {
120+
if (!criteria.getOperation().equals(CriteriaOperator.SPECIFIED)) {
121121
try {
122122
criteria.setValues(deserialize(root.get(criteria.getKey()).getJavaType(), criteria.getValues()));
123123
} catch (Exception e) {

src/main/java/com/beyt/query/builder/QuerySimplifier.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.beyt.query.builder;
22

33
import com.beyt.dto.Criteria;
4-
import com.beyt.dto.enums.CriteriaType;
4+
import com.beyt.dto.enums.CriteriaOperator;
55
import com.beyt.dto.enums.Order;
66
import com.beyt.query.DynamicSpecification;
77
import lombok.AllArgsConstructor;
@@ -11,14 +11,14 @@
1111
import java.util.Arrays;
1212

1313
public class QuerySimplifier {
14-
public static final Criteria OR = Criteria.of("", CriteriaType.OR);
14+
public static final Criteria OR = Criteria.OR();
1515

1616
public static Field Field(String name) {
1717
return new Field(name);
1818
}
1919

2020
public static Criteria Parantesis(Criteria... criterias) {
21-
return Criteria.of("", CriteriaType.PARENTHES, Arrays.asList(criterias));
21+
return Criteria.of("", CriteriaOperator.PARENTHES, Arrays.asList(criterias));
2222
}
2323

2424
public static OrderByRule OrderBy(String fieldName, Order orderType) {
@@ -57,55 +57,55 @@ public Field(String name) {
5757
}
5858

5959
public Criteria eq(Object... values) {
60-
return Criteria.of(name, CriteriaType.EQUAL, values);
60+
return Criteria.of(name, CriteriaOperator.EQUAL, values);
6161
}
6262

6363
public Criteria notEq(Object... values) {
64-
return Criteria.of(name, CriteriaType.NOT_EQUAL, values);
64+
return Criteria.of(name, CriteriaOperator.NOT_EQUAL, values);
6565
}
6666

6767
public Criteria contain(Object... values) {
68-
return Criteria.of(name, CriteriaType.CONTAIN, values);
68+
return Criteria.of(name, CriteriaOperator.CONTAIN, values);
6969
}
7070

7171
public Criteria doesNotContain(Object... values) {
72-
return Criteria.of(name, CriteriaType.DOES_NOT_CONTAIN, values);
72+
return Criteria.of(name, CriteriaOperator.DOES_NOT_CONTAIN, values);
7373
}
7474

7575
public Criteria endWith(Object... values) {
76-
return Criteria.of(name, CriteriaType.END_WITH, values);
76+
return Criteria.of(name, CriteriaOperator.END_WITH, values);
7777
}
7878

7979
public Criteria startWith(Object... values) {
80-
return Criteria.of(name, CriteriaType.START_WITH, values);
80+
return Criteria.of(name, CriteriaOperator.START_WITH, values);
8181
}
8282

8383
public Criteria specified(boolean value) {
84-
return Criteria.of(name, CriteriaType.SPECIFIED, value);
84+
return Criteria.of(name, CriteriaOperator.SPECIFIED, value);
8585
}
8686

8787
public Criteria isNull() {
88-
return Criteria.of(name, CriteriaType.SPECIFIED, false);
88+
return Criteria.of(name, CriteriaOperator.SPECIFIED, false);
8989
}
9090

9191
public Criteria nonNull() {
92-
return Criteria.of(name, CriteriaType.SPECIFIED, true);
92+
return Criteria.of(name, CriteriaOperator.SPECIFIED, true);
9393
}
9494

9595
public Criteria greaterThan(Object value) {
96-
return Criteria.of(name, CriteriaType.GREATER_THAN, value);
96+
return Criteria.of(name, CriteriaOperator.GREATER_THAN, value);
9797
}
9898

9999
public Criteria greaterThanOrEqual(Object value) {
100-
return Criteria.of(name, CriteriaType.GREATER_THAN_OR_EQUAL, value);
100+
return Criteria.of(name, CriteriaOperator.GREATER_THAN_OR_EQUAL, value);
101101
}
102102

103103
public Criteria lessThan(Object value) {
104-
return Criteria.of(name, CriteriaType.LESS_THAN, value);
104+
return Criteria.of(name, CriteriaOperator.LESS_THAN, value);
105105
}
106106

107107
public Criteria lessThanOrEqual(Object value) {
108-
return Criteria.of(name, CriteriaType.LESS_THAN_OR_EQUAL, value);
108+
return Criteria.of(name, CriteriaOperator.LESS_THAN_OR_EQUAL, value);
109109
}
110110
}
111111
}

src/main/java/com/beyt/resolver/CriteriaListArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.beyt.dto.Criteria;
44
import com.beyt.dto.CriteriaList;
5-
import com.beyt.dto.enums.CriteriaType;
5+
import com.beyt.dto.enums.CriteriaOperator;
66
import org.springframework.beans.factory.config.BeanDefinition;
77
import org.springframework.context.annotation.Role;
88
import org.springframework.core.MethodParameter;
@@ -37,7 +37,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
3737
String operation = webRequest.getParameter(operationField);
3838
String values = webRequest.getParameter(valuesField);
3939
if (key != null && operation != null && values != null) {
40-
Criteria criteria = new Criteria(key, CriteriaType.valueOf(operation), null);
40+
Criteria criteria = new Criteria(key, CriteriaOperator.valueOf(operation), null);
4141
criteria.setValues(Arrays.asList(values.split(",")));
4242
filter.add(criteria);
4343
} else {

0 commit comments

Comments
 (0)