/** * 处理WithItem * * @param withItemsList */ public void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
@Override public void visit(SubSelect subSelect) { if (subSelect.isUseBrackets()) { buffer.append("("); } if (selectVisitor != null) { if (subSelect.getWithItemsList() != null) { buffer.append("WITH "); for (Iterator<WithItem> iter = subSelect.getWithItemsList().iterator(); iter. hasNext();) { iter.next().accept(selectVisitor); if (iter.hasNext()) { buffer.append(", "); } buffer.append(" "); } buffer.append(" "); } subSelect.getSelectBody().accept(selectVisitor); } if (subSelect.isUseBrackets()) { buffer.append(")"); } }
@Override public void visit(WithItem withItem) { otherItemNames.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); }
@Override public void visit(WithItem withItem) { if (withItem.isRecursive()) { buffer.append("RECURSIVE "); } buffer.append(withItem.getName()); if (withItem.getWithItemList() != null) { buffer.append(" ").append(PlainSelect. getStringList(withItem.getWithItemList(), true, true)); } buffer.append(" AS ("); withItem.getSelectBody().accept(this); buffer.append(")"); }
final public WithItem WithItem() throws ParseException { WithItem with = new WithItem(); String name = null; List selectItems = null; SelectBody selectBody = null; name = RelObjectName(); with.setName(name); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 79: jj_consume_token(79); selectItems = SelectItemsList(); jj_consume_token(80); with.setWithItemList(selectItems); break; default: jj_la1[48] = jj_gen; ; } jj_consume_token(K_AS); jj_consume_token(79); selectBody = SelectBody(); with.setSelectBody(selectBody); jj_consume_token(80); {if (true) return with;} throw new Error("Missing return statement in function"); }
@Override public void visit(WithItem withItem) throws Exception { // TODO: Redo this later. What's withItem list. // Add with name here. if (withItem.getName() != null) { this.withTableNameList.add(withItem.getName()); } withItem.getSelectBody().accept(this); if (withItem.getWithItemList() != null) { for (SelectItem selectItem : withItem.getWithItemList()) { selectItem.accept(this); } } }
final public WithItem WithItem() throws ParseException {WithItem with = new WithItem(); String name = null; List selectItems = null; name = RelObjectName(); if (token.specialToken != null) { with.setCommentName(token.specialToken.image); with.setName(name); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case LPAREN:{ tk = jj_consume_token(LPAREN); if (tk.specialToken != null) { with.setCommentBeginBracketWith(tk.specialToken.image); with.setCommentEndBracketWith(tk.specialToken.image); with.setWithItemList(selectItems); with.setCommentsCommaWith(commentComma); break; with.setCommentAs(tk.specialToken.image); with.setCommentBeginBracketAs(tk.specialToken.image); with.setSelectBody(selectBody); tk = jj_consume_token(RPAREN); if (tk.specialToken != null) { with.setCommentEndBracketAs(tk.specialToken.image);
@Override public void visit(WithItem withItem) { if (withItem.getSelectBody() != null) { withItem.getSelectBody().accept(this); } if (withItem.getWithItemList() != null) { withItem.getWithItemList().forEach(s -> s.accept(this)); } }
@Override public void visit(WithItem withItem) { if (withItem.isRecursive()) { buffer.append("RECURSIVE "); } buffer.append(withItem.getName()); if (withItem.getWithItemList() != null) { buffer.append(" ").append(PlainSelect. getStringList(withItem.getWithItemList(), true, true)); } buffer.append(" AS ("); withItem.getSelectBody().accept(this); buffer.append(")"); }
boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1));WithItem with = new WithItem(); String name = null; List<SelectItem> selectItems = null; case K_RECURSIVE:{ jj_consume_token(K_RECURSIVE); with.setRecursive(true); break; with.setName(name); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case 198:{ selectItems = SelectItemsList(); jj_consume_token(200); with.setWithItemList(selectItems); break; jj_consume_token(198); selectBody = SelectBody(); with.setSelectBody(selectBody); jj_consume_token(200); jjtree.closeNodeScope(jjtn000, true);
/** * select 语句处理 */ @Override public void processSelectBody(SelectBody selectBody) { if (selectBody instanceof PlainSelect) { processPlainSelect((PlainSelect) selectBody); } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; if (withItem.getSelectBody() != null) { processSelectBody(withItem.getSelectBody()); } } else { SetOperationList operationList = (SetOperationList) selectBody; if (operationList.getSelects() != null && operationList.getSelects().size() > 0) { operationList.getSelects().forEach(this::processSelectBody); } } }
@Override public void visit(WithItem withItem) { withTCEs.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); } };
final public WithItem WithItem() throws ParseException {WithItem with = new WithItem(); String name = null; List selectItems = null; SelectBody selectBody = null; name = RelObjectName(); with.setName(name); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case 79:{ jj_consume_token(79); selectItems = SelectItemsList(); jj_consume_token(80); with.setWithItemList(selectItems); break; } default: jj_la1[48] = jj_gen; ; } jj_consume_token(K_AS); jj_consume_token(79); selectBody = SelectBody(); with.setSelectBody(selectBody); jj_consume_token(80); {if ("" != null) return with;} throw new Error("Missing return statement in function"); }
@Override public void visit(SubSelect subSelect) { buffer.append("("); if (subSelect.getWithItemsList() != null && !subSelect.getWithItemsList().isEmpty()) { buffer.append("WITH "); for (Iterator<WithItem> iter = subSelect.getWithItemsList().iterator(); iter.hasNext();) { WithItem withItem = iter.next(); withItem.accept(this); if (iter.hasNext()) { buffer.append(","); } buffer.append(" "); } } subSelect.getSelectBody().accept(this); buffer.append(")"); Alias alias = subSelect.getAlias(); if (alias != null) { buffer.append(alias.toString()); } Pivot pivot = subSelect.getPivot(); if (pivot != null) { pivot.accept(this); } }
/** * extra order by and set default orderby to null * * @param selectBody */ public static List<OrderByElement> extraOrderBy(SelectBody selectBody) { if (selectBody instanceof PlainSelect) { List<OrderByElement> orderByElements = ((PlainSelect) selectBody).getOrderByElements(); ((PlainSelect) selectBody).setOrderByElements(null); return orderByElements; } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; if (withItem.getSelectBody() != null) { return extraOrderBy(withItem.getSelectBody()); } } else { SetOperationList operationList = (SetOperationList) selectBody; if (operationList.getSelects() != null && operationList.getSelects().size() > 0) { List<SelectBody> plainSelects = operationList.getSelects(); return extraOrderBy(plainSelects.get(plainSelects.size() - 1)); } } return null; } }
@Override public void visit(WithItem withItem) { otherItemNames.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); }
boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1));WithItem with = new WithItem(); String name = null; List<SelectItem> selectItems = null; case K_RECURSIVE:{ jj_consume_token(K_RECURSIVE); with.setRecursive(true); break; with.setName(name); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case 195:{ selectItems = SelectItemsList(); jj_consume_token(197); with.setWithItemList(selectItems); break; jj_consume_token(195); selectBody = SelectBody(); with.setSelectBody(selectBody); jj_consume_token(197); jjtree.closeNodeScope(jjtn000, true);
@Override public void visit(Select select) { selectDeParser.setBuffer(buffer); expressionDeParser.setSelectVisitor(selectDeParser); expressionDeParser.setBuffer(buffer); selectDeParser.setExpressionVisitor(expressionDeParser); if (select.getWithItemsList() != null && !select.getWithItemsList().isEmpty()) { buffer.append("WITH "); for (Iterator<WithItem> iter = select.getWithItemsList().iterator(); iter.hasNext();) { WithItem withItem = iter.next(); withItem.accept(selectDeParser); if (iter.hasNext()) { buffer.append(","); } buffer.append(" "); } } select.getSelectBody().accept(selectDeParser); }
/** * 处理selectBody去除Order by * * @param selectBody */ protected void processSelectBody(SelectBody selectBody, int level) { if (selectBody instanceof PlainSelect) { processPlainSelect((PlainSelect) selectBody, level + 1); } else if (selectBody instanceof WithItem) { WithItem withItem = (WithItem) selectBody; if (withItem.getSelectBody() != null) { processSelectBody(withItem.getSelectBody(), level + 1); } } else { SetOperationList operationList = (SetOperationList) selectBody; if (operationList.getSelects() != null && operationList.getSelects().size() > 0) { List<SelectBody> plainSelects = operationList.getSelects(); for (SelectBody plainSelect : plainSelects) { processSelectBody(plainSelect, level + 1); } } } }
@Override public void visit(WithItem withItem) { withTCEs.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); } };