improved sql parser.

This commit is contained in:
wenshao
2017-09-09 07:41:39 +08:00
parent 6545e23629
commit 3330643479
50 changed files with 1898 additions and 195 deletions
@@ -33,4 +33,7 @@ public interface SQLDataType extends SQLObject {
boolean isWithLocalTimeZone();
SQLDataType clone();
void setDbType(String dbType);
String getDbType();
}
@@ -15,6 +15,7 @@
*/
package com.alibaba.druid.sql.ast;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FnvHash;
@@ -24,11 +25,12 @@ import java.util.List;
public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
private String name;
private long nameHashCode64;
private String name;
private long nameHashCode64;
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
private Boolean withTimeZone;
private boolean withLocalTimeZone = false;
private Boolean withTimeZone;
private boolean withLocalTimeZone = false;
private String dbType;
public SQLDataTypeImpl(){
@@ -122,6 +124,14 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
this.withLocalTimeZone = withLocalTimeZone;
}
public String getDbType() {
return dbType;
}
public void setDbType(String dbType) {
this.dbType = dbType;
}
public SQLDataTypeImpl clone() {
SQLDataTypeImpl x = new SQLDataTypeImpl();
@@ -131,6 +141,7 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
}
public void cloneTo(SQLDataTypeImpl x) {
x.dbType = dbType;
x.name = name;
for (SQLExpr arg : arguments) {
@@ -140,4 +151,8 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
x.withTimeZone = withTimeZone;
x.withLocalTimeZone = withLocalTimeZone;
}
public String toString() {
return SQLUtils.toSQLString(this, dbType);
}
}
@@ -45,6 +45,14 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
return name;
}
public String getLowerName() {
if (name == null) {
return null;
}
return name.toLowerCase();
}
public String getName() {
return this.name;
}
@@ -36,9 +36,6 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
}
public SQLPropertyExpr(SQLExpr owner, String name){
if (name == null) {
throw new IllegalArgumentException("name is null.");
}
setOwner(owner);
this.name = name;
}
@@ -23,6 +23,7 @@ public interface SQLForeignKeyConstraint extends SQLConstraint, SQLTableElement,
List<SQLName> getReferencingColumns();
SQLExprTableSource getReferencedTable();
SQLName getReferencedTableName();
void setReferencedTableName(SQLName value);
@@ -22,12 +22,11 @@ import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLForeignKeyImpl extends SQLConstraintImpl implements SQLForeignKeyConstraint {
private SQLName referencedTableName;
private List<SQLName> referencingColumns = new ArrayList<SQLName>();
private List<SQLName> referencedColumns = new ArrayList<SQLName>();
private boolean onDeleteCascade = false;
private boolean onDeleteSetNull = false;
private SQLExprTableSource referencedTable;
private List<SQLName> referencingColumns = new ArrayList<SQLName>();
private List<SQLName> referencedColumns = new ArrayList<SQLName>();
private boolean onDeleteCascade = false;
private boolean onDeleteSetNull = false;
public SQLForeignKeyImpl(){
@@ -38,14 +37,33 @@ public class SQLForeignKeyImpl extends SQLConstraintImpl implements SQLForeignKe
return referencingColumns;
}
@Override
public SQLExprTableSource getReferencedTable() {
return referencedTable;
}
@Override
public SQLName getReferencedTableName() {
return referencedTableName;
if (referencedTable == null) {
return null;
}
return referencedTable.getName();
}
@Override
public void setReferencedTableName(SQLName value) {
this.referencedTableName = value;
if (value == null) {
this.referencedTable = null;
return;
}
this.setReferencedTable(new SQLExprTableSource(value));
}
public void setReferencedTable(SQLExprTableSource x) {
if (x != null) {
x.setParent(this);
}
this.referencedTable = x;
}
@Override
@@ -83,8 +101,8 @@ public class SQLForeignKeyImpl extends SQLConstraintImpl implements SQLForeignKe
public void cloneTo(SQLForeignKeyImpl x) {
super.cloneTo(x);
if (referencedTableName != null) {
x.setReferencedTableName(referencedTableName.clone());
if (referencedTable != null) {
x.setReferencedTable(referencedTable.clone());
}
for (SQLName column : referencingColumns) {