Skip to content
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

feat: add support for builder pattern in QuerySpec #94

Merged
merged 2 commits into from
Jul 1, 2024
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
2 changes: 1 addition & 1 deletion backend-core-business-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>backend-core-business-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend-core-business-spring-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>backend-core-business-spring-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend-core-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>backend-core-business</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend-core-data-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>backend-core-data-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend-core-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>backend-core-data</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend-core-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>backend-core-model</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Accessors(chain=true)
public class QuerySpec {

public enum Order {
Expand All @@ -51,19 +52,22 @@ public enum Order {
@Getter
private final Collection<Constraint> constraints = new ArrayList<>();

public void addOrder(String property, Order order) {
public QuerySpec addOrder(String property, Order order) {
if (this.orders == null) {
this.orders = new LinkedHashMap<>();
}
this.orders.put(property, order);
return this;
}

public void addOrder(String property) {
public QuerySpec addOrder(String property) {
addOrder(property, Order.ASC);
return this;
}

public void addConstraint(Constraint constraint) {
public QuerySpec addConstraint(Constraint constraint) {
this.constraints.add(constraint);
return this;
}

@Override
Expand Down Expand Up @@ -107,18 +111,20 @@ public Integer getMaxResult() {
* @return the same query instance
* @throws IllegalArgumentException if the argument is negative
*/
public void setFirstResult(Integer firstResult) {
public QuerySpec setFirstResult(Integer firstResult) {
if (firstResult!=null && firstResult<0) throw new IllegalArgumentException();
this.firstResult = firstResult;
return this;
}

/**
* Set the maximum number of results to retrieve.
* @param maxResult maximum number of results to retrieve (may be null)
* @throws IllegalArgumentException if the argument is negative
*/
public void setMaxResult(Integer maxResult) {
public QuerySpec setMaxResult(Integer maxResult) {
if (maxResult!=null && maxResult<0) throw new IllegalArgumentException();
this.maxResult = maxResult;
return this;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.flowingcode.backend-core</groupId>
<artifactId>backend-core</artifactId>
<packaging>pom</packaging>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>Backend Core</name>
<description>Common utilities for backend enterprise application development</description>
<url>https://www.flowingcode.com/en/open-source/</url>
Expand Down
Loading