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:
@@ -117,7 +117,7 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
|
||||
public SQLParameter findParameter(long hash) {
|
||||
for (SQLParameter param : this.parameters) {
|
||||
if (param.getName().name_hash_lower() == hash) {
|
||||
if (param.getName().nameHashCode64() == hash) {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class SQLCharacterDataType extends SQLDataTypeImpl {
|
||||
|
||||
|
||||
public SQLCharacterDataType clone() {
|
||||
SQLCharacterDataType x = new SQLCharacterDataType(name);
|
||||
SQLCharacterDataType x = new SQLCharacterDataType(getName());
|
||||
|
||||
super.cloneTo(x);
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ public class SQLCreateProcedureStatement extends SQLStatementImpl implements SQL
|
||||
|
||||
public SQLParameter findParameter(long hash) {
|
||||
for (SQLParameter param : this.parameters) {
|
||||
if (param.getName().name_hash_lower() == hash) {
|
||||
if (param.getName().nameHashCode64() == hash) {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
@@ -24,14 +23,12 @@ import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.ListDG;
|
||||
import com.alibaba.druid.util.lang.Consumer;
|
||||
import oracle.sql.SQLUtil;
|
||||
|
||||
public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLStatement, SQLCreateStatement {
|
||||
|
||||
@@ -239,7 +236,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(columName);
|
||||
long hash = FnvHash.hashCode64(columName);
|
||||
return findColumn(hash);
|
||||
}
|
||||
|
||||
@@ -248,7 +245,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
if (element instanceof SQLColumnDefinition) {
|
||||
SQLColumnDefinition column = (SQLColumnDefinition) element;
|
||||
SQLName columnName = column.getName();
|
||||
if (columnName != null && columnName.name_hash_lower() == columName_hash) {
|
||||
if (columnName != null && columnName.nameHashCode64() == columName_hash) {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,10 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.repository.SchemaObject;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
|
||||
@@ -218,13 +217,13 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
}
|
||||
|
||||
public boolean containsAlias(long aliasHash) {
|
||||
if (this.alias_hash() == aliasHash) {
|
||||
if (this.aliasHashCode64() == aliasHash) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (expr instanceof SQLName) {
|
||||
long exprNameHash = ((SQLName) expr).name_hash_lower();
|
||||
return exprNameHash == alias_hash;
|
||||
long exprNameHash = ((SQLName) expr).nameHashCode64();
|
||||
return exprNameHash == aliasHashCod64;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -235,7 +234,7 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
|
||||
long hash = FnvHash.hashCode64(columnName);
|
||||
return findColumn(hash);
|
||||
}
|
||||
|
||||
@@ -257,7 +256,7 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
|
||||
long hash = FnvHash.hashCode64(columnName);
|
||||
return findTableSourceWithColumn(hash);
|
||||
}
|
||||
|
||||
@@ -287,12 +286,12 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (alias_hash() == alias_hash) {
|
||||
if (aliasHashCode64() == alias_hash) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (expr instanceof SQLName) {
|
||||
long exprNameHash = ((SQLName) expr).name_hash_lower();
|
||||
long exprNameHash = ((SQLName) expr).nameHashCode64();
|
||||
if (exprNameHash == alias_hash) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -20,15 +20,12 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplaceable {
|
||||
|
||||
@@ -417,7 +414,7 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
}
|
||||
|
||||
public SQLColumnDefinition findColumn(String columnName) {
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
|
||||
long hash = FnvHash.hashCode64(columnName);
|
||||
return findColumn(hash);
|
||||
}
|
||||
|
||||
@@ -438,7 +435,7 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
|
||||
@Override
|
||||
public SQLTableSource findTableSourceWithColumn(String columnName) {
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
|
||||
long hash = FnvHash.hashCode64(columnName);
|
||||
return findTableSourceWithColumn(hash);
|
||||
}
|
||||
|
||||
@@ -533,7 +530,7 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
return null;
|
||||
}
|
||||
|
||||
if (alias_hash() == alias_hash) {
|
||||
if (aliasHashCode64() == alias_hash) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
|
||||
protected boolean connectByRoot = false;
|
||||
|
||||
protected transient long alias_hash;
|
||||
protected transient long aliasHashCode64;
|
||||
|
||||
public SQLSelectItem(){
|
||||
|
||||
@@ -174,15 +174,15 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
return false;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(alias);
|
||||
long hash = FnvHash.hashCode64(alias);
|
||||
return match(hash);
|
||||
}
|
||||
|
||||
public long alias_hash() {
|
||||
if (this.alias_hash == 0) {
|
||||
this.alias_hash = FNVUtils.fnv_64_lower_normalized(alias);
|
||||
if (this.aliasHashCode64 == 0) {
|
||||
this.aliasHashCode64 = FnvHash.hashCode64(alias);
|
||||
}
|
||||
return alias_hash;
|
||||
return aliasHashCode64;
|
||||
}
|
||||
|
||||
public boolean match(long alias_hash) {
|
||||
@@ -202,7 +202,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
}
|
||||
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
return ((SQLIdentifierExpr) expr).name_hash_lower() == alias_hash;
|
||||
return ((SQLIdentifierExpr) expr).nameHashCode64() == alias_hash;
|
||||
}
|
||||
|
||||
if (expr instanceof SQLPropertyExpr) {
|
||||
@@ -216,7 +216,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((SQLPropertyExpr) expr).name_hash_lower() == alias_hash;
|
||||
return ((SQLPropertyExpr) expr).nameHashCode64() == alias_hash;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -21,9 +21,8 @@ import java.util.List;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.repository.SchemaObject;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery, SQLReplaceable {
|
||||
private boolean bracket = false;
|
||||
@@ -487,7 +486,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(ident);
|
||||
long hash = FnvHash.hashCode64(ident);
|
||||
return findSelectItem(hash);
|
||||
}
|
||||
|
||||
@@ -528,7 +527,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
|
||||
long hash = FnvHash.hashCode64(columnName);
|
||||
return from.findColumn(hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.ast.SQLObject;
|
||||
public interface SQLTableSource extends SQLObject {
|
||||
|
||||
String getAlias();
|
||||
long aliasHashCode64();
|
||||
|
||||
void setAlias(String alias);
|
||||
|
||||
|
||||
@@ -22,17 +22,13 @@ import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLHint;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTableSource {
|
||||
|
||||
protected String alias;
|
||||
|
||||
protected List<SQLHint> hints;
|
||||
|
||||
protected SQLExpr flashback;
|
||||
|
||||
protected long alias_hash;
|
||||
protected long aliasHashCod64;
|
||||
|
||||
public SQLTableSourceImpl(){
|
||||
|
||||
@@ -48,7 +44,7 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
this.alias_hash = 0L;
|
||||
this.aliasHashCod64 = 0L;
|
||||
}
|
||||
|
||||
public int getHintsSize() {
|
||||
@@ -97,12 +93,12 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
return false;
|
||||
}
|
||||
|
||||
public long alias_hash() {
|
||||
if (alias_hash == 0
|
||||
public long aliasHashCode64() {
|
||||
if (aliasHashCod64 == 0
|
||||
&& alias != null) {
|
||||
alias_hash = FNVUtils.fnv_64_lower_normalized(alias);
|
||||
aliasHashCod64 = FnvHash.hashCode64(alias);
|
||||
}
|
||||
return alias_hash;
|
||||
return aliasHashCod64;
|
||||
}
|
||||
|
||||
public SQLColumnDefinition findColumn(String columnName) {
|
||||
@@ -110,7 +106,7 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(alias);
|
||||
long hash = FnvHash.hashCode64(alias);
|
||||
return findColumn(hash);
|
||||
}
|
||||
|
||||
@@ -123,7 +119,7 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
return null;
|
||||
}
|
||||
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(alias);
|
||||
long hash = FnvHash.hashCode64(alias);
|
||||
return findTableSourceWithColumn(hash);
|
||||
}
|
||||
|
||||
@@ -132,12 +128,12 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSource(String alias) {
|
||||
long hash = FNVUtils.fnv_64_lower_normalized(alias);
|
||||
long hash = FnvHash.hashCode64(alias);
|
||||
return findTableSource(hash);
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSource(long alias_hash) {
|
||||
long hash = this.alias_hash();
|
||||
long hash = this.aliasHashCode64();
|
||||
if (hash != 0 && hash == alias_hash) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLWithSubqueryClause extends SQLObjectImpl {
|
||||
@@ -129,7 +128,7 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
|
||||
|
||||
public SQLTableSource findTableSourceWithColumn(long columnNameHash) {
|
||||
for (SQLName column : columns) {
|
||||
if (column.name_hash_lower() == columnNameHash) {
|
||||
if (column.nameHashCode64() == columnNameHash) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +142,7 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
|
||||
}
|
||||
|
||||
for (Entry entry : entries) {
|
||||
if (entry.alias_hash() == alias_hash) {
|
||||
if (entry.aliasHashCode64() == alias_hash) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user