mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -25,9 +25,7 @@ public abstract class SQLExprImpl extends SQLObjectImpl implements SQLExpr {
|
||||
|
||||
public abstract int hashCode();
|
||||
|
||||
public SQLExpr clone() {
|
||||
throw new UnsupportedOperationException(this.getClass().getName());
|
||||
}
|
||||
public abstract SQLExpr clone();
|
||||
|
||||
public SQLDataType computeDataType() {
|
||||
return null;
|
||||
|
||||
@@ -28,8 +28,15 @@ public class SQLAllExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public SQLAllExpr(SQLSelect select){
|
||||
setSubQuery(select);
|
||||
}
|
||||
|
||||
this.subQuery = select;
|
||||
public SQLAllExpr clone() {
|
||||
SQLAllExpr x = new SQLAllExpr();
|
||||
if (subQuery != null) {
|
||||
x.setSubQuery(subQuery.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLSelect getSubQuery() {
|
||||
@@ -37,6 +44,9 @@ public class SQLAllExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public void setSubQuery(SQLSelect subQuery) {
|
||||
if (subQuery != null) {
|
||||
subQuery.setParent(this);
|
||||
}
|
||||
this.subQuery = subQuery;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,15 @@ public class SQLAnyExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public SQLAnyExpr(SQLSelect select){
|
||||
setSubQuery(select);
|
||||
}
|
||||
|
||||
this.subQuery = select;
|
||||
public SQLAnyExpr clone() {
|
||||
SQLAnyExpr x = new SQLAnyExpr();
|
||||
if (subQuery != null) {
|
||||
x.setSubQuery(subQuery.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLSelect getSubQuery() {
|
||||
@@ -42,6 +49,9 @@ public class SQLAnyExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public void setSubQuery(SQLSelect subQuery) {
|
||||
if (subQuery != null) {
|
||||
subQuery.setParent(this);
|
||||
}
|
||||
this.subQuery = subQuery;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,19 @@ public class SQLArrayExpr extends SQLExprImpl {
|
||||
|
||||
private List<SQLExpr> values = new ArrayList<SQLExpr>();
|
||||
|
||||
public SQLArrayExpr clone() {
|
||||
SQLArrayExpr x = new SQLArrayExpr();
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
for (SQLExpr value : values) {
|
||||
SQLExpr value2 = value.clone();
|
||||
value2.setParent(x);
|
||||
x.values.add(value2);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,21 @@ public class SQLBetweenExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
}
|
||||
|
||||
public SQLBetweenExpr clone() {
|
||||
SQLBetweenExpr x = new SQLBetweenExpr();
|
||||
if (testExpr != null) {
|
||||
x.setTestExpr(testExpr.clone());
|
||||
}
|
||||
x.not = not;
|
||||
if (beginExpr != null) {
|
||||
x.setBeginExpr(beginExpr.clone());
|
||||
}
|
||||
if (endExpr != null) {
|
||||
x.setEndExpr(endExpr.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLBetweenExpr(SQLExpr testExpr, SQLExpr beginExpr, SQLExpr endExpr){
|
||||
setTestExpr(testExpr);
|
||||
setBeginExpr(beginExpr);
|
||||
|
||||
@@ -97,4 +97,15 @@ public class SQLCastExpr extends SQLExprImpl {
|
||||
public SQLDataType computeDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public SQLCastExpr clone() {
|
||||
SQLCastExpr x = new SQLCastExpr();
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
if (dataType != null) {
|
||||
x.setDataType(dataType.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,22 @@ public class SQLCurrentOfCursorExpr extends SQLExprImpl {
|
||||
this.cursorName = cursorName;
|
||||
}
|
||||
|
||||
public SQLCurrentOfCursorExpr clone() {
|
||||
SQLCurrentOfCursorExpr x = new SQLCurrentOfCursorExpr();
|
||||
if (cursorName != null) {
|
||||
x.setCursorName(cursorName.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLName getCursorName() {
|
||||
return cursorName;
|
||||
}
|
||||
|
||||
public void setCursorName(SQLName cursorName) {
|
||||
if (cursorName != null) {
|
||||
cursorName.setParent(this);
|
||||
}
|
||||
this.cursorName = cursorName;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,23 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExplainStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLGroupingSetExpr extends SQLExprImpl {
|
||||
|
||||
private final List<SQLExpr> parameters = new ArrayList<SQLExpr>();
|
||||
|
||||
public SQLGroupingSetExpr clone() {
|
||||
SQLGroupingSetExpr x = new SQLGroupingSetExpr();
|
||||
for (SQLExpr p : parameters) {
|
||||
SQLExpr p2 = p.clone();
|
||||
p2.setParent(x);
|
||||
x.parameters.add(p2);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,15 @@ public class SQLSomeExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public SQLSomeExpr(SQLSelect select){
|
||||
this.setSubQuery(select);
|
||||
}
|
||||
|
||||
this.subQuery = select;
|
||||
public SQLSomeExpr clone() {
|
||||
SQLSomeExpr x = new SQLSomeExpr();
|
||||
if (subQuery != null) {
|
||||
x.setSubQuery(subQuery.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLSelect getSubQuery() {
|
||||
@@ -42,6 +49,9 @@ public class SQLSomeExpr extends SQLExprImpl {
|
||||
}
|
||||
|
||||
public void setSubQuery(SQLSelect subQuery) {
|
||||
if (subQuery != null) {
|
||||
subQuery.setParent(this);
|
||||
}
|
||||
this.subQuery = subQuery;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,14 @@ public class SQLTimestampExpr extends SQLExprImpl {
|
||||
|
||||
}
|
||||
|
||||
public SQLTimestampExpr clone() {
|
||||
SQLTimestampExpr x = new SQLTimestampExpr();
|
||||
x.literal = literal;
|
||||
x.timeZone = timeZone;
|
||||
x.withTimeZone = withTimeZone;
|
||||
return x;
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,15 @@ public class SQLUnaryExpr extends SQLExprImpl implements Serializable {
|
||||
this.setExpr(expr);
|
||||
}
|
||||
|
||||
public SQLUnaryExpr clone() {
|
||||
SQLUnaryExpr x = new SQLUnaryExpr();
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
x.operator = operator;
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLUnaryOperator getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,9 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
}
|
||||
|
||||
public void setSelect(SQLSelect select) {
|
||||
if (select != null) {
|
||||
select.setParent(this);
|
||||
}
|
||||
this.select = select;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,23 @@ public class MySqlExtractExpr extends SQLExprImpl implements MySqlExpr {
|
||||
public MySqlExtractExpr(){
|
||||
}
|
||||
|
||||
public MySqlExtractExpr clone() {
|
||||
MySqlExtractExpr x = new MySqlExtractExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
x.unit = unit;
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(SQLExpr value) {
|
||||
if (value != null) {
|
||||
value.setParent(this);
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,15 @@ public class MySqlIntervalExpr extends SQLExprImpl implements MySqlExpr {
|
||||
public MySqlIntervalExpr(){
|
||||
}
|
||||
|
||||
public MySqlIntervalExpr clone() {
|
||||
MySqlIntervalExpr x = new MySqlIntervalExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
x.unit = unit;
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,20 @@ public class MySqlMatchAgainstExpr extends SQLExprImpl implements MySqlExpr {
|
||||
|
||||
private SearchModifier searchModifier;
|
||||
|
||||
public MySqlMatchAgainstExpr clone() {
|
||||
MySqlMatchAgainstExpr x = new MySqlMatchAgainstExpr();
|
||||
for (SQLExpr column : columns) {
|
||||
SQLExpr column2 = column.clone();
|
||||
column2.setParent(x);
|
||||
x.columns.add(column2);
|
||||
}
|
||||
if (against != null) {
|
||||
x.setAgainst(against.clone());
|
||||
}
|
||||
x.searchModifier = searchModifier;
|
||||
return x;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
@@ -44,6 +58,9 @@ public class MySqlMatchAgainstExpr extends SQLExprImpl implements MySqlExpr {
|
||||
}
|
||||
|
||||
public void setAgainst(SQLExpr against) {
|
||||
if (against != null) {
|
||||
against.setParent(this);
|
||||
}
|
||||
this.against = against;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,19 @@ public class MySqlOrderingExpr extends SQLExprImpl implements MySqlExpr {
|
||||
|
||||
public MySqlOrderingExpr(SQLExpr expr, SQLOrderingSpecification type){
|
||||
super();
|
||||
this.expr = expr;
|
||||
setExpr(expr);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public MySqlOrderingExpr clone() {
|
||||
MySqlOrderingExpr x = new MySqlOrderingExpr();
|
||||
if (expr != null) {
|
||||
x.setExpr(expr.clone());
|
||||
}
|
||||
x.type = type;
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor;
|
||||
@@ -51,7 +60,9 @@ public class MySqlOrderingExpr extends SQLExprImpl implements MySqlExpr {
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
expr.setParent(this);
|
||||
if (expr != null) {
|
||||
expr.setParent(this);
|
||||
}
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
|
||||
+29
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObject;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlObject {
|
||||
@@ -46,6 +47,34 @@ public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlO
|
||||
|
||||
}
|
||||
|
||||
public MySqlSelectQueryBlock clone() {
|
||||
MySqlSelectQueryBlock x = new MySqlSelectQueryBlock();
|
||||
cloneTo(x);
|
||||
|
||||
x.hignPriority = hignPriority;
|
||||
x.straightJoin = straightJoin;
|
||||
|
||||
x.smallResult = smallResult;
|
||||
x.bigResult = bigResult;
|
||||
x.bufferResult = bufferResult;
|
||||
x.cache = cache;
|
||||
x.calcFoundRows = calcFoundRows;
|
||||
|
||||
if (procedureName != null) {
|
||||
x.setProcedureName(procedureName.clone());
|
||||
}
|
||||
if (procedureArgumentList != null) {
|
||||
for (SQLExpr arg : procedureArgumentList) {
|
||||
SQLExpr arg_cloned = arg.clone();
|
||||
arg_cloned.setParent(this);
|
||||
x.procedureArgumentList.add(arg_cloned);
|
||||
}
|
||||
}
|
||||
x.lockInShareMode = lockInShareMode;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getHintsSize() {
|
||||
if (hints == null) {
|
||||
return 0;
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
package com.alibaba.druid.sql.dialect.mysql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint;
|
||||
@@ -3677,4 +3674,31 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
block.accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCommentStatement x) {
|
||||
SQLCommentStatement.Type type = x.getType();
|
||||
|
||||
SQLExpr on = x.getOn();
|
||||
if (type == SQLCommentStatement.Type.TABLE) {
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
on.accept(this);
|
||||
print0(ucase ? " COMMENT = " : " comment = ");
|
||||
x.getComment().accept(this);
|
||||
} else {
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) on;
|
||||
|
||||
SQLExpr table = propertyExpr.getOwner();
|
||||
String column = propertyExpr.getName();
|
||||
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
table.accept(this);
|
||||
print0(ucase ? " MODIFY COLUMN " : " modify column ");
|
||||
print(column);
|
||||
print0(ucase ? " COMMENT " : " comment ");
|
||||
x.getComment().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} //
|
||||
|
||||
@@ -28,9 +28,16 @@ public class OracleCursorExpr extends SQLExprImpl implements OracleExpr {
|
||||
|
||||
}
|
||||
|
||||
public OracleCursorExpr clone() {
|
||||
OracleCursorExpr x = new OracleCursorExpr();
|
||||
if (query != null) {
|
||||
x.setQuery(query.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public OracleCursorExpr(SQLSelect query){
|
||||
super();
|
||||
this.query = query;
|
||||
setQuery(query);
|
||||
}
|
||||
|
||||
public SQLSelect getQuery() {
|
||||
|
||||
@@ -31,11 +31,22 @@ public class OracleIsSetExpr extends SQLExprImpl implements OracleExpr {
|
||||
this.nestedTable = nestedTable;
|
||||
}
|
||||
|
||||
public OracleIsSetExpr clone() {
|
||||
OracleIsSetExpr x = new OracleIsSetExpr();
|
||||
if (nestedTable != null) {
|
||||
x.setNestedTable(nestedTable.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getNestedTable() {
|
||||
return nestedTable;
|
||||
}
|
||||
|
||||
public void setNestedTable(SQLExpr nestedTable) {
|
||||
if (nestedTable != null) {
|
||||
nestedTable.setParent(this);
|
||||
}
|
||||
this.nestedTable = nestedTable;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,14 @@ public class PGBoxExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGBoxExpr clone() {
|
||||
PGBoxExpr x = new PGBoxExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,14 @@ public class PGCidrExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGCidrExpr clone() {
|
||||
PGCidrExpr x = new PGCidrExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,14 @@ public class PGCircleExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGCircleExpr clone() {
|
||||
PGCircleExpr x = new PGCircleExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,15 @@ public class PGExtractExpr extends PGExprImpl {
|
||||
private PGDateField field;
|
||||
private SQLExpr source;
|
||||
|
||||
public PGExtractExpr clone() {
|
||||
PGExtractExpr x = new PGExtractExpr();
|
||||
x.field = field;
|
||||
if (source != null) {
|
||||
x.setSource(source.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public PGDateField getField() {
|
||||
return field;
|
||||
}
|
||||
@@ -36,6 +45,9 @@ public class PGExtractExpr extends PGExprImpl {
|
||||
}
|
||||
|
||||
public void setSource(SQLExpr source) {
|
||||
if (source != null) {
|
||||
source.setParent(this);
|
||||
}
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,14 @@ public class PGInetExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGInetExpr clone() {
|
||||
PGInetExpr x = new PGInetExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
+8
@@ -22,6 +22,14 @@ public class PGLineSegmentsExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGLineSegmentsExpr clone() {
|
||||
PGLineSegmentsExpr x = new PGLineSegmentsExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,14 @@ public class PGMacAddrExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGMacAddrExpr clone() {
|
||||
PGMacAddrExpr x = new PGMacAddrExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,14 @@ public class PGPointExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGPointExpr clone() {
|
||||
PGPointExpr x = new PGPointExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,14 @@ public class PGPolygonExpr extends PGExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
|
||||
public PGPolygonExpr clone() {
|
||||
PGPolygonExpr x = new PGPolygonExpr();
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectTableReference;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitorAdapter;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -39,6 +41,7 @@ import java.util.*;
|
||||
* Created by wenshao on 03/06/2017.
|
||||
*/
|
||||
public class SchemaRepository {
|
||||
private static Log LOG = LogFactory.getLog(SchemaRepository.class);
|
||||
private Schema defaultSchema;
|
||||
protected String dbType;
|
||||
protected SQLASTVisitor consoleVisitor;
|
||||
@@ -804,11 +807,12 @@ public class SchemaRepository {
|
||||
}
|
||||
|
||||
boolean acceptCreateTable(SQLCreateTableStatement x) {
|
||||
String schemaName = x.getSchema();
|
||||
SQLCreateTableStatement x1 = x.clone();
|
||||
String schemaName = x1.getSchema();
|
||||
|
||||
Schema schema = findSchema(schemaName, true);
|
||||
|
||||
SQLSelect select = x.getSelect();
|
||||
SQLSelect select = x1.getSelect();
|
||||
if (select != null) {
|
||||
select.accept(createResolveVisitor(SchemaResolveVisitor.Option.ResolveAllColumn));
|
||||
|
||||
@@ -822,21 +826,21 @@ public class SchemaRepository {
|
||||
column.setName(name);
|
||||
column.setDataType(dataType);
|
||||
column.setDbType(dbType);
|
||||
x.getTableElementList().add(column);
|
||||
x1.getTableElementList().add(column);
|
||||
}
|
||||
x.setSelect(null);
|
||||
x1.setSelect(null);
|
||||
}
|
||||
}
|
||||
|
||||
x.setSchema(null);
|
||||
|
||||
String name = x.computeName();
|
||||
String name = x1.computeName();
|
||||
SchemaObject table = schema.findTableOrView(name);
|
||||
if (table != null) {
|
||||
return false;
|
||||
LOG.info("replaced table '" + name + "'");
|
||||
}
|
||||
|
||||
table = new SchemaObjectImpl(name, SchemaObjectType.Table, x.clone());
|
||||
table = new SchemaObjectImpl(name, SchemaObjectType.Table, x1);
|
||||
String name_lower = SQLUtils.normalize(name).toLowerCase();
|
||||
schema.objects.put(name_lower, table);
|
||||
return true;
|
||||
|
||||
@@ -122,6 +122,10 @@ public class StringUtils {
|
||||
return a.equalsIgnoreCase(b);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String value) {
|
||||
return isEmpty((CharSequence) value);
|
||||
}
|
||||
|
||||
public static boolean isEmpty(CharSequence value) {
|
||||
if (value == null || value.length() == 0) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user