-
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 logic to build query clause (#8)
Signed-off-by: Sean Sundberg <[email protected]>
- Loading branch information
Showing
2 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 21 additions & 1 deletion
22
src/main/java/com/ibm/openpages/support/util/query/Operation.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,15 +1,35 @@ | ||
package com.ibm.openpages.support.util.query; | ||
|
||
import com.ibm.openpages.support.models.IObjectType; | ||
import com.ibm.openpages.support.models.ResultValue; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public enum Operation { | ||
EQUAL("="); | ||
EQUALS("="), | ||
IN("IN", inValue -> (inValue instanceof List<?>) ? inValue : Collections.singletonList(inValue)); | ||
|
||
private final String value; | ||
private final Function<Object, Object> valueFormatter; | ||
|
||
Operation(String value) { | ||
this(value, in -> in); | ||
} | ||
|
||
Operation(String value, Function<Object, Object> valueFormatter) { | ||
this.value = value; | ||
this.valueFormatter = valueFormatter; | ||
} | ||
|
||
public String value() { | ||
return value; | ||
} | ||
|
||
public String toClause(IObjectType type, ResultValue field, Object inValue) { | ||
final Object value = valueFormatter.apply(inValue); | ||
|
||
return "[" + type.name() + "].[" + field.baseValue() + "] " + this.value() + " " + 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