-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parser support from generated source
- Loading branch information
1 parent
1613a76
commit f060c27
Showing
7 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
core/src/main/java/com/alibaba/druid/sql/ast/statement/SQLGeneratedTableSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.alibaba.druid.sql.ast.statement; | ||
|
||
import com.alibaba.druid.sql.ast.SQLExpr; | ||
import com.alibaba.druid.sql.ast.SQLName; | ||
import com.alibaba.druid.sql.ast.SQLReplaceable; | ||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; | ||
import com.alibaba.druid.sql.visitor.SQLASTVisitor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SQLGeneratedTableSource extends SQLTableSourceImpl | ||
implements SQLReplaceable { | ||
private final List<SQLExpr> items = new ArrayList<SQLExpr>(); | ||
protected List<SQLName> columns = new ArrayList<SQLName>(); | ||
private SQLIdentifierExpr methodName; | ||
|
||
public List<SQLExpr> getItems() { | ||
return items; | ||
} | ||
|
||
public List<SQLName> getColumns() { | ||
return columns; | ||
} | ||
|
||
@Override | ||
protected void accept0(SQLASTVisitor v) { | ||
if (v.visit(this)) { | ||
acceptChild(v, methodName); | ||
acceptChild(v, columns); | ||
acceptChild(v, items); | ||
} | ||
v.endVisit(this); | ||
} | ||
|
||
@Override | ||
public boolean replace(SQLExpr expr, SQLExpr target) { | ||
for (int i = 0; i < items.size(); i++) { | ||
if (items.get(i) == expr) { | ||
target.setParent(this); | ||
items.set(i, target); | ||
return true; | ||
} | ||
} | ||
if (target instanceof SQLName) { | ||
SQLName targetName = (SQLName) target; | ||
for (int i = 0; i < columns.size(); i++) { | ||
if (columns.get(i) == expr) { | ||
target.setParent(this); | ||
columns.set(i, targetName); | ||
return true; | ||
} | ||
} | ||
} | ||
if (target instanceof SQLIdentifierExpr) { | ||
if (methodName == expr) { | ||
target.setParent(this); | ||
methodName = (SQLIdentifierExpr) target; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public SQLIdentifierExpr getMethodName() { | ||
return methodName; | ||
} | ||
|
||
public void setMethodName(SQLIdentifierExpr methodName) { | ||
this.methodName = methodName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters