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:
@@ -895,7 +895,7 @@ public class SQLUtils {
|
||||
}
|
||||
|
||||
tableName = normalize(tableName);
|
||||
long hash = Utils.fnv_32_lower(tableName);
|
||||
long hash = FnvHash.hashCode64(tableName);
|
||||
return Utils.hex_t(hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,11 @@ public abstract class SQLObjectImpl implements SQLObject {
|
||||
}
|
||||
|
||||
public boolean hasAfterComment() {
|
||||
List<String> comments = getAfterCommentsDirect();
|
||||
if (attributes == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> comments = (List<String>) attributes.get("format.after_comment");
|
||||
if (comments == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
|
||||
public SQLIdentifierExpr simplify() {
|
||||
String normalized = SQLUtils.normalize(name);
|
||||
if (normalized != name) {
|
||||
return new SQLIdentifierExpr(name, hashCode64);
|
||||
return new SQLIdentifierExpr(normalized, hashCode64);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -284,4 +284,18 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
public boolean nameEquals(String name) {
|
||||
return SQLUtils.nameEquals(this.name, name);
|
||||
}
|
||||
|
||||
public SQLPropertyExpr simplify() {
|
||||
String normalizedName = SQLUtils.normalize(name);
|
||||
SQLExpr normalizedOwner = this.owner;
|
||||
if (normalizedOwner instanceof SQLIdentifierExpr) {
|
||||
normalizedOwner = ((SQLIdentifierExpr) normalizedOwner).simplify();
|
||||
}
|
||||
|
||||
if (normalizedName != name || normalizedOwner != owner) {
|
||||
return new SQLPropertyExpr(normalizedOwner, normalizedName, hashCode64);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -444,7 +444,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
SQLName columnName = x.getColumnName();
|
||||
if (columnName != null) {
|
||||
addColumn(table, columnName.getSimpleName(), tableName.nameHashCode64(), columnName.nameHashCode64());
|
||||
addColumn(table, columnName.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -954,7 +954,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
SQLName column = x.getColumnName();
|
||||
String columnName = column.toString();
|
||||
addColumn(tableName, columnName, table.nameHashCode64(), column.nameHashCode64());
|
||||
addColumn(tableName, columnName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -972,7 +972,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
SQLName column = x.getNewColumnDefinition().getName();
|
||||
String columnName = column.toString();
|
||||
addColumn(tableName, columnName, table.nameHashCode64(), column.nameHashCode64());
|
||||
addColumn(tableName, columnName);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
|
||||
SQLExpr tableName = tableSource.getExpr();
|
||||
|
||||
if (tableName instanceof SQLName) {
|
||||
String ident = ((SQLName) tableName).toString();
|
||||
TableStat stat = getTableStat(tableName);
|
||||
TableStat stat = getTableStat((SQLName) tableName);
|
||||
stat.incrementInsertCount();
|
||||
|
||||
}
|
||||
|
||||
@@ -76,11 +76,8 @@ public class OracleDbLinkExpr extends SQLExprImpl implements SQLName, OracleExpr
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((dbLink == null) ? 0 : dbLink.hashCode());
|
||||
result = prime * result + ((expr == null) ? 0 : expr.hashCode());
|
||||
return result;
|
||||
long value = hashCode64();
|
||||
return (int)(value ^ (value >>> 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,21 +92,7 @@ public class OracleDbLinkExpr extends SQLExprImpl implements SQLName, OracleExpr
|
||||
return false;
|
||||
}
|
||||
OracleDbLinkExpr other = (OracleDbLinkExpr) obj;
|
||||
if (dbLink == null) {
|
||||
if (other.dbLink != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!dbLink.equals(other.dbLink)) {
|
||||
return false;
|
||||
}
|
||||
if (expr == null) {
|
||||
if (other.expr != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!expr.equals(other.expr)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return this.hashCode64() == other.hashCode64();
|
||||
}
|
||||
|
||||
public OracleDbLinkExpr clone() {
|
||||
@@ -138,14 +121,14 @@ public class OracleDbLinkExpr extends SQLExprImpl implements SQLName, OracleExpr
|
||||
if (expr instanceof SQLName) {
|
||||
hash = ((SQLName) expr).hashCode64();
|
||||
|
||||
hash ^= '.';
|
||||
hash ^= '@';
|
||||
hash *= FnvHash.PRIME;
|
||||
} else if (expr == null){
|
||||
hash = FnvHash.BASIC;
|
||||
} else {
|
||||
hash = FnvHash.fnv1a_64_lower(expr.toString());
|
||||
|
||||
hash ^= '.';
|
||||
hash ^= '@';
|
||||
hash *= FnvHash.PRIME;
|
||||
}
|
||||
hash = FnvHash.hashCode64(hash, dbLink);
|
||||
|
||||
@@ -480,7 +480,7 @@ public class OracleExprParser extends SQLExprParser {
|
||||
if (acceptLPAREN) {
|
||||
accept(Token.LPAREN);
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.PLUS) {
|
||||
lexer.nextToken();
|
||||
accept(Token.RPAREN);
|
||||
@@ -508,7 +508,7 @@ public class OracleExprParser extends SQLExprParser {
|
||||
return primaryRest(treatExpr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return super.methodRest(expr, false);
|
||||
}
|
||||
|
||||
@@ -878,11 +878,31 @@ public class OracleExprParser extends SQLExprParser {
|
||||
interval.setValue(new SQLCharExpr(lexer.stringVal()));
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
OracleIntervalType type = OracleIntervalType.valueOf(lexer.stringVal());
|
||||
OracleIntervalType type;
|
||||
if (lexer.identifierEquals(FnvHash.Constants.YEAR)) {
|
||||
lexer.nextToken();
|
||||
type = OracleIntervalType.YEAR;
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.MONTH)) {
|
||||
lexer.nextToken();
|
||||
type = OracleIntervalType.MONTH;
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.DAY)) {
|
||||
lexer.nextToken();
|
||||
type = OracleIntervalType.DAY;
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.HOUR)) {
|
||||
lexer.nextToken();
|
||||
type = OracleIntervalType.HOUR;
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.MINUTE)) {
|
||||
lexer.nextToken();
|
||||
type = OracleIntervalType.MINUTE;
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.SECOND)) {
|
||||
lexer.nextToken();
|
||||
type = OracleIntervalType.SECOND;
|
||||
} else {
|
||||
throw new ParserException("illegal interval type. " + lexer.info());
|
||||
}
|
||||
|
||||
interval.setType(type);
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() != Token.LITERAL_INT) {
|
||||
|
||||
@@ -922,8 +922,6 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
if (lexer.token() == Token.ELSE) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
|
||||
SQLIfStatement.Else elseItem = new SQLIfStatement.Else();
|
||||
this.parseStatementList(elseItem.getStatements(), -1, elseItem);
|
||||
stmt.setElseItem(elseItem);
|
||||
|
||||
+15
-19
@@ -151,9 +151,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
}
|
||||
|
||||
if (tableExpr instanceof SQLName) {
|
||||
String ident = tableExpr.toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat((SQLName) tableExpr);
|
||||
stat.incrementUpdateCount();
|
||||
} else {
|
||||
tableSource.accept(this);
|
||||
@@ -176,13 +174,13 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
}
|
||||
|
||||
public boolean visit(OracleSelectQueryBlock x) {
|
||||
if (x.getInto() instanceof SQLName) {
|
||||
String tableName = x.getInto().toString();
|
||||
TableStat stat = getTableStat(tableName);
|
||||
if (stat != null) {
|
||||
stat.incrementInsertCount();
|
||||
}
|
||||
}
|
||||
SQLExprTableSource into = x.getInto();
|
||||
// if (into != null && into.getExpr() instanceof SQLName) {
|
||||
// TableStat stat = getTableStat((SQLName) into.getExpr());
|
||||
// if (stat != null) {
|
||||
// stat.incrementInsertCount();
|
||||
// }
|
||||
// }
|
||||
|
||||
return visit((SQLSelectQueryBlock) x);
|
||||
}
|
||||
@@ -638,9 +636,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
public boolean visit(InsertIntoClause x) {
|
||||
|
||||
if (x.getTableName() instanceof SQLName) {
|
||||
String ident = ((SQLName) x.getTableName()).toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(x.getTableName());
|
||||
stat.incrementInsertCount();
|
||||
}
|
||||
|
||||
@@ -729,8 +725,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleLockTableStatement x) {
|
||||
String tableName = x.getTable().toString();
|
||||
getTableStat(tableName);
|
||||
getTableStat(x.getTable());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -902,11 +897,12 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
@Override
|
||||
public boolean visit(OracleAlterTableModify x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String table = stmt.getName().toString();
|
||||
SQLName tableName = stmt.getName();
|
||||
String table = tableName.toString();
|
||||
|
||||
for (SQLColumnDefinition column : x.getColumns()) {
|
||||
String columnName = column.getName().toString();
|
||||
addColumn(table, columnName);
|
||||
SQLName columnName = column.getName();
|
||||
addColumn(table, columnName.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -1333,7 +1329,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
}
|
||||
|
||||
if (sql != null) {
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, getDbType());
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(this);
|
||||
}
|
||||
|
||||
+2
-6
@@ -139,9 +139,7 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
|
||||
SQLName tableName = x.getTableName();
|
||||
{
|
||||
String ident = tableName.toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(tableName);
|
||||
stat.incrementInsertCount();
|
||||
}
|
||||
|
||||
@@ -181,9 +179,7 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
x.getWith().accept(this);
|
||||
}
|
||||
|
||||
String ident = x.getTableName().toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(x.getTableName());
|
||||
stat.incrementUpdateCount();
|
||||
|
||||
accept(x.getFrom());
|
||||
|
||||
+1
-3
@@ -84,9 +84,7 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerUpdateStatement x) {
|
||||
String ident = x.getTableName().toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(x.getTableName());
|
||||
stat.incrementUpdateCount();
|
||||
|
||||
accept(x.getItems());
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreatePackageStatemen
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import oracle.sql.SQLUtil;
|
||||
|
||||
import static com.alibaba.druid.util.Utils.getBoolean;
|
||||
|
||||
@@ -52,7 +53,6 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
protected final Appendable appender;
|
||||
private String indent = "\t";
|
||||
protected int indentCount = 0;
|
||||
protected boolean ucase = true;
|
||||
protected int selectListNumberOfLine = 5;
|
||||
@@ -111,6 +111,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (tableMapping == null) {
|
||||
tableMapping = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
if (srcTable.indexOf('.') >= 0) {
|
||||
SQLExpr expr = SQLUtils.toSQLExpr(srcTable, dbType);
|
||||
if (expr instanceof SQLPropertyExpr) {
|
||||
srcTable = ((SQLPropertyExpr) expr).simplify().toString();
|
||||
}
|
||||
} else {
|
||||
srcTable = SQLUtils.normalize(srcTable);
|
||||
}
|
||||
tableMapping.put(srcTable, destTable);
|
||||
}
|
||||
|
||||
@@ -207,7 +216,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
try {
|
||||
this.appender.append(value);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("println error", e);
|
||||
throw new RuntimeException("print error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +299,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
private static int paramCount(SQLExpr x) {
|
||||
if (x instanceof SQLName) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x instanceof SQLMethodInvokeExpr) {
|
||||
List<SQLExpr> params = ((SQLMethodInvokeExpr) x).getParameters();
|
||||
int paramCount = 1;
|
||||
@@ -319,14 +332,20 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
protected void printSelectList(List<SQLSelectItem> selectList) {
|
||||
this.indentCount++;
|
||||
for (int i = 0, lineItemCount = 0, size = selectList.size()
|
||||
; i < size; ++i, ++lineItemCount) {
|
||||
; i < size
|
||||
; ++i, ++lineItemCount)
|
||||
{
|
||||
SQLSelectItem selectItem = selectList.get(i);
|
||||
SQLExpr selectItemExpr = selectItem.getExpr();
|
||||
|
||||
int paramCount = paramCount(selectItemExpr);
|
||||
if (selectItemExpr instanceof SQLMethodInvokeExpr
|
||||
|
||||
boolean methodOrBinary = (!(selectItemExpr instanceof SQLName))
|
||||
&& (selectItemExpr instanceof SQLMethodInvokeExpr
|
||||
|| selectItemExpr instanceof SQLAggregateExpr
|
||||
|| selectItemExpr instanceof SQLBinaryOpExpr) {
|
||||
|| selectItemExpr instanceof SQLBinaryOpExpr);
|
||||
|
||||
if (methodOrBinary) {
|
||||
lineItemCount += (paramCount - 1);
|
||||
}
|
||||
|
||||
@@ -335,9 +354,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (preSelectItem.getAfterCommentsDirect() != null) {
|
||||
lineItemCount = 0;
|
||||
println();
|
||||
} else if (selectItemExpr instanceof SQLMethodInvokeExpr
|
||||
|| selectItemExpr instanceof SQLAggregateExpr
|
||||
|| selectItemExpr instanceof SQLBinaryOpExpr) {
|
||||
} else if (methodOrBinary) {
|
||||
if (lineItemCount >= selectListNumberOfLine) {
|
||||
lineItemCount = paramCount;
|
||||
println();
|
||||
@@ -376,9 +393,17 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
}
|
||||
|
||||
public void printIndent() {
|
||||
for (int i = 0; i < this.indentCount; ++i) {
|
||||
print0(this.indent);
|
||||
protected void printIndent() {
|
||||
if (this.appender == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
for (int i = 0; i < this.indentCount; ++i) {
|
||||
this.appender.append('\t');
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("print error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +413,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
return;
|
||||
}
|
||||
|
||||
print0("\n");
|
||||
print('\n');
|
||||
lines++;
|
||||
printIndent();
|
||||
}
|
||||
@@ -398,11 +423,6 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
println();
|
||||
}
|
||||
|
||||
protected void println0(String text) {
|
||||
print0(text);
|
||||
println();
|
||||
}
|
||||
|
||||
// ////////////////////
|
||||
|
||||
public boolean visit(SQLBetweenExpr x) {
|
||||
@@ -1658,24 +1678,28 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
if (JdbcConstants.INFORMIX.equals(dbType)) {
|
||||
final boolean informix =JdbcConstants.INFORMIX.equals(dbType);
|
||||
if (informix) {
|
||||
printFetchFirst(x);
|
||||
}
|
||||
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
|
||||
final int distinctOption = x.getDistionOption();
|
||||
if (SQLSetQuantifier.ALL == distinctOption) {
|
||||
print0(ucase ? "ALL " : "all ");
|
||||
} else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
|
||||
} else if (SQLSetQuantifier.DISTINCT == distinctOption) {
|
||||
print0(ucase ? "DISTINCT " : "distinct ");
|
||||
} else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) {
|
||||
} else if (SQLSetQuantifier.UNIQUE == distinctOption) {
|
||||
print0(ucase ? "UNIQUE " : "unique ");
|
||||
}
|
||||
|
||||
printSelectList(x.getSelectList());
|
||||
printSelectList(
|
||||
x.getSelectList());
|
||||
|
||||
if (x.getInto() != null) {
|
||||
SQLExprTableSource into = x.getInto();
|
||||
if (into != null) {
|
||||
println();
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
x.getInto().accept(this);
|
||||
into.accept(this);
|
||||
}
|
||||
|
||||
SQLTableSource from = x.getFrom();
|
||||
@@ -1689,7 +1713,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (where != null) {
|
||||
println();
|
||||
print0(ucase ? "WHERE " : "where ");
|
||||
where.accept(this);
|
||||
printExpr(where);
|
||||
}
|
||||
|
||||
printHierarchical(x);
|
||||
@@ -1706,7 +1730,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
orderBy.accept(this);
|
||||
}
|
||||
|
||||
if (!JdbcConstants.INFORMIX.equals(dbType)) {
|
||||
if (!informix) {
|
||||
printFetchFirst(x);
|
||||
}
|
||||
|
||||
@@ -1785,12 +1809,17 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
SQLExpr expr = x.getExpr();
|
||||
|
||||
printExpr(expr);
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
print0(((SQLIdentifierExpr) expr).getName());
|
||||
} else {
|
||||
printExpr(expr);
|
||||
}
|
||||
|
||||
String alias = x.getAlias();
|
||||
if (alias != null && alias.length() > 0) {
|
||||
print0(ucase ? " AS " : " as ");
|
||||
if (alias.indexOf(' ') == -1 || alias.charAt(0) == '"' || alias.charAt(0) == '\'') {
|
||||
char c0 = alias.charAt(0);
|
||||
if (alias.indexOf(' ') == -1 || c0 == '"' || c0 == '\'') {
|
||||
print0(alias);
|
||||
} else {
|
||||
print('"');
|
||||
|
||||
@@ -102,24 +102,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public TableStat getTableStat(String ident) {
|
||||
return getTableStat(ident, null);
|
||||
}
|
||||
|
||||
protected Column addColumn(String tableName, String columnName) {
|
||||
return addColumn(tableName, columnName, 0, 0);
|
||||
}
|
||||
|
||||
protected Column addColumn(String tableName, String columnName, long table_hash, long name_hash) {
|
||||
Column column = this.getColumn(tableName, columnName);
|
||||
if (column == null && columnName != null) {
|
||||
column = new Column(tableName, columnName);
|
||||
columns.put(column.hashCode64(), column);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
public TableStat getTableStat(String tableName, String alias) {
|
||||
public TableStat getTableStat(String tableName) {
|
||||
tableName = handleName(tableName);
|
||||
|
||||
TableStat.Name tableNameObj = new TableStat.Name(tableName);
|
||||
@@ -131,6 +114,49 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return stat;
|
||||
}
|
||||
|
||||
public TableStat getTableStat(SQLName tableName) {
|
||||
String strName = tableName.toString();
|
||||
long hashCode64 = tableName.hashCode64();
|
||||
|
||||
if (hashCode64 == FnvHash.Constants.DUAL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TableStat.Name tableNameObj = new TableStat.Name(strName, hashCode64);
|
||||
TableStat stat = tableStats.get(tableNameObj);
|
||||
if (stat == null) {
|
||||
stat = new TableStat();
|
||||
tableStats.put(new TableStat.Name(strName, hashCode64), stat);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
protected Column addColumn(String tableName, String columnName) {
|
||||
Column column = this.getColumn(tableName, columnName);
|
||||
if (column == null && columnName != null) {
|
||||
column = new Column(tableName, columnName);
|
||||
columns.put(column.hashCode64(), column);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
protected Column addColumn(SQLName table, String columnName) {
|
||||
String tableName = table.toString();
|
||||
long tableHashCode64 = table.hashCode64();
|
||||
|
||||
long basic = tableHashCode64;
|
||||
basic ^= '.';
|
||||
basic *= FnvHash.PRIME;
|
||||
long columnHashCode64 = FnvHash.hashCode64(basic, columnName);
|
||||
|
||||
Column column = this.columns.get(columnHashCode64);
|
||||
if (column == null && columnName != null) {
|
||||
column = new Column(tableName, columnName, columnHashCode64);
|
||||
columns.put(columnHashCode64, column);
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
private String handleName(String ident) {
|
||||
int len = ident.length();
|
||||
if (ident.charAt(0) == '[' && ident.charAt(len - 1) == ']') {
|
||||
@@ -171,9 +197,6 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return ident;
|
||||
}
|
||||
|
||||
public void setAliasMap() {
|
||||
}
|
||||
|
||||
protected Mode getMode() {
|
||||
return mode;
|
||||
}
|
||||
@@ -455,11 +478,11 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
protected SQLASTVisitor createOrderByVisitor(SQLOrderBy x) {
|
||||
final SQLASTVisitor orderByVisitor;
|
||||
if (JdbcConstants.MYSQL.equals(getDbType())) {
|
||||
if (JdbcConstants.MYSQL.equals(dbType)) {
|
||||
orderByVisitor = new MySqlOrderByStatVisitor(x);
|
||||
} else if (JdbcConstants.POSTGRESQL.equals(getDbType())) {
|
||||
} else if (JdbcConstants.POSTGRESQL.equals(dbType)) {
|
||||
orderByVisitor = new PGOrderByStatVisitor(x);
|
||||
} else if (JdbcConstants.ORACLE.equals(getDbType())) {
|
||||
} else if (JdbcConstants.ORACLE.equals(dbType)) {
|
||||
orderByVisitor = new OracleOrderByStatVisitor(x);
|
||||
} else {
|
||||
orderByVisitor = new OrderByStatVisitor(x);
|
||||
@@ -550,11 +573,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
Relationship relationship = new Relationship();
|
||||
relationship.setLeft(leftColumn);
|
||||
relationship.setRight(rightColumn);
|
||||
relationship.setOperator(operator);
|
||||
|
||||
Relationship relationship = new Relationship(leftColumn, rightColumn, operator);
|
||||
this.relationships.add(relationship);
|
||||
}
|
||||
|
||||
@@ -581,9 +600,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
|
||||
if (condition == null) {
|
||||
condition = new Condition();
|
||||
condition.setColumn(column);
|
||||
condition.setOperator(operator);
|
||||
condition = new Condition(column, operator);
|
||||
this.conditions.add(condition);
|
||||
}
|
||||
|
||||
@@ -592,7 +609,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (valueColumn != null) {
|
||||
continue;
|
||||
}
|
||||
Object value = SQLEvalVisitorUtils.eval(getDbType(), item, parameters, false);
|
||||
Object value = SQLEvalVisitorUtils.eval(dbType, item, parameters, false);
|
||||
if (value == SQLEvalVisitor.EVAL_VALUE_NULL) {
|
||||
value = null;
|
||||
}
|
||||
@@ -617,13 +634,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
String column = propertyExpr.getName();
|
||||
|
||||
if (owner instanceof SQLName) {
|
||||
String tableName = owner.toString();
|
||||
String table = tableName;
|
||||
// String tableNameLower = tableName.toLowerCase();
|
||||
//
|
||||
// if (aliasMap.containsKey(tableNameLower)) {
|
||||
// table = aliasMap.get(tableNameLower);
|
||||
// }
|
||||
SQLName table = (SQLName) owner;
|
||||
|
||||
SQLObject resolvedOwnerObject = propertyExpr.getResolvedOwnerObject();
|
||||
if (resolvedOwnerObject instanceof SQLSubqueryTableSource
|
||||
@@ -635,12 +646,19 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (resolvedOwnerObject instanceof SQLExprTableSource) {
|
||||
SQLExpr tableSourceExpr = ((SQLExprTableSource) resolvedOwnerObject).getExpr();
|
||||
if (tableSourceExpr instanceof SQLName) {
|
||||
table = tableSourceExpr.toString();
|
||||
table = (SQLName) tableSourceExpr;
|
||||
}
|
||||
}
|
||||
|
||||
if (table != null) {
|
||||
return new Column(table, column);
|
||||
long tableHashCode64 = table.hashCode64();
|
||||
|
||||
long basic = tableHashCode64;
|
||||
basic ^= '.';
|
||||
basic *= FnvHash.PRIME;
|
||||
long columnHashCode64 = FnvHash.hashCode64(basic, column);
|
||||
|
||||
return new Column(table.toString(), column, columnHashCode64);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,27 +681,28 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
String column = identifierExpr.getName();
|
||||
|
||||
String table = null;
|
||||
SQLName table = null;
|
||||
SQLTableSource tableSource = identifierExpr.getResolvedTableSource();
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLExpr tableSourceExpr = ((SQLExprTableSource) tableSource).getExpr();
|
||||
SQLName tableName = null;
|
||||
|
||||
if (tableSourceExpr != null && !(tableSourceExpr instanceof SQLName)) {
|
||||
tableSourceExpr = unwrapExpr(tableSourceExpr);
|
||||
}
|
||||
|
||||
if (tableSourceExpr instanceof SQLName) {
|
||||
tableName = (SQLName) tableSourceExpr;
|
||||
}
|
||||
|
||||
if (tableName != null) {
|
||||
table = tableName.toString();
|
||||
table = (SQLName) tableSourceExpr;
|
||||
}
|
||||
}
|
||||
|
||||
if (table != null) {
|
||||
return new Column(table, column);
|
||||
long tableHashCode64 = table.hashCode64();
|
||||
long basic = tableHashCode64;
|
||||
basic ^= '.';
|
||||
basic *= FnvHash.PRIME;
|
||||
long columnHashCode64 = FnvHash.hashCode64(basic, column);
|
||||
|
||||
return new Column(table.toString(), column, columnHashCode64);
|
||||
}
|
||||
|
||||
return new Column("UNKNOWN", column);
|
||||
@@ -809,10 +828,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
for (SQLExprTableSource tableSource : x.getTableSources()) {
|
||||
SQLName name = (SQLName) tableSource.getExpr();
|
||||
|
||||
String ident = name.toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(name);
|
||||
stat.incrementDeleteCount();
|
||||
}
|
||||
|
||||
@@ -831,9 +847,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
for (SQLExprTableSource tableSource : x.getTableSources()) {
|
||||
SQLName name = (SQLName) tableSource.getExpr();
|
||||
String ident = name.toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(name);
|
||||
stat.incrementDropCount();
|
||||
}
|
||||
|
||||
@@ -852,7 +866,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (x.getTableName() instanceof SQLName) {
|
||||
String ident = ((SQLName) x.getTableName()).toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(x.getTableName());
|
||||
stat.incrementInsertCount();
|
||||
}
|
||||
|
||||
@@ -905,8 +919,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
boolean isParam = intoExpr instanceof SQLIdentifierExpr && isParam((SQLIdentifierExpr) intoExpr);
|
||||
|
||||
if (!isParam) {
|
||||
String ident = intoExpr.toString();
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(intoExpr);
|
||||
if (stat != null) {
|
||||
stat.incrementInsertCount();
|
||||
}
|
||||
@@ -972,7 +985,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isParam(SQLIdentifierExpr x) {
|
||||
private static boolean isParam(SQLIdentifierExpr x) {
|
||||
if (x.getResolvedParameter() != null
|
||||
|| x.getResolvedDeclareItem() != null) {
|
||||
return true;
|
||||
@@ -1048,7 +1061,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
column = addColumn(table.getName(), ident, table.nameHashCode64(), x.nameHashCode64());
|
||||
column = addColumn(table.getName(), ident);
|
||||
|
||||
if (column != null && isParentGroupBy(x)) {
|
||||
this.groupByColumns.add(column);
|
||||
@@ -1056,7 +1069,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
} else if (expr instanceof SQLPropertyExpr) {
|
||||
SQLPropertyExpr table = (SQLPropertyExpr) expr;
|
||||
String tableName = table.toString();
|
||||
column = addColumn(tableName, ident, 0, x.nameHashCode64());
|
||||
column = addColumn(tableName, ident);
|
||||
|
||||
if (column != null && isParentGroupBy(x)) {
|
||||
this.groupByColumns.add(column);
|
||||
@@ -1085,7 +1098,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
tableName = table.toString();
|
||||
}
|
||||
|
||||
column = addColumn(tableName, ident, 0, x.nameHashCode64());
|
||||
column = addColumn(tableName, ident);
|
||||
}
|
||||
}
|
||||
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
|
||||
@@ -1135,11 +1148,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String aliasWrap(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isPseudoColumn(long hash) {
|
||||
protected boolean isPseudoColumn(long hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1183,14 +1192,14 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLExpr expr = ((SQLExprTableSource) tableSource).getExpr();
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr table = (SQLIdentifierExpr) expr;
|
||||
column = addColumn(table.getName(), ident, table.nameHashCode64(), hash);
|
||||
column = addColumn(table, ident);
|
||||
|
||||
if (column != null && isParentGroupBy(x)) {
|
||||
this.groupByColumns.add(column);
|
||||
}
|
||||
} else if (expr instanceof SQLPropertyExpr || expr instanceof OracleDbLinkExpr) {
|
||||
String tableName = expr.toString();
|
||||
column = addColumn(tableName, ident, 0, hash);
|
||||
column = addColumn(tableName, ident);
|
||||
|
||||
if (column != null && isParentGroupBy(x)) {
|
||||
this.groupByColumns.add(column);
|
||||
@@ -1219,7 +1228,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
tableName = table.toString();
|
||||
}
|
||||
|
||||
column = addColumn(tableName, ident, 0, x.nameHashCode64());
|
||||
column = addColumn(tableName, ident);
|
||||
}
|
||||
}
|
||||
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
|
||||
@@ -1263,31 +1272,29 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
|
||||
private boolean isParentSelectItem(SQLObject parent) {
|
||||
if (parent == null) {
|
||||
return false;
|
||||
for (; parent != null; parent = parent.getParent()) {
|
||||
if (parent instanceof SQLSelectItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parent instanceof SQLSelectQueryBlock) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof SQLSelectItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parent instanceof SQLSelectQueryBlock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isParentSelectItem(parent.getParent());
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isParentGroupBy(SQLObject parent) {
|
||||
if (parent == null) {
|
||||
return false;
|
||||
for (; parent != null; parent = parent.getParent()) {
|
||||
if (parent instanceof SQLSelectItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parent instanceof SQLSelectGroupByClause) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof SQLSelectGroupByClause) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return isParentGroupBy(parent.getParent());
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setColumn(SQLExpr x, Column column) {
|
||||
@@ -1362,7 +1369,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (e instanceof SQLColumnDefinition) {
|
||||
SQLColumnDefinition columnDefinition = (SQLColumnDefinition) e;
|
||||
SQLName columnName = columnDefinition.getName();
|
||||
Column column = addColumn(tableName.toString(), columnName.toString(), tableName.hashCode64(), columnName.hashCode64());
|
||||
Column column = addColumn(tableName.toString(), columnName.toString());
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
@@ -1458,12 +1465,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
|
||||
public TableStat getTableStat(SQLExprTableSource tableSource) {
|
||||
return getTableStat(
|
||||
return getTableStatWithUnwrap(
|
||||
tableSource.getExpr());
|
||||
}
|
||||
|
||||
public TableStat getTableStat(SQLExpr expr) {
|
||||
String ident = null;
|
||||
private TableStat getTableStatWithUnwrap(SQLExpr expr) {
|
||||
SQLExpr identExpr = null;
|
||||
|
||||
expr = unwrapExpr(expr);
|
||||
|
||||
@@ -1489,21 +1496,24 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLExpr tableSourceExpr = ((SQLExprTableSource) tableSource).getExpr();
|
||||
if (tableSourceExpr instanceof SQLName) {
|
||||
ident = tableSourceExpr.toString();
|
||||
identExpr = tableSourceExpr;
|
||||
}
|
||||
}
|
||||
|
||||
if (ident == null) {
|
||||
ident = expr.toString();
|
||||
if (identExpr == null) {
|
||||
identExpr = expr;
|
||||
}
|
||||
|
||||
return getTableStat(ident);
|
||||
if (identExpr instanceof SQLName) {
|
||||
return getTableStat((SQLName) identExpr);
|
||||
}
|
||||
return getTableStat(identExpr.toString());
|
||||
}
|
||||
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
if (isSimpleExprTableSource(x)) {
|
||||
SQLExpr expr = x.getExpr();
|
||||
TableStat stat = getTableStat(expr);
|
||||
TableStat stat = getTableStatWithUnwrap(expr);
|
||||
if (stat == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -1649,9 +1659,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLTableSource tableSource = x.getTableSource();
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLName identName = ((SQLExprTableSource) tableSource).getName();
|
||||
String ident = identName.toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(identName);
|
||||
stat.incrementUpdateCount();
|
||||
} else {
|
||||
tableSource.accept(this);
|
||||
@@ -1673,8 +1681,6 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
setMode(x, Mode.Delete);
|
||||
|
||||
String tableName = x.getTableName().toString();
|
||||
|
||||
if (x.getTableSource() instanceof SQLSubqueryTableSource) {
|
||||
SQLSelectQuery selectQuery = ((SQLSubqueryTableSource) x.getTableSource()).getSelect().getQuery();
|
||||
if (selectQuery instanceof SQLSelectQueryBlock) {
|
||||
@@ -1683,7 +1689,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
TableStat stat = getTableStat(tableName);
|
||||
TableStat stat = getTableStat(x.getTableName());
|
||||
stat.incrementDeleteCount();
|
||||
|
||||
accept(x.getWhere());
|
||||
@@ -1728,9 +1734,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
e.setParent(x);
|
||||
}
|
||||
|
||||
String tableName = x.getName().toString();
|
||||
|
||||
TableStat stat = getTableStat(tableName);
|
||||
TableStat stat = getTableStat(x.getName());
|
||||
stat.incrementCreateCount();
|
||||
|
||||
accept(x.getTableElementList());
|
||||
@@ -1854,8 +1858,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
String tableName = x.getName().toString();
|
||||
TableStat stat = getTableStat(tableName);
|
||||
TableStat stat = getTableStat(x.getName());
|
||||
stat.incrementAlterCount();
|
||||
|
||||
|
||||
@@ -1878,10 +1881,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLExprTableSource table = x.getTableName();
|
||||
if (table != null) {
|
||||
SQLName name = (SQLName) table.getExpr();
|
||||
|
||||
String ident = name.toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(name);
|
||||
stat.incrementDropIndexCount();
|
||||
}
|
||||
return false;
|
||||
@@ -1895,7 +1895,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
String table = name.toString();
|
||||
|
||||
TableStat stat = getTableStat(table);
|
||||
TableStat stat = getTableStat(name);
|
||||
stat.incrementCreateIndexCount();
|
||||
|
||||
for (SQLSelectOrderByItem item : x.getItems()) {
|
||||
@@ -1919,7 +1919,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
String table = x.getReferencedTableName().getSimpleName();
|
||||
|
||||
TableStat stat = getTableStat(table);
|
||||
TableStat stat = getTableStat(x.getReferencedTableName());
|
||||
stat.incrementReferencedCount();
|
||||
for (SQLName column : x.getReferencedColumns()) {
|
||||
String columnName = column.getSimpleName();
|
||||
@@ -1971,7 +1971,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
item.accept(this);
|
||||
}
|
||||
|
||||
String table = ((SQLAlterTableStatement) x.getParent()).getName().toString();
|
||||
SQLName table = ((SQLAlterTableStatement) x.getParent()).getName();
|
||||
TableStat tableStat = this.getTableStat(table);
|
||||
tableStat.incrementCreateIndexCount();
|
||||
return false;
|
||||
@@ -2240,9 +2240,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLConstraint constraint = x.getConstraint();
|
||||
if (constraint instanceof SQLUniqueConstraint) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String tableName = stmt.getName().toString();
|
||||
|
||||
TableStat tableStat = this.getTableStat(tableName);
|
||||
TableStat tableStat = this.getTableStat(stmt.getName());
|
||||
tableStat.incrementCreateIndexCount();
|
||||
}
|
||||
return true;
|
||||
@@ -2251,9 +2249,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropIndex x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String tableName = stmt.getName().toString();
|
||||
|
||||
TableStat tableStat = this.getTableStat(tableName);
|
||||
TableStat tableStat = this.getTableStat(stmt.getName());
|
||||
tableStat.incrementDropIndexCount();
|
||||
return false;
|
||||
}
|
||||
@@ -2261,9 +2257,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropPrimaryKey x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String tableName = stmt.getName().toString();
|
||||
|
||||
TableStat tableStat = this.getTableStat(tableName);
|
||||
TableStat tableStat = this.getTableStat(stmt.getName());
|
||||
tableStat.incrementDropIndexCount();
|
||||
return false;
|
||||
}
|
||||
@@ -2271,9 +2265,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropKey x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String tableName = stmt.getName().toString();
|
||||
|
||||
TableStat tableStat = this.getTableStat(tableName);
|
||||
TableStat tableStat = this.getTableStat(stmt.getName());
|
||||
tableStat.incrementDropIndexCount();
|
||||
return false;
|
||||
}
|
||||
@@ -2282,7 +2274,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLDescribeStatement x) {
|
||||
String tableName = x.getObject().toString();
|
||||
|
||||
TableStat tableStat = this.getTableStat(tableName);
|
||||
TableStat tableStat = this.getTableStat(x.getObject());
|
||||
tableStat.incrementDropIndexCount();
|
||||
|
||||
SQLName column = x.getColumn();
|
||||
|
||||
@@ -189,8 +189,12 @@ public class TableStat {
|
||||
private final long hashCode64;
|
||||
|
||||
public Name(String name){
|
||||
this(name, FnvHash.hashCode64(name));
|
||||
}
|
||||
|
||||
public Name(String name, long hashCode64){
|
||||
this.name = name;
|
||||
hashCode64 = FnvHash.hashCode64(name);
|
||||
this.hashCode64 = hashCode64;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -225,34 +229,24 @@ public class TableStat {
|
||||
private Column right;
|
||||
private String operator;
|
||||
|
||||
public Relationship(){
|
||||
|
||||
public Relationship(Column left, Column right, String operator) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public Column getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setLeft(Column left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public Column getRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setRight(Column right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public void setOperator(String operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -308,27 +302,23 @@ public class TableStat {
|
||||
|
||||
public static class Condition {
|
||||
|
||||
private Column column;
|
||||
private String operator;
|
||||
private final Column column;
|
||||
private final String operator;
|
||||
private final List<Object> values = new ArrayList<Object>();
|
||||
|
||||
private List<Object> values = new ArrayList<Object>();
|
||||
public Condition(Column column, String operator) {
|
||||
this.column = column;
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public Column getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public void setColumn(Column column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public void setOperator(String operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public List<Object> getValues() {
|
||||
return values;
|
||||
}
|
||||
@@ -440,6 +430,12 @@ public class TableStat {
|
||||
}
|
||||
}
|
||||
|
||||
public Column(String table, String name, long hashCode64){
|
||||
this.table = table;
|
||||
this.name = name;
|
||||
this.hashCode64 = hashCode64;
|
||||
}
|
||||
|
||||
public String getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,10 @@ public final class FnvHash {
|
||||
}
|
||||
|
||||
public static long hashCode64(long basic, String name) {
|
||||
if (name == null) {
|
||||
return basic;
|
||||
}
|
||||
|
||||
boolean quote = false;
|
||||
|
||||
int len = name.length();
|
||||
@@ -387,5 +391,12 @@ public final class FnvHash {
|
||||
long RECURSIVE = fnv1a_64_lower("RECURSIVE");
|
||||
long ROLLUP = fnv1a_64_lower("ROLLUP");
|
||||
long CUBE = fnv1a_64_lower("CUBE");
|
||||
|
||||
long YEAR = fnv1a_64_lower("YEAR");
|
||||
long MONTH = fnv1a_64_lower("MONTH");
|
||||
long DAY = fnv1a_64_lower("DAY");
|
||||
long HOUR = fnv1a_64_lower("HOUR");
|
||||
long MINUTE = fnv1a_64_lower("MINUTE");
|
||||
long SECOND = fnv1a_64_lower("SECOND");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user