????Select ????????
?????? SQLSelectStatement ????????????????????????????????????????
????????ζ????? Druid ??????????????????? Select ???????г????????
????Visitor
?????? demo ?????п???????????? AST ?????????????? visitor ????????
????// ???visitor??????AST
????MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
????statement.accept(visitor);
????System.out.println(visitor.getColumns());
????System.out.println(visitor.getOrderByColumns());
????statement ???? accept ???????? visitor ???????????????????á??????? statement ??????????? SQLSelectStatement ??
?????? Druid ?У???? SQL ????е?????????????λ?????ε???????????? SQLObject ??statement ????? SQLObject?????? expr ?????? SQLObject??????????Ρ???????????Щ??????? SQLObject??SQLObject ????????? accept ?????????????????????????÷?????????? SQLObject ?????????????Щ???飬???÷????????????????????????????? SQLObject ???Щ?????
????????? accept() ?????? SQLObjectImpl ??????У??????????????
????public final void accept(SQLASTVisitor visitor) {
????if (visitor == null) {
????throw new IllegalArgumentException();
????}
????visitor.preVisit(this);
????accept0(visitor);
????visitor.postVisit(this);
????}
??????????? final ????????ζ?????е??????????????壬???? accept ????????visitor ???????Щ???????????????????????? accept0() ??????????????? ?????? ??
??????????? Druid ??????η??? AST ??????? SQLSelectStatement ?? accept0() ??????????????
????protected void accept0(SQLASTVisitor visitor) {
????if (visitor.visit(this)) {
????acceptChild(visitor?? this.select);
????}
????visitor.endVisit(this);
????}
?????????? visitor ??????????????????visitor ????????????????????????
?????? MySqlSchemaStateVisitor ?? visit ???????????????visitor ?????Щ?£????????????? aliasMap????? return true??????ζ???????? SQLSelectStatement ??????
????public boolean visit(SQLSelectStatement x) {
????setAliasMap();
????return true;
????}
???????????????????
????protected final void acceptChild(SQLASTVisitor visitor?? SQLObject child) {
????if (child == null) {
????return;
????}
????child.accept(visitor);
????}
???????????????SQLObject ?????? visitor ????????????Щ?????? visitor ?????????????????У????????????????????