Skip to content

Commit

Permalink
refactor WhereClauseParser 2nd version
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 1, 2017
1 parent 8e2c6e1 commit 28c26f5
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,17 @@ private void parseComparisonCondition(final ShardingRule shardingRule, final SQL
lexerEngine.skipIfEqual(Symbol.RIGHT_PAREN);
return;
}
if (lexerEngine.skipIfEqual(Symbol.LT, Symbol.LT_EQ)) {
if (left instanceof SQLIdentifierExpression && sqlStatement instanceof SelectStatement
&& isRowNumberCondition(items, ((SQLIdentifierExpression) left).getName())) {
if (sqlStatement instanceof SelectStatement && isRowNumberCondition(items, left)) {
if (lexerEngine.skipIfEqual(Symbol.LT, Symbol.LT_EQ)) {
parseRowCountCondition((SelectStatement) sqlStatement);
} else if (left instanceof SQLPropertyExpression && sqlStatement instanceof SelectStatement
&& isRowNumberCondition(items, ((SQLPropertyExpression) left).getName())) {
parseRowCountCondition((SelectStatement) sqlStatement);
} else {
parseOtherCondition(sqlStatement);
return;
}
} else if (lexerEngine.skipIfEqual(Symbol.GT, Symbol.GT_EQ)) {
if (left instanceof SQLIdentifierExpression && sqlStatement instanceof SelectStatement
&& isRowNumberCondition(items, ((SQLIdentifierExpression) left).getName())) {
parseOffsetCondition((SelectStatement) sqlStatement);
} else if (left instanceof SQLPropertyExpression && sqlStatement instanceof SelectStatement
&& isRowNumberCondition(items, ((SQLPropertyExpression) left).getName())) {
if (lexerEngine.skipIfEqual(Symbol.GT, Symbol.GT_EQ)) {
parseOffsetCondition((SelectStatement) sqlStatement);
} else {
parseOtherCondition(sqlStatement);
return;
}
} else if (lexerEngine.skipIfEqual(Symbol.LT_GT, Symbol.BANG_EQ, Symbol.BANG_GT, Symbol.BANG_LT, DefaultKeyword.LIKE)) {
}
if (lexerEngine.skipIfEqual(Symbol.LT, Symbol.LT_EQ, Symbol.GT, Symbol.GT_EQ, Symbol.LT_GT, Symbol.BANG_EQ, Symbol.BANG_GT, Symbol.BANG_LT, DefaultKeyword.LIKE)) {
parseOtherCondition(sqlStatement);
}
lexerEngine.skipIfEqual(Symbol.RIGHT_PAREN);
Expand Down Expand Up @@ -148,6 +138,16 @@ private void parseBetweenCondition(final ShardingRule shardingRule, final SQLSta
}
}

private boolean isRowNumberCondition(final List<SelectItem> items, final SQLExpression sqlExpression) {
String columnLabel = null;
if (sqlExpression instanceof SQLIdentifierExpression) {
columnLabel = ((SQLIdentifierExpression) sqlExpression).getName();
} else if (sqlExpression instanceof SQLPropertyExpression) {
columnLabel = ((SQLPropertyExpression) sqlExpression).getName();
}
return null != columnLabel && isRowNumberCondition(items, columnLabel);
}

protected boolean isRowNumberCondition(final List<SelectItem> items, final String columnLabel) {
return false;
}
Expand Down

0 comments on commit 28c26f5

Please sign in to comment.