Search in sources :

Example 1 with Mode

use of com.alibaba.druid.stat.TableStat.Mode in project druid by alibaba.

the class OracleSchemaStatVisitor method visit.

public boolean visit(OracleSelectTableReference x) {
    SQLExpr expr = x.getExpr();
    if (expr instanceof SQLMethodInvokeExpr) {
        SQLMethodInvokeExpr methodInvoke = (SQLMethodInvokeExpr) expr;
        if ("TABLE".equalsIgnoreCase(methodInvoke.getMethodName()) && methodInvoke.getParameters().size() == 1) {
            expr = methodInvoke.getParameters().get(0);
        }
    }
    Map<String, String> aliasMap = getAliasMap();
    if (expr instanceof SQLName) {
        String ident;
        if (expr instanceof SQLPropertyExpr) {
            String owner = ((SQLPropertyExpr) expr).getOwner().toString();
            String name = ((SQLPropertyExpr) expr).getName();
            if (aliasMap.containsKey(owner)) {
                owner = aliasMap.get(owner);
            }
            ident = owner + "." + name;
        } else {
            ident = expr.toString();
        }
        if (containsSubQuery(ident)) {
            return false;
        }
        if ("DUAL".equalsIgnoreCase(ident)) {
            return false;
        }
        x.putAttribute(ATTR_TABLE, ident);
        TableStat stat = getTableStat(ident);
        Mode mode = getMode();
        switch(mode) {
            case Delete:
                stat.incrementDeleteCount();
                break;
            case Insert:
                stat.incrementInsertCount();
                break;
            case Update:
                stat.incrementUpdateCount();
                break;
            case Select:
                stat.incrementSelectCount();
                break;
            case Merge:
                stat.incrementMergeCount();
                break;
            default:
                break;
        }
        putAliasMap(aliasMap, x.getAlias(), ident);
        putAliasMap(aliasMap, ident, ident);
        return false;
    }
    accept(x.getExpr());
    return false;
}
Also used : SQLMethodInvokeExpr(com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr) Mode(com.alibaba.druid.stat.TableStat.Mode) SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 2 with Mode

use of com.alibaba.druid.stat.TableStat.Mode in project druid by alibaba.

the class SchemaStatVisitor method setMode.

protected Mode setMode(SQLObject x, Mode mode) {
    Mode oldMode = this.mode;
    x.putAttribute("_original_use_mode", oldMode);
    this.mode = mode;
    return oldMode;
}
Also used : Mode(com.alibaba.druid.stat.TableStat.Mode)

Example 3 with Mode

use of com.alibaba.druid.stat.TableStat.Mode in project druid by alibaba.

the class SchemaStatVisitor method visit.

public boolean visit(SQLExprTableSource x) {
    if (isSimpleExprTableSource(x)) {
        String ident = x.getExpr().toString();
        if (variants.containsKey(ident)) {
            return false;
        }
        if (containsSubQuery(ident)) {
            return false;
        }
        Map<String, String> aliasMap = getAliasMap();
        TableStat stat = getTableStat(ident);
        Mode mode = getMode();
        if (mode != null) {
            switch(mode) {
                case Delete:
                    stat.incrementDeleteCount();
                    break;
                case Insert:
                    stat.incrementInsertCount();
                    break;
                case Update:
                    stat.incrementUpdateCount();
                    break;
                case Select:
                    stat.incrementSelectCount();
                    break;
                case Merge:
                    stat.incrementMergeCount();
                    break;
                case Drop:
                    stat.incrementDropCount();
                    break;
                default:
                    break;
            }
        }
        if (aliasMap != null) {
            String alias = x.getAlias();
            if (alias != null && !aliasMap.containsKey(alias)) {
                putAliasMap(aliasMap, alias, ident);
            }
            if (!aliasMap.containsKey(ident)) {
                putAliasMap(aliasMap, ident, ident);
            }
        }
    } else {
        accept(x.getExpr());
    }
    return false;
}
Also used : Mode(com.alibaba.druid.stat.TableStat.Mode) TableStat(com.alibaba.druid.stat.TableStat)

Example 4 with Mode

use of com.alibaba.druid.stat.TableStat.Mode in project druid by alibaba.

the class SchemaStatVisitor method setModeOrigin.

protected void setModeOrigin(SQLObject x) {
    Mode originalMode = (Mode) x.getAttribute("_original_use_mode");
    mode = originalMode;
}
Also used : Mode(com.alibaba.druid.stat.TableStat.Mode)

Aggregations

Mode (com.alibaba.druid.stat.TableStat.Mode)4 TableStat (com.alibaba.druid.stat.TableStat)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)1 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)1