-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
386 additions
and
9 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/homihq/db2rest/rest/read/model/DbWhere.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,7 @@ | ||
package com.homihq.db2rest.rest.read.model; | ||
|
||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public record DbWhere(String tableName, DbTable table, List<DbColumn> columns, Map<String,Object> paramMap) { } |
32 changes: 23 additions & 9 deletions
32
src/main/java/com/homihq/db2rest/rest/read/processor/pre/RootWhereProcessor.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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/homihq/db2rest/rest/read/processor/rsql/operator/CustomRSQLOperators.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,21 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator; | ||
|
||
import cz.jirutka.rsql.parser.ast.ComparisonOperator; | ||
import cz.jirutka.rsql.parser.ast.RSQLOperators; | ||
|
||
import java.util.Arrays; | ||
import java.util.Set; | ||
|
||
public class CustomRSQLOperators extends RSQLOperators { | ||
|
||
public static final ComparisonOperator LIKE = new ComparisonOperator("=like=", false); | ||
public static final ComparisonOperator START_WITH = new ComparisonOperator("=startWith=", false); | ||
public static final ComparisonOperator END_WITH = new ComparisonOperator("=endWith=", false); | ||
|
||
public static Set<ComparisonOperator> customOperators() { | ||
Set<ComparisonOperator> comparisonOperators = defaultOperators(); | ||
comparisonOperators.addAll(Arrays.asList(LIKE, START_WITH, END_WITH)); | ||
return comparisonOperators; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../com/homihq/db2rest/rest/read/processor/rsql/operator/handler/EndWithOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class EndWithOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " like "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + "'%" + value + "'"; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
.../com/homihq/db2rest/rest/read/processor/rsql/operator/handler/EqualToOperatorHandler.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,19 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class EqualToOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " = "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
|
||
Object vo = parseValue(value, type); | ||
|
||
paramMap.put(columnName, vo); | ||
|
||
return columnName + OPERATOR + PREFIX + columnName; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../db2rest/rest/read/processor/rsql/operator/handler/GreaterThanEqualToOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class GreaterThanEqualToOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " >= "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + parseValue(value, type); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../homihq/db2rest/rest/read/processor/rsql/operator/handler/GreaterThanOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class GreaterThanOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " > "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + parseValue(value, type); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
.../java/com/homihq/db2rest/rest/read/processor/rsql/operator/handler/InOperatorHandler.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,22 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class InOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " in "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return handle(columnName, Arrays.asList(value), type, paramMap); | ||
} | ||
|
||
@Override | ||
public String handle(String columnName, List<String> values, Class type, Map<String, Object> paramMap) { | ||
return columnName + " in (" + | ||
values.stream().map(value -> parseValue(value, type)).collect(Collectors.joining(",")) + ")"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ihq/db2rest/rest/read/processor/rsql/operator/handler/LessThanEqualToOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class LessThanEqualToOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " <= "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + parseValue(value, type); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...com/homihq/db2rest/rest/read/processor/rsql/operator/handler/LessThanOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class LessThanOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " < "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + parseValue(value, type); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ava/com/homihq/db2rest/rest/read/processor/rsql/operator/handler/LikeOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class LikeOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " like "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + "'%" + value + "%'"; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...m/homihq/db2rest/rest/read/processor/rsql/operator/handler/NotEqualToOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class NotEqualToOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " != "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + parseValue(value, type); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...va/com/homihq/db2rest/rest/read/processor/rsql/operator/handler/NotInOperatorHandler.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,23 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class NotInOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " not in "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return handle(columnName, Arrays.asList(value), type, paramMap); | ||
} | ||
|
||
@Override | ||
public String handle(String columnName, List<String> values, Class type, Map<String, Object> paramMap) { | ||
return columnName + " not in (" + | ||
values.stream().map(value -> parseValue(value, type)).collect(Collectors.joining(",")) + ")"; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...in/java/com/homihq/db2rest/rest/read/processor/rsql/operator/handler/OperatorHandler.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,31 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface OperatorHandler { | ||
|
||
String PREFIX = ":"; | ||
|
||
String handle(String columnName, String value, Class type, Map<String, Object> paramMap); | ||
|
||
default String handle(String columnName, List<String> value, Class type, Map<String, Object> paramMap) { | ||
return handle(columnName, value.get(0), type, paramMap); | ||
} | ||
|
||
default String parseValue(String value, Class type) { | ||
|
||
if (String.class == type) { | ||
return "'" + value + "'"; | ||
} | ||
else if (Boolean.class == type || boolean.class == type) { | ||
Boolean aBoolean = Boolean.valueOf(value); | ||
return aBoolean ? "1" : "0"; | ||
} | ||
else { | ||
return value; | ||
} | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...va/com/homihq/db2rest/rest/read/processor/rsql/operator/handler/RSQLOperatorHandlers.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,32 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
|
||
import static com.homihq.db2rest.rest.read.processor.rsql.operator.CustomRSQLOperators.*; | ||
import static cz.jirutka.rsql.parser.ast.RSQLOperators.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class RSQLOperatorHandlers { | ||
|
||
private static final Map<String, OperatorHandler> OPERATOR_HANDLER_MAP = new HashMap<>(); | ||
|
||
static { | ||
OPERATOR_HANDLER_MAP.put(EQUAL.getSymbol(), new EqualToOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(NOT_EQUAL.getSymbol(), new NotEqualToOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(IN.getSymbol(), new InOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(NOT_IN.getSymbol(), new NotInOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(GREATER_THAN.getSymbol(), new GreaterThanOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(GREATER_THAN_OR_EQUAL.getSymbol(), new GreaterThanEqualToOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(LESS_THAN.getSymbol(), new LessThanOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(LESS_THAN_OR_EQUAL.getSymbol(), new LessThanEqualToOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(LIKE.getSymbol(), new LikeOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(START_WITH.getSymbol(), new StartWithOperatorHandler()); | ||
OPERATOR_HANDLER_MAP.put(END_WITH.getSymbol(), new EndWithOperatorHandler()); | ||
|
||
} | ||
|
||
public static OperatorHandler getOperatorHandler(String symbol) { | ||
return OPERATOR_HANDLER_MAP.get(symbol); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...om/homihq/db2rest/rest/read/processor/rsql/operator/handler/StartWithOperatorHandler.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,14 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.operator.handler; | ||
|
||
import java.util.Map; | ||
|
||
public class StartWithOperatorHandler implements OperatorHandler { | ||
|
||
private static final String OPERATOR = " like "; | ||
|
||
@Override | ||
public String handle(String columnName, String value, Class type, Map<String, Object> paramMap) { | ||
return columnName + OPERATOR + "'" + value + "%'"; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/homihq/db2rest/rest/read/processor/rsql/parser/RSQLParserBuilder.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,13 @@ | ||
package com.homihq.db2rest.rest.read.processor.rsql.parser; | ||
|
||
import com.homihq.db2rest.rest.read.processor.rsql.operator.CustomRSQLOperators; | ||
|
||
import cz.jirutka.rsql.parser.RSQLParser; | ||
|
||
public class RSQLParserBuilder { | ||
|
||
public static RSQLParser newRSQLParser(){ | ||
return new RSQLParser(CustomRSQLOperators.customOperators()); | ||
} | ||
|
||
} |
Oops, something went wrong.