Search in sources :

Example 1 with Relationship

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

the class OracleSchemaStatVisitor method visit.

@Override
public boolean visit(OracleSelectJoin x) {
    super.visit(x);
    for (SQLExpr item : x.getUsing()) {
        if (item instanceof SQLIdentifierExpr) {
            String columnName = ((SQLIdentifierExpr) item).getName();
            String leftTable = (String) x.getLeft().getAttribute(ATTR_TABLE);
            String rightTable = (String) x.getRight().getAttribute(ATTR_TABLE);
            if (leftTable != null && rightTable != null) {
                Relationship relationship = new Relationship();
                relationship.setLeft(new Column(leftTable, columnName));
                relationship.setRight(new Column(rightTable, columnName));
                relationship.setOperator("USING");
                relationships.add(relationship);
            }
            if (leftTable != null) {
                addColumn(leftTable, columnName);
            }
            if (rightTable != null) {
                addColumn(rightTable, columnName);
            }
        }
    }
    return false;
}
Also used : ModelColumn(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ModelColumn) Column(com.alibaba.druid.stat.TableStat.Column) Relationship(com.alibaba.druid.stat.TableStat.Relationship) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 2 with Relationship

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

the class SchemaStatVisitor method handleRelationship.

protected void handleRelationship(SQLExpr left, String operator, SQLExpr right) {
    Column leftColumn = getColumn(left);
    if (leftColumn == null) {
        return;
    }
    Column rightColumn = getColumn(right);
    if (rightColumn == null) {
        return;
    }
    Relationship relationship = new Relationship();
    relationship.setLeft(leftColumn);
    relationship.setRight(rightColumn);
    relationship.setOperator(operator);
    this.relationships.add(relationship);
}
Also used : Column(com.alibaba.druid.stat.TableStat.Column) Relationship(com.alibaba.druid.stat.TableStat.Relationship)

Aggregations

Column (com.alibaba.druid.stat.TableStat.Column)2 Relationship (com.alibaba.druid.stat.TableStat.Relationship)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 ModelColumn (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ModelColumn)1