improved sql parser.

This commit is contained in:
wenshao
2017-06-04 21:30:23 +08:00
parent de4bfb0ae3
commit 21ae9b5722
63 changed files with 1049 additions and 350 deletions
@@ -113,4 +113,19 @@ public class OracleSelectJoin extends SQLJoinTableSource implements OracleSelect
public String toString () {
return SQLUtils.toOracleString(this);
}
public SQLJoinTableSource clone() {
OracleSelectJoin x = new OracleSelectJoin();
cloneTo(x);
if (pivot != null) {
x.setPivot(pivot.clone());
}
if (flashback != null) {
x.setFlashback(flashback.clone());
}
return x;
}
}
@@ -28,32 +28,36 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class OracleSelectQueryBlock extends SQLSelectQueryBlock {
private final List<SQLCommentHint> hints = new ArrayList<SQLCommentHint>(1);
private List<SQLCommentHint> hints;
private ModelClause modelClause;
private final List<SQLExpr> forUpdateOf = new ArrayList<SQLExpr>(1);
private List<SQLExpr> forUpdateOf;
private boolean skipLocked = false;
public OracleSelectQueryBlock clone() {
OracleSelectQueryBlock x = new OracleSelectQueryBlock();
super.clone(x);
super.cloneTo(x);
for (SQLCommentHint hint : hints) {
SQLCommentHint hint1 = hint.clone();
hint1.setParent(x);
x.getHints().add(hint1);
if (hints != null) {
for (SQLCommentHint hint : hints) {
SQLCommentHint hint1 = hint.clone();
hint1.setParent(x);
x.getHints().add(hint1);
}
}
if (modelClause != null) {
x.setModelClause(modelClause.clone());
}
for (SQLExpr item : forUpdateOf) {
SQLExpr item1 = item.clone();
item1.setParent(x);
forUpdateOf.add(item1);
if (forUpdateOf != null) {
for (SQLExpr item : forUpdateOf) {
SQLExpr item1 = item.clone();
item1.setParent(x);
forUpdateOf.add(item1);
}
}
x.skipLocked = skipLocked;
@@ -74,13 +78,35 @@ public class OracleSelectQueryBlock extends SQLSelectQueryBlock {
}
public List<SQLCommentHint> getHints() {
if (hints == null) {
hints = new ArrayList<SQLCommentHint>(1);
}
return this.hints;
}
public int getHintsSize() {
if (hints == null) {
return 0;
}
return hints.size();
}
public List<SQLExpr> getForUpdateOf() {
if (forUpdateOf == null) {
forUpdateOf = new ArrayList<SQLExpr>(1);
}
return forUpdateOf;
}
public int getForUpdateOfSize() {
if (forUpdateOf == null) {
return 0;
}
return forUpdateOf.size();
}
public boolean isSkipLocked() {
return skipLocked;
}
@@ -34,31 +34,6 @@ public class OracleSelectTableReference extends SQLExprTableSource implements Or
protected FlashbackQueryClause flashback;
public OracleSelectTableReference clone() {
OracleSelectTableReference x = new OracleSelectTableReference();
cloneTo(x);
x.only = only;
if (pivot != null) {
x.setPivot(pivot.clone());
}
if (partition != null) {
x.setPartition(partition.clone());
}
if (sampleClause != null) {
x.setSampleClause(sampleClause.clone());
}
if (flashback != null) {
setFlashback(flashback.clone());
}
return x;
}
public OracleSelectTableReference(){
}
@@ -167,4 +142,29 @@ public class OracleSelectTableReference extends SQLExprTableSource implements Or
return SQLUtils.toOracleString(this);
}
public OracleSelectTableReference clone() {
OracleSelectTableReference x = new OracleSelectTableReference();
cloneTo(x);
x.only = only;
if (pivot != null) {
x.setPivot(pivot.clone());
}
if (partition != null) {
x.setPartition(partition.clone());
}
if (sampleClause != null) {
x.setSampleClause(sampleClause.clone());
}
if (flashback != null) {
setFlashback(flashback.clone());
}
return x;
}
}
@@ -807,7 +807,7 @@ public class OracleStatementParser extends SQLStatementParser {
return stmt;
}
SQLBlockStatement block = this.parseBlock();
SQLStatement block = this.parseBlock();
stmt.setBlock(block);
@@ -1460,7 +1460,7 @@ public class OracleStatementParser extends SQLStatementParser {
return stmt;
}
public SQLBlockStatement parseBlock() {
public SQLStatement parseBlock() {
SQLBlockStatement block = new SQLBlockStatement();
block.setDbType(JdbcConstants.ORACLE);
@@ -1475,6 +1475,15 @@ public class OracleStatementParser extends SQLStatementParser {
}
}
if (lexer.token() == Token.PROCEDURE) {
SQLCreateProcedureStatement stmt = this.parseCreateProcedure();
for (SQLParameter param : block.getParameters()) {
param.setParent(stmt);
stmt.getParameters().add(param);
}
return stmt;
}
accept(Token.BEGIN);
parseStatementList(block.getStatementList(), -1, block);
@@ -2113,7 +2122,7 @@ public class OracleStatementParser extends SQLStatementParser {
return stmt;
}
SQLBlockStatement block = this.parseBlock();
SQLStatement block = this.parseBlock();
stmt.setBlock(block);
@@ -383,7 +383,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
public boolean visit(OracleSelectQueryBlock x) {
print0(ucase ? "SELECT " : "select ");
if (x.getHints().size() > 0) {
if (x.getHintsSize() > 0) {
printAndAccept(x.getHints(), ", ");
print(' ');
}
@@ -437,7 +437,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
if (x.isForUpdate()) {
println();
print0(ucase ? "FOR UPDATE" : "for update");
if (x.getForUpdateOf().size() > 0) {
if (x.getForUpdateOfSize() > 0) {
print('(');
printAndAccept(x.getForUpdateOf(), ", ");
print(')');
@@ -423,7 +423,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
print0(ucase ? "FOR BROWSE" : "for browse");
}
if (x.getForXmlOptions().size() > 0) {
if (x.getForXmlOptionsSize() > 0) {
println();
print0(ucase ? "FOR XML " : "for xml ");
for (int i = 0; i < x.getForXmlOptions().size(); ++i) {