-
-
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.
#266 - creating base for compound join
- Loading branch information
Showing
9 changed files
with
176 additions
and
13 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
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
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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/homihq/db2rest/rest/read/processor/post/JoinWhereProcessor.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,34 @@ | ||
package com.homihq.db2rest.rest.read.processor.post; | ||
|
||
import com.homihq.db2rest.rest.read.dto.ReadContextV2; | ||
import com.homihq.db2rest.rest.read.processor.pre.ReadPreProcessor; | ||
import com.homihq.db2rest.rsql.operators.SimpleRSQLOperators; | ||
import com.homihq.db2rest.rsql.parser.WhereFilterVisitor; | ||
import cz.jirutka.rsql.parser.RSQLParser; | ||
import cz.jirutka.rsql.parser.ast.Node; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.mybatis.dynamic.sql.SqlCriterion; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
|
||
//@Component | ||
@Slf4j | ||
//@Order(6) | ||
public class JoinWhereProcessor implements ReadPreProcessor { | ||
@Override | ||
public void process(ReadContextV2 readContextV2) { | ||
if(StringUtils.isNotBlank(readContextV2.getFilter())) { | ||
|
||
log.info("**** Creating JOIN where condition *****"); | ||
|
||
Node rootNode = new RSQLParser(SimpleRSQLOperators.customOperators()).parse(readContextV2.getFilter()); | ||
|
||
SqlCriterion condition = rootNode | ||
.accept(new WhereFilterVisitor(readContextV2.getRootTable())); | ||
|
||
readContextV2.addWhereCondition(condition); | ||
|
||
} | ||
} | ||
} |
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
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
107 changes: 107 additions & 0 deletions
107
src/main/java/com/homihq/db2rest/rsql/parser/JoinWhereFilterVisitor.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,107 @@ | ||
package com.homihq.db2rest.rsql.parser; | ||
|
||
|
||
import com.homihq.db2rest.mybatis.MyBatisTable; | ||
import com.homihq.db2rest.rsql.operators.Operator; | ||
import com.homihq.db2rest.rsql.operators.RSQLOperatorHandlers; | ||
import cz.jirutka.rsql.parser.ast.*; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.mybatis.dynamic.sql.AndOrCriteriaGroup; | ||
import org.mybatis.dynamic.sql.SqlColumn; | ||
import org.mybatis.dynamic.sql.SqlCriterion; | ||
import org.mybatis.dynamic.sql.select.join.JoinCriterion; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.homihq.db2rest.schema.TypeMapperUtil.getColumnJavaType; | ||
import static com.homihq.db2rest.schema.TypeMapperUtil.getJdbcType; | ||
import static org.mybatis.dynamic.sql.SqlBuilder.*; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class JoinWhereFilterVisitor implements RSQLVisitor<JoinCriterion, Object> { | ||
private final MyBatisTable sqlTable; | ||
|
||
@Override | ||
public JoinCriterion visit(AndNode node, Object optionalParameter) { | ||
log.info("AndNode - {}", node); | ||
|
||
List<AndOrCriteriaGroup> criterionList = new ArrayList<>(); | ||
|
||
for (Node child : node.getChildren()) { | ||
//criterionList.add(and(child.accept(this, optionalParameter))); | ||
} | ||
|
||
//return processCriteriaGroup(criterionList); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public JoinCriterion visit(OrNode node, Object optionalParameter) { | ||
log.info("OrNode - {}", node); | ||
|
||
List<AndOrCriteriaGroup> criterionList = new ArrayList<>(); | ||
|
||
for (Node child : node.getChildren()) { | ||
//criterionList.add(or(child.accept(this, optionalParameter))); | ||
} | ||
|
||
//return processCriteriaGroup(criterionList); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public JoinCriterion visit(ComparisonNode comparisonNode, Object optionalParameter) { | ||
log.info("ComparisonNode - {}", comparisonNode); | ||
|
||
ComparisonOperator op = comparisonNode.getOperator(); | ||
String columnName = comparisonNode.getSelector(); | ||
|
||
Operator operatorHandler = RSQLOperatorHandlers.getOperatorHandler(op.getSymbol()); | ||
|
||
if (operatorHandler == null) { | ||
throw new IllegalArgumentException(String.format("Operator '%s' is invalid", op.getSymbol())); | ||
} | ||
|
||
SqlColumn<Object> column = | ||
SqlColumn.of(columnName, this.sqlTable, | ||
getJdbcType(this.sqlTable.findColumn(columnName))); | ||
|
||
|
||
//Java type | ||
Class<?> clazz = getColumnJavaType(sqlTable.getTable(), columnName); | ||
|
||
log.debug("Col - {} Clazz - {}",columnName , clazz); | ||
|
||
/* | ||
if (op.isMultiValue()) { | ||
return operatorHandler.handle(column, comparisonNode.getArguments(), clazz); | ||
} | ||
else { | ||
return operatorHandler.handle(column, comparisonNode.getArguments().get(0), clazz); | ||
} | ||
*/ | ||
|
||
return null; | ||
|
||
} | ||
|
||
private SqlCriterion processCriteriaGroup(List<AndOrCriteriaGroup> criterionList){ | ||
if(criterionList.isEmpty()){ | ||
throw new InternalError("criterionList should never be empty here"); | ||
} | ||
|
||
AndOrCriteriaGroup initialCriterion = criterionList.get(0); | ||
List<AndOrCriteriaGroup> criterionSiblings = criterionList.subList(1, criterionList.size()); | ||
if(!initialCriterion.subCriteria().isEmpty()){ | ||
throw new InternalError("Unexpected subCriteria found. Initial criterion should never contain subCriteria. This is most likely a coding bug."); | ||
} | ||
return group(initialCriterion.initialCriterion().orElseThrow(), criterionSiblings); | ||
} | ||
} |
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