-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update QueryClause logic to inherit type if not provided (#9)
Signed-off-by: Sean Sundberg <[email protected]>
- Loading branch information
Showing
6 changed files
with
99 additions
and
52 deletions.
There are no files selected for viewing
30 changes: 7 additions & 23 deletions
30
src/main/java/com/ibm/openpages/support/util/query/AndQueryClause.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,21 @@ | ||
package com.ibm.openpages.support.util.query; | ||
|
||
import com.sun.org.apache.xpath.internal.operations.Or; | ||
import com.ibm.openpages.support.models.IObjectType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class AndQueryClause extends GroupQueryClause { | ||
private final List<QueryClause> clauses; | ||
|
||
protected AndQueryClause() { | ||
this(new ArrayList<>()); | ||
} | ||
protected AndQueryClause(QueryClause... clauses) { | ||
this(Arrays.asList(clauses)); | ||
} | ||
protected AndQueryClause(List<QueryClause> clauses) { | ||
this.clauses = clauses; | ||
} | ||
|
||
@Override | ||
public boolean isAnd() { | ||
return true; | ||
protected AndQueryClause(IObjectType type) { | ||
this(type, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public void add(QueryClause clause) { | ||
clauses.add(clause); | ||
protected AndQueryClause(IObjectType type, QueryClause... clauses) { | ||
this(type, Arrays.asList(clauses)); | ||
} | ||
|
||
@Override | ||
public String toClause() { | ||
return "(" + clauses.stream().map(QueryClause::toClause).collect(Collectors.joining(" AND ")) + ")"; | ||
protected AndQueryClause(IObjectType type, List<QueryClause> clauses) { | ||
super(true, type, clauses); | ||
} | ||
} |
37 changes: 34 additions & 3 deletions
37
src/main/java/com/ibm/openpages/support/util/query/GroupQueryClause.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,44 @@ | ||
package com.ibm.openpages.support.util.query; | ||
|
||
import com.ibm.openpages.support.models.IObjectType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class GroupQueryClause extends QueryClause { | ||
private final boolean and; | ||
private final List<QueryClause> clauses; | ||
|
||
protected GroupQueryClause(boolean and, IObjectType type) { | ||
this(and, type, new ArrayList<>()); | ||
} | ||
protected GroupQueryClause(boolean and, IObjectType type, QueryClause... clauses) { | ||
this(and, type, Arrays.asList(clauses)); | ||
} | ||
protected GroupQueryClause(boolean and, IObjectType type, List<QueryClause> clauses) { | ||
super(type); | ||
|
||
this.and = and; | ||
this.clauses = clauses; | ||
} | ||
|
||
public boolean isAnd() { | ||
return false; | ||
return and; | ||
} | ||
public boolean isOr() { | ||
return false; | ||
return !and; | ||
} | ||
|
||
public void add(QueryClause clause) { | ||
clauses.add(clause); | ||
} | ||
|
||
public abstract void add(QueryClause clause); | ||
@Override | ||
public String toClause() { | ||
final String delimiter = and ? " AND " : " OR "; | ||
|
||
return "(" + clauses.stream().map(QueryClause::toClause).collect(Collectors.joining(delimiter)) + ")"; | ||
} | ||
} |
30 changes: 8 additions & 22 deletions
30
src/main/java/com/ibm/openpages/support/util/query/OrQueryClause.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
package com.ibm.openpages.support.util.query; | ||
|
||
import com.ibm.openpages.support.models.IObjectType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class OrQueryClause extends GroupQueryClause { | ||
private final List<QueryClause> clauses; | ||
|
||
protected OrQueryClause() { | ||
this(new ArrayList<>()); | ||
} | ||
protected OrQueryClause(QueryClause... clauses) { | ||
this(Arrays.asList(clauses)); | ||
} | ||
protected OrQueryClause(List<QueryClause> clauses) { | ||
this.clauses = clauses; | ||
} | ||
|
||
@Override | ||
public boolean isOr() { | ||
return true; | ||
protected OrQueryClause(IObjectType type) { | ||
this(type, new ArrayList<>()); | ||
} | ||
|
||
@Override | ||
public void add(QueryClause clause) { | ||
clauses.add(clause); | ||
protected OrQueryClause(IObjectType type, QueryClause... clauses) { | ||
this(type, Arrays.asList(clauses)); | ||
} | ||
|
||
@Override | ||
public String toClause() { | ||
return "(" + clauses.stream().map(QueryClause::toClause).collect(Collectors.joining(" OR ")) + ")"; | ||
protected OrQueryClause(IObjectType type, List<QueryClause> clauses) { | ||
super(false, type, clauses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/ibm/openpages/support/util/query/QueryClauseType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ibm.openpages.support.util.query; | ||
|
||
import com.ibm.openpages.support.models.IObjectType; | ||
import com.ibm.openpages.support.models.ResultValue; | ||
|
||
public class QueryClauseType { | ||
|
||
private final IObjectType type; | ||
|
||
protected QueryClauseType(IObjectType type) { | ||
this.type = type; | ||
} | ||
|
||
public QueryClauseType forType(IObjectType type) { | ||
return new QueryClauseType(type); | ||
} | ||
|
||
public QueryClause where(ResultValue field, Operation operation, ResultValue value) { | ||
return where(field, operation, value.value()); | ||
} | ||
public QueryClause where(ResultValue field, Operation operation, Object value) { | ||
return new SimpleQueryClause(type, field, operation, value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters