/** * 处理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(WithItem withItem) { otherItemNames.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); }
/** * 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) { 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(")"); }
/** * 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; } }
/** * 处理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); } } } }
/** * 处理selectBody去除Order by * * @param selectBody */ 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) { List<SelectBody> plainSelects = operationList.getSelects(); for (SelectBody plainSelect : plainSelects) { processSelectBody(plainSelect); } } if (!orderByHashParameters(operationList.getOrderByElements())) { operationList.setOrderByElements(null); } } }
@Override public void visit(WithItem withItem) { if (withItem!=null) { replace(withItem.getSelectBody(), cteName2Def, placeHolderTables); } }
/** * 处理WithItem * * @param withItemsList */ public void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
/** * 处理WithItem * * @param withItemsList */ public void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
/** * 处理WithItem * * @param withItemsList */ public void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
/** * 处理WithItem * * @param withItemsList */ protected void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
@Override public void visit(WithItem withItem) { withItem.getSelectBody().accept(this); }}); }
/** * 处理WithItem * * @param withItemsList */ public void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
/** * 处理WithItem * * @param withItems withItems */ private static void processWithItemsList(List<WithItem> withItems) { if (CollectionUtils.isEmpty(withItems)) { return; } withItems.forEach(item -> processSelectBody(item.getSelectBody())); }
/** * 处理WithItem * */ public void processWithItemsList(List<WithItem> withItemsList) { if (withItemsList != null && withItemsList.size() > 0) { for (WithItem item : withItemsList) { processSelectBody(item.getSelectBody()); } } }
@Override public void visit(WithItem withItem) { withTCEs.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); } };
@Override public void visit(WithItem withItem) { withTCEs.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); } };
@Override public void visit(WithItem withItem) { otherItemNames.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); }
@Override public void visit(WithItem withItem) { withTCEs.add(withItem.getName().toLowerCase()); withItem.getSelectBody().accept(this); } };