Skip to content

update master #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## 0.3.35-SNAPSHOT
## 0.3.36-SNAPSHOT
* feat(GH-208): added EQ_, NE_, STARTS_, LIKE_, ENDS_ case insensitive string match criteria #210 [53c84dc](https://github.com/introproventures/graphql-jpa-query/commit/53c84dc9980f01cc037e2c81a418e74d4581bbfb)
* feat(GH-204): added LOWER predicate for case insensitive match (#206) [6ff6992](https://github.com/introproventures/graphql-jpa-query/commit/6ff699284a2340de0f22d7a5e447444e8347f0f7)
* fix(travis): changed to openjdk8 [8f1e36c](https://github.com/introproventures/graphql-jpa-query/commit/8f1e36c302a1083f11ff4342e96005ead23e38ef)
* docs(README): polish description [skip travis] [4ad2ad2](https://github.com/introproventures/graphql-jpa-query/commit/4ad2ad245659f3c6b78a9b119c1e791d99129925)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ While typical REST APIs require loading from multiple URLs, GraphQL APIs get all

JPA 2.1 (Java Persistence Annotation) is Java's standard solution to bridge the gap between object-oriented domain models and relational database systems.

GraphQL JPA Query creates a uniform query API across for your applications without being limited by a single data source. You can use it with multiple JPA compliant databases by instrumenting separate EntityManager for each DataSource and expose a single GraphQL Query Apis for your Web application domain using Spring Boot Auto Configuration magic.
GraphQL JPA Query creates a uniform query API for your applications without being limited by a single data source. You can use it with multiple JPA compliant databases by instrumenting a separate EntityManager for each DataSource and expose a single GraphQL Query Apis for your Web application domain using Spring Boot Auto Configuration magic.

Tested using JDK Versions
----------------------
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-dependencies</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-dependencies</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>
<artifactId>graphql-jpa-query-autoconfigure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-dependencies</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-dependencies</relativePath>
</parent>
<artifactId>graphql-jpa-query-build</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>graphql-jpa-query-dependencies</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-example-merge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-example-model-books/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>
<artifactId>graphql-jpa-query-example-model-books</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-example-model-starwars/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-example-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-graphiql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
</parent>
<artifactId>graphql-jpa-query-graphiql</artifactId>
</project>
2 changes: 1 addition & 1 deletion graphql-jpa-query-schema/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.35-SNAPSHOT</version>
<version>0.3.36-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,34 @@ private GraphQLInputType getWhereAttributeType(Attribute<?,?> attribute) {
if(attribute.getJavaType().equals(String.class)) {
builder.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.LIKE.name())
.description("Like criteria")
.description("Like criteria, case sensitive")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.LIKE_.name())
.description("Like criteria, case insensitive")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.LOWER.name())
.description("Case insensitive match criteria")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.EQ_.name())
.description("Case equals case insensitive match criteria")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.NE_.name())
.description("Not equals case insensitive match criteria")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.CASE.name())
.description("Case sensitive match criteria")
Expand All @@ -529,15 +547,27 @@ private GraphQLInputType getWhereAttributeType(Attribute<?,?> attribute) {
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.STARTS.name())
.description("Starts with criteria")
.description("Starts with criteria, case sensitive")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.STARTS_.name())
.description("Starts with criteria, case insensitive")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.ENDS.name())
.description("Ends with criteria")
.description("Ends with criteria, case sensitive")
.type(getAttributeInputType(attribute))
.build()
)
.field(GraphQLInputObjectField.newInputObjectField()
.name(Criteria.ENDS_.name())
.description("Ends with criteria, case insensitive")
.type(getAttributeInputType(attribute))
.build()
);
}
else if (attribute.getJavaMember().getClass().isAssignableFrom(Field.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.introproventures.graphql.jpa.query.schema.impl;


import java.lang.reflect.Constructor;
import java.math.BigDecimal;
import java.math.BigInteger;
Expand Down Expand Up @@ -130,43 +131,47 @@ protected Predicate getStringPredicate(Path<String> root, PredicateFilter filter
String compareValue = filter.getValue().toString();
Expression<String> fieldValue = root;

if (filter.getCriterias().contains(PredicateFilter.Criteria.IN)) {
CriteriaBuilder.In<Object> in = cb.in(root);
if (filter.anyMatch(Criteria.EQ_, Criteria.NE_, Criteria.LIKE_, Criteria.STARTS_, Criteria.ENDS_, Criteria.LOWER)) {
compareValue = compareValue.toLowerCase();
fieldValue = cb.lower(fieldValue);
};

if (filter.getCriterias().contains(Criteria.IN)) {
CriteriaBuilder.In<Object> in = cb.in(fieldValue);
return in.value(compareValue);
}
if (filter.getCriterias().contains(PredicateFilter.Criteria.NIN)) {
return cb.not(root.in(compareValue));
if (filter.getCriterias().contains(Criteria.NIN)) {
return cb.not(fieldValue.in(compareValue));
}

if (filter.getCriterias().contains(PredicateFilter.Criteria.EQ)) {
if (filter.anyMatch(Criteria.EQ, Criteria.LOWER, Criteria.EQ_)) {
return cb.equal(fieldValue, compareValue);
}
else if (filter.getCriterias().contains(PredicateFilter.Criteria.LOWER)) {
return cb.equal(cb.lower(fieldValue),
compareValue.toLowerCase());
}
else if (filter.getCriterias().contains(PredicateFilter.Criteria.NE)) {
else if (filter.anyMatch(Criteria.NE, Criteria.NE_)) {
return cb.notEqual(fieldValue, compareValue);
}
else if (filter.getCriterias().contains(PredicateFilter.Criteria.LIKE)) {
else if (filter.anyMatch(Criteria.LIKE, Criteria.LIKE_)) {
compareValue = "%" + compareValue + "%";
}
else if (filter.getCriterias().contains(PredicateFilter.Criteria.ENDS)) {
else if (filter.anyMatch(Criteria.STARTS, Criteria.STARTS_)) {
compareValue = compareValue + "%";
}
else if (filter.anyMatch(Criteria.ENDS, Criteria.ENDS_)) {
compareValue = "%" + compareValue;
}
else if (filter.getCriterias().contains(PredicateFilter.Criteria.EXACT)) {
else if (filter.anyMatch(Criteria.EXACT, Criteria.CASE)) {
// do nothing
}
// STARTS or empty (default)
} // default empty
else {
compareValue = compareValue + "%";
compareValue = "%";
}

return cb.like(fieldValue, compareValue);
}

return arrayValuePredicate;
}

protected Predicate getBooleanPredicate(Path<?> root, PredicateFilter filter) {
Boolean bool = (Boolean) filter.getValue();
if (filter.getCriterias().contains(PredicateFilter.Criteria.NE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.EnumSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class PredicateFilter implements Comparable<PredicateFilter>, Serializable {

Expand Down Expand Up @@ -53,9 +54,13 @@ public enum Criteria {
*/
EQ,
/**
* not equal (numbers, dates, booleans)
* not equal (numbers, dates, booleans, strings)
*/
NE,
/**
* not equal strings, case insensitive
*/
NE_,
/**
* case sensitive (strings)
*/
Expand All @@ -64,21 +69,35 @@ public enum Criteria {
* case insensitive match
* <pre>LOWER(field) = LOWER(SEARCH)</pre>
*/
LOWER,
LOWER, EQ_,
/**
* end of the string matches
* end of the string matches, case sensitive
*/
ENDS,
/**
* beginning of string matches
* end of the string matches, case insensitive
*/
ENDS_,
/**
* beginning of string matches, case sensitive
* <pre>LIKE SEARCH%</pre>
*/
STARTS,
/**
* any part of the string matches
* beginning of string matches, case insensitive
* <pre>LIKE SEARCH%</pre>
*/
STARTS_,
/**
* any part of the string matches, case sensitive
* <pre>LIKE %SEARCH%</pre>
*/
LIKE,
/**
* any part of the string matches, case insensitive
* <pre>LIKE %SEARCH%</pre>
*/
LIKE_,
/**
* full string match =
*/
Expand Down Expand Up @@ -151,4 +170,10 @@ public Set<Criteria> getCriterias() {
public int compareTo(PredicateFilter o) {
return this.getField().compareTo(o.getField());
}

public boolean anyMatch(Criteria...criterias) {
return Stream.of(criterias)
.anyMatch(criteria -> this.getCriterias()
.contains(criteria));
}
}
Loading