public static boolean visit(MappingVisitor visitor, SQLSelectQueryBlock x) { if (x.getSelectList().size() == 0) { fillSelectList(visitor, x); } if (x.getSelectList().size() == 1) { if (x.getSelectList().get(0).getExpr() instanceof SQLAllColumnExpr) { x.getSelectList().clear(); fillSelectList(visitor, x); } } if (x.getFrom() == null) { Entity firstEntity = visitor.getFirstEntity(); SQLExprTableSource from = new SQLExprTableSource(new SQLIdentifierExpr(firstEntity.getName())); x.setFrom(from); } for (SQLSelectItem item : x.getSelectList()) { item.setParent(x); } return true; }
public boolean visit(SQLSelectQueryBlock x) { if (x.getFrom() == null) { return false; } setMode(x, Mode.Select); if (x.getFrom() instanceof SQLSubqueryTableSource) { x.getFrom().accept(this); return false; } if (x.getInto() != null && x.getInto().getExpr() instanceof SQLName) { SQLName into = (SQLName) x.getInto().getExpr(); String ident = into.toString(); TableStat stat = getTableStat(ident); if (stat != null) { stat.incrementInsertCount(); } } String originalTable = getCurrentTable(); if (x.getFrom() instanceof SQLExprTableSource) { SQLExprTableSource tableSource = (SQLExprTableSource) x.getFrom(); if (tableSource.getExpr() instanceof SQLName) { String ident = tableSource.getExpr().toString(); setCurrentTable(x, ident); x.putAttribute(ATTR_TABLE, ident); if (x.getParent() instanceof SQLSelect) { x.getParent().putAttribute(ATTR_TABLE, ident); } x.putAttribute("_old_local_", originalTable); } } if (x.getFrom() != null) { x.getFrom().accept(this); // 提前执行,获得aliasMap String table = (String) x.getFrom().getAttribute(ATTR_TABLE); if (table != null) { x.putAttribute(ATTR_TABLE, table); } } // String ident = x.getTable().toString(); // // TableStat stat = getTableStat(ident); // stat.incrementInsertCount(); // return false; if (x.getWhere() != null) { x.getWhere().setParent(x); } return true; }
public static boolean visit(SQLEvalVisitor visitor, SQLQueryExpr x) { if (x.getSubQuery().getQuery() instanceof SQLSelectQueryBlock) { SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) x.getSubQuery().getQuery(); boolean nullFrom = false; if (queryBlock.getFrom() == null) { nullFrom = true; } else if (queryBlock.getFrom() instanceof SQLExprTableSource) { SQLExpr expr = ((SQLExprTableSource) queryBlock.getFrom()).getExpr(); if (expr instanceof SQLIdentifierExpr) { if ("dual".equalsIgnoreCase(((SQLIdentifierExpr) expr).getName())) { nullFrom = true; } } } if (nullFrom) { List<Object> row = new ArrayList<Object>(queryBlock.getSelectList().size()); for (int i = 0; i < queryBlock.getSelectList().size(); ++i) { SQLSelectItem item = queryBlock.getSelectList().get(i); item.getExpr().accept(visitor); Object cell = item.getExpr().getAttribute(EVAL_VALUE); row.add(cell); } List<List<Object>> rows = new ArrayList<List<Object>>(1); rows.add(row); Object result = rows; queryBlock.putAttribute(EVAL_VALUE, result); x.getSubQuery().putAttribute(EVAL_VALUE, result); x.putAttribute(EVAL_VALUE, result); return false; } } return false; }