Skip to content

Commit 5b6eff2

Browse files
authored
Merge pull request #50 from hellojavaer/1.0.x
update
2 parents 59c94db + bb2c1f2 commit 5b6eff2

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

ddal-jsqlparser/src/main/java/org/hellojavaer/ddal/jsqlparser/JSQLParserAdapter.java

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ private ShardRouteInfo getRouteInfo(TableWrapper tab, Object sdValue) {
437437
@Override
438438
public void visit(Insert insert) {
439439
this.getStack().push(new FrameContext(StatementType.INSERT));
440-
super.visit(insert);
440+
visit0(insert);
441441
// route table
442442
List<Column> columns = insert.getColumns();
443443
if (columns != null) {
@@ -464,7 +464,7 @@ public void visit(Delete delete) {
464464
throw new IllegalStateException("no limit in sql: " + sql);
465465
}
466466
this.getStack().push(new FrameContext(StatementType.DELETE));
467-
super.visit(delete);
467+
visit0(delete);
468468
afterVisitBaseStatement();
469469
}
470470

@@ -474,7 +474,7 @@ public void visit(Update update) {
474474
throw new IllegalStateException("no limit in sql: " + sql);
475475
}
476476
this.getStack().push(new FrameContext(StatementType.UPDATE));
477-
super.visit(update);
477+
visit0(update);
478478
afterVisitBaseStatement();
479479
}
480480

@@ -485,14 +485,14 @@ public void visit(Select select) {
485485
throw new IllegalStateException("no limit in sql: " + sql);
486486
}
487487
this.getStack().push(new FrameContext(StatementType.SELECT));
488-
super.visit(select);
488+
visit0(select);
489489
afterVisitBaseStatement();
490490
}
491491

492492
@Override
493493
public void visit(SubSelect subSelect) {
494494
this.getStack().push(new FrameContext(StatementType.SELECT));
495-
super.visit(subSelect);
495+
visit0(subSelect);
496496
afterVisitBaseStatement();
497497

498498
}
@@ -572,46 +572,46 @@ private Object getRouteValue(Column column, Expression obj) {
572572
@Override
573573
public void visit(InExpression inExpression) {
574574
if (inExpression.isNot()) {
575-
super.visit(inExpression);
575+
visit0(inExpression);
576576
return;
577577
}
578578
Column column = (Column) inExpression.getLeftExpression();
579579
if (inExpression.getRightItemsList() instanceof ExpressionList) {
580580
TableWrapper tab = getTableFromContext(column);
581581
if (tab == null) {
582-
super.visit(inExpression);
582+
visit0(inExpression);
583583
return;
584584
}
585585
ExpressionList itemsList = (ExpressionList) inExpression.getRightItemsList();
586586
List<Expression> list = itemsList.getExpressions();
587587
if (list == null || list.isEmpty()) {
588-
super.visit(inExpression);
588+
visit0(inExpression);
589589
}
590590
for (Expression exp : list) {
591591
routeTable(tab, column, exp);
592592
}
593593
} else {
594-
super.visit(inExpression);
594+
visit0(inExpression);
595595
return;
596596
}
597597
}
598598

599599
@Override
600600
public void visit(Between between) {
601601
if (between.isNot()) {
602-
super.visit(between);
602+
visit0(between);
603603
return;
604604
}
605605
Column column = (Column) between.getLeftExpression();
606606
TableWrapper tab = getTableFromContext(column);
607607
if (tab == null) {
608-
super.visit(between);
608+
visit0(between);
609609
return;
610610
}
611611
Expression begin = between.getBetweenExpressionStart();
612612
Expression end = between.getBetweenExpressionEnd();
613613
if (begin instanceof SubSelect || end instanceof SubSelect) {
614-
super.visit(between);
614+
visit0(between);
615615
return;
616616
} else if ((begin instanceof JdbcParameter || begin instanceof JdbcNamedParameter) //
617617
|| (end instanceof JdbcParameter || end instanceof JdbcNamedParameter)) {
@@ -635,7 +635,7 @@ public void visit(Between between) {
635635
public void visit(EqualsTo equalsTo) {
636636
Column column = (Column) equalsTo.getLeftExpression();
637637
if (equalsTo.getRightExpression() instanceof SubSelect) {
638-
super.visit(equalsTo);
638+
visit0(equalsTo);
639639
return;
640640
} else {
641641
String fullColumnName = column.toString();
@@ -644,7 +644,7 @@ public void visit(EqualsTo equalsTo) {
644644
if (tab != null) {// 需要路由的table
645645
routeTable(tab, column, equalsTo.getRightExpression());
646646
} else {// there maybe contains sub query,so we show invoke super.visit
647-
super.visit(equalsTo);
647+
visit0(equalsTo);
648648
}
649649
}
650650
}
@@ -718,6 +718,38 @@ public void visit(Table table) {
718718
}
719719
}
720720

721+
protected void visit0(Select select) {
722+
super.visit(select);
723+
}
724+
725+
protected void visit0(SubSelect subSelect) {
726+
super.visit(subSelect);
727+
}
728+
729+
protected void visit0(Insert insert) {
730+
super.visit(insert);
731+
}
732+
733+
protected void visit0(Update update) {
734+
super.visit(update);
735+
}
736+
737+
protected void visit0(Delete delete) {
738+
super.visit(delete);
739+
}
740+
741+
protected void visit0(EqualsTo equalsTo) {
742+
super.visit(equalsTo);
743+
}
744+
745+
protected void visit0(InExpression inExpression) {
746+
super.visit(inExpression);
747+
}
748+
749+
protected void visit0(Between between) {
750+
super.visit(between);
751+
}
752+
721753
private void putIntoContext(FrameContext frameContext, String key, TableWrapper tab) {
722754
TableWrapper tab0 = frameContext.get(key);
723755
if (tab0 == null) {

0 commit comments

Comments
 (0)