// DUAL public boolean visit(MySqlDeleteStatement x) { setAliasMap(); setMode(x, Mode.Delete); accept(x.getFrom()); accept(x.getUsing()); x.getTableSource().accept(this); if (x.getTableSource() instanceof SQLExprTableSource) { SQLName tableName = (SQLName) ((SQLExprTableSource) x.getTableSource()).getExpr(); String ident = tableName.toString(); setCurrentTable(x, ident); TableStat stat = this.getTableStat(ident); stat.incrementDeleteCount(); } accept(x.getWhere()); accept(x.getOrderBy()); accept(x.getLimit()); return false; }
@Override public boolean visit(SQLCreateIndexStatement x) { setMode(x, Mode.CreateIndex); SQLName name = (SQLName) ((SQLExprTableSource) x.getTable()).getExpr(); String table = name.toString(); setCurrentTable(table); TableStat stat = getTableStat(table); stat.incrementDropIndexCount(); Map<String, String> aliasMap = getAliasMap(); if (aliasMap != null) { aliasMap.put(table, table); } for (SQLSelectOrderByItem item : x.getItems()) { SQLExpr expr = item.getExpr(); if (expr instanceof SQLIdentifierExpr) { SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr; String columnName = identExpr.getName(); addColumn(table, columnName); } } return false; }
@Override public boolean visit(SQLDropTableStatement x) { setMode(x, Mode.Insert); setAliasMap(); String originalTable = getCurrentTable(); for (SQLExprTableSource tableSource : x.getTableSources()) { SQLName name = (SQLName) tableSource.getExpr(); String ident = name.toString(); setCurrentTable(ident); x.putAttribute("_old_local_", originalTable); TableStat stat = getTableStat(ident); stat.incrementDropCount(); Map<String, String> aliasMap = getAliasMap(); if (aliasMap != null) { aliasMap.put(ident, ident); } } return false; }
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; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((cursorName == null) ? 0 : cursorName.hashCode()); return result; }
@Override public boolean visit(SQLForeignKeyImpl x) { for (SQLName column : x.getReferencedColumns()) { column.accept(this); } String table = x.getReferencedTableName().getSimpleName(); setCurrentTable(table); TableStat stat = getTableStat(table); stat.incrementReferencedCount(); for (SQLName column : x.getReferencedColumns()) { String columnName = column.getSimpleName(); addColumn(table, columnName); } return false; }
@Override public void output(StringBuffer buf) { name.output(buf); buf.append(' '); this.dataType.output(buf); if (defaultExpr != null) { buf.append(" DEFAULT "); this.defaultExpr.output(buf); } }
@Override public boolean visit(SQLDropIndexStatement x) { setMode(x, Mode.DropIndex); SQLExprTableSource table = x.getTableName(); if (table != null) { SQLName name = (SQLName) table.getExpr(); String ident = name.toString(); setCurrentTable(ident); TableStat stat = getTableStat(ident); stat.incrementDropIndexCount(); Map<String, String> aliasMap = getAliasMap(); if (aliasMap != null) { aliasMap.put(ident, ident); } } return false; }
public boolean visit(SQLUpdateStatement x) { setAliasMap(); setMode(x, Mode.Update); SQLName identName = x.getTableName(); if (identName != null) { String ident = identName.toString(); setCurrentTable(ident); TableStat stat = getTableStat(ident); stat.incrementUpdateCount(); Map<String, String> aliasMap = getAliasMap(); aliasMap.put(ident, ident); } else { x.getTableSource().accept(this); } accept(x.getItems()); accept(x.getWhere()); return false; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } SQLCurrentOfCursorExpr other = (SQLCurrentOfCursorExpr) obj; if (cursorName == null) { if (other.cursorName != null) { return false; } } else if (!cursorName.equals(other.cursorName)) { return false; } return true; }
public SQLDataType parseDataType() { if (lexer.token() == Token.CONSTRAINT || lexer.token() == Token.COMMA) { return null; } if (lexer.token() == Token.DEFAULT || lexer.token() == Token.NOT || lexer.token() == Token.NULL) { return null; } if (lexer.token() == Token.INTERVAL) { lexer.nextToken(); if (identifierEquals("YEAR")) { lexer.nextToken(); OracleDataTypeIntervalYear interval = new OracleDataTypeIntervalYear(); if (lexer.token() == Token.LPAREN) { lexer.nextToken(); interval.getArguments().add(this.expr()); accept(Token.RPAREN); } accept(Token.TO); acceptIdentifier("MONTH"); return interval; } else { acceptIdentifier("DAY"); OracleDataTypeIntervalDay interval = new OracleDataTypeIntervalDay(); if (lexer.token() == Token.LPAREN) { lexer.nextToken(); interval.getArguments().add(this.expr()); accept(Token.RPAREN); } accept(Token.TO); acceptIdentifier("SECOND"); if (lexer.token() == Token.LPAREN) { lexer.nextToken(); interval.getFractionalSeconds().add(this.expr()); accept(Token.RPAREN); } return interval; } } String typeName; if (identifierEquals("LONG")) { lexer.nextToken(); acceptIdentifier("RAW"); typeName = "LONG RAW"; } else { SQLName typeExpr = name(); typeName = typeExpr.toString(); } if ("TIMESTAMP".equalsIgnoreCase(typeName)) { OracleDataTypeTimestamp timestamp = new OracleDataTypeTimestamp(); if (lexer.token() == Token.LPAREN) { lexer.nextToken(); timestamp.getArguments().add(this.expr()); accept(Token.RPAREN); } if (lexer.token() == Token.WITH) { lexer.nextToken(); if (identifierEquals("LOCAL")) { lexer.nextToken(); timestamp.setWithLocalTimeZone(true); } else { timestamp.setWithTimeZone(true); } acceptIdentifier("TIME"); acceptIdentifier("ZONE"); } return timestamp; } if (isCharType(typeName)) { SQLCharactorDataType charType = new SQLCharactorDataType(typeName); if (lexer.token() == Token.LPAREN) { lexer.nextToken(); charType.getArguments().add(this.expr()); if (identifierEquals("CHAR")) { lexer.nextToken(); charType.setCharType(SQLCharactorDataType.CHAR_TYPE_CHAR); } else if (identifierEquals("BYTE")) { lexer.nextToken(); charType.setCharType(SQLCharactorDataType.CHAR_TYPE_BYTE); } accept(Token.RPAREN); } return parseCharTypeRest(charType); } if (lexer.token() == Token.PERCENT) { lexer.nextToken(); if (identifierEquals("TYPE")) { lexer.nextToken(); typeName += "%TYPE"; } else if (identifierEquals("ROWTYPE")) { lexer.nextToken(); typeName += "%ROWTYPE"; } else { throw new ParserException("syntax error : " + lexer.token() + " " + lexer.stringVal()); } } SQLDataType dataType = new SQLDataTypeImpl(typeName); return parseDataTypeRest(dataType); }
@Override public void output(StringBuffer buf) { buf.append("CURRENT OF "); cursorName.output(buf); }