use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class OracleSelectJoin method setLeft.
public void setLeft(String tableName) {
SQLExprTableSource tableSource;
if (tableName == null || tableName.length() == 0) {
tableSource = null;
} else {
tableSource = new OracleSelectTableReference(new SQLIdentifierExpr(tableName));
}
this.setLeft(tableSource);
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class Schema method findTable.
public SchemaObject findTable(SQLTableSource tableSource, String alias) {
if (tableSource instanceof SQLExprTableSource) {
if (StringUtils.equalsIgnoreCase(alias, tableSource.computeAlias())) {
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
SchemaObject tableObject = exprTableSource.getSchemaObject();
if (tableObject != null) {
return tableObject;
}
SQLExpr expr = exprTableSource.getExpr();
if (expr instanceof SQLIdentifierExpr) {
long tableNameHashCode64 = ((SQLIdentifierExpr) expr).nameHashCode64();
tableObject = findTable(tableNameHashCode64);
if (tableObject != null) {
exprTableSource.setSchemaObject(tableObject);
}
return tableObject;
}
if (expr instanceof SQLPropertyExpr) {
long tableNameHashCode64 = ((SQLPropertyExpr) expr).nameHashCode64();
tableObject = findTable(tableNameHashCode64);
if (tableObject != null) {
exprTableSource.setSchemaObject(tableObject);
}
return tableObject;
}
}
return null;
}
if (tableSource instanceof SQLJoinTableSource) {
SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
SQLTableSource left = join.getLeft();
SchemaObject tableObject = findTable(left, alias);
if (tableObject != null) {
return tableObject;
}
SQLTableSource right = join.getRight();
tableObject = findTable(right, alias);
return tableObject;
}
return null;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class Schema method findTable.
public SchemaObject findTable(SQLTableSource tableSource, SQLExpr expr) {
if (expr instanceof SQLAggregateExpr) {
SQLAggregateExpr aggregateExpr = (SQLAggregateExpr) expr;
String function = aggregateExpr.getMethodName();
if ("min".equalsIgnoreCase(function) || "max".equalsIgnoreCase(function)) {
SQLExpr arg = aggregateExpr.getArguments().get(0);
return findTable(tableSource, arg);
}
}
if (expr instanceof SQLPropertyExpr) {
String ownerName = ((SQLPropertyExpr) expr).getOwnernName();
return findTable(tableSource, ownerName);
}
if (expr instanceof SQLAllColumnExpr || expr instanceof SQLIdentifierExpr) {
if (tableSource instanceof SQLExprTableSource) {
return findTable(tableSource, tableSource.computeAlias());
}
if (tableSource instanceof SQLJoinTableSource) {
SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
SchemaObject table = findTable(join.getLeft(), expr);
if (table == null) {
table = findTable(join.getRight(), expr);
}
return table;
}
return null;
}
return null;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class SQLRefactorVisitor method visit.
public boolean visit(SQLExprTableSource x) {
TableMapping mapping = findMapping(x);
if (mapping == null) {
return true;
}
String destTable = mapping.getDestTable();
x.setExpr(new SQLIdentifierExpr(quote(destTable)));
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class MySqlAlterTableTest_40_change method isRenameColumn.
public boolean isRenameColumn(SQLAlterTableStatement stmt) {
for (SQLAlterTableItem item : stmt.getItems()) {
if (item instanceof MySqlAlterTableChangeColumn) {
MySqlAlterTableChangeColumn changeColumn = (MySqlAlterTableChangeColumn) item;
SQLIdentifierExpr columnName = (SQLIdentifierExpr) changeColumn.getColumnName();
String newColumnName = changeColumn.getNewColumnDefinition().getColumnName();
if (!columnName.nameEquals(newColumnName)) {
return true;
}
}
if (item instanceof SQLAlterTableRenameColumn) {
return true;
}
}
return false;
}
Aggregations