Java Code Examples for com.alibaba.druid.sql.ast.SQLName#toString()

The following examples show how to use com.alibaba.druid.sql.ast.SQLName#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MycatSchemaStatVisitor.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
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,ident);
        stat.incrementDeleteCount();
    }

    accept(x.getWhere());

    accept(x.getOrderBy());
    accept(x.getLimit());

    return false;
}
 
Example 2
Source File: ServerSchemaStatVisitor.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean visit(MySqlDeleteStatement x) {
    aliasMap.clear();
    accept(x.getFrom());
    accept(x.getUsing());
    x.getTableSource().accept(this);

    if (x.getTableSource() instanceof SQLExprTableSource) {
        SQLName tableName = (SQLName) ((SQLExprTableSource) x.getTableSource()).getExpr();
        currentTable = tableName.toString();
    }

    accept(x.getWhere());

    accept(x.getOrderBy());
    accept(x.getLimit());

    return false;
}
 
Example 3
Source File: ServerSchemaStatVisitor.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean visit(SQLUpdateStatement x) {
    aliasMap.clear();
    SQLName identName = x.getTableName();
    if (identName != null) {
        String ident = identName.toString();
        currentTable = ident;

        putAliasToMap(ident, ident.replace("`", ""));
        String alias = x.getTableSource().getAlias();
        if (alias != null) {
            putAliasToMap(alias, ident.replace("`", ""));
        }
    } else {
        x.getTableSource().accept(this);
    }

    accept(x.getItems());
    accept(x.getWhere());

    return false;
}
 
Example 4
Source File: DruidAlterTableParser.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
/**
 * this function is check if the name is the important column in any tables
 * true -- the column influence some important column
 * false -- safe
 */
private boolean influenceKeyColumn(SQLName name, SchemaConfig schema, String tableName) {
    String columnName = name.toString();
    Map<String, TableConfig> tableConfig = schema.getTables();
    TableConfig changedTable = tableConfig.get(tableName);
    if (changedTable == null) {
        return false;
    }
    if (columnName.equalsIgnoreCase(changedTable.getPartitionColumn()) ||
            columnName.equalsIgnoreCase(changedTable.getJoinKey())) {
        return true;
    }
    // Traversal all the table node to find if some table is the child table of the changedTale
    for (Map.Entry<String, TableConfig> entry : tableConfig.entrySet()) {
        TableConfig tb = entry.getValue();
        if (tb.getParentTC() != null &&
                tableName.equalsIgnoreCase(tb.getParentTC().getName()) &&
                columnName.equalsIgnoreCase(tb.getParentKey())) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: SqlVisitor.java    From baymax with Apache License 2.0 6 votes vote down vote up
@Override
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,ident);
        stat.incrementDeleteCount();
    }

    accept(x.getWhere());

    accept(x.getOrderBy());
    accept(x.getLimit());

    return false;
}
 
Example 6
Source File: MycatSchemaStatVisitor.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean visit(MySqlCreateTableStatement x) {
    SQLName sqlName=  x.getName();
    if(sqlName!=null)
    {
        String table = sqlName.toString();
        if(table.startsWith("`"))
        {
            table=table.substring(1,table.length()-1);
        }
        setCurrentTable(table);
    }
    return false;
}
 
Example 7
Source File: MycatSchemaStatVisitor.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean visit(MySqlInsertStatement x) {
    SQLName sqlName=  x.getTableName();
    if(sqlName!=null)
    {
        String table = sqlName.toString();
        if(table.startsWith("`"))
        {
            table=table.substring(1,table.length()-1);
        }
        setCurrentTable(sqlName.toString());
    }
    return false;
}
 
Example 8
Source File: MycatSchemaStatVisitor.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean visit(SQLUpdateStatement x) {
    setAliasMap();

    setMode(x, Mode.Update);

    SQLName identName = x.getTableName();
    if (identName != null) {
        String ident = identName.toString();
        String alias = x.getTableSource().getAlias();
        setCurrentTable(ident);

        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();

        Map<String, String> aliasMap = getAliasMap();
        
        aliasMap.put(ident, ident);
        if(alias != null) {
        	aliasMap.put(alias, ident);
        }
    } else {
        x.getTableSource().accept(this);
    }

    accept(x.getItems());
    accept(x.getWhere());

    return false;
}
 
Example 9
Source File: ServerSchemaStatVisitor.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean visit(MySqlInsertStatement x) {
    SQLName sqlName = x.getTableName();
    if (sqlName != null) {
        currentTable = sqlName.toString();
    }
    return false;
}
 
Example 10
Source File: SqlVisitor.java    From baymax with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(SQLUpdateStatement x) {
    setAliasMap();

    setMode(x, Mode.Update);

    SQLName identName = x.getTableName();
    if (identName != null) {
        String ident = identName.toString();
        //
        String alias = x.getTableSource().getAlias();
        setCurrentTable(ident);

        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();

        Map<String, String> aliasMap = getAliasMap();
        
        aliasMap.put(ident, ident);
        //
        if(alias != null) {
        	aliasMap.put(alias, ident);
        }
    } else {
        x.getTableSource().accept(this);
    }

    accept(x.getItems());
    accept(x.getWhere());

    return false;
}