Commit daadfce1 by wuchao

修复bug

parent f88168cb
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding"> <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component> </component>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package util;
public class ColumnMeta {
String database = null;
String schema;
String table;
String column;
public ColumnMeta(String schema, String table, String column) {
this.schema = schema;
this.table = table;
this.column = column;
}
public String getDatabase() {
return this.database;
}
public void setDatabase(String database) {
this.database = database;
}
public String getSchema() {
return this.schema;
}
public void setSchema(String schema) {
this.schema = schema;
}
public String getTable() {
return this.table;
}
public void setTable(String table) {
this.table = table;
}
public String getColumn() {
return this.column;
}
public void setColumn(String column) {
this.column = column;
}
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o != null && this.getClass() == o.getClass()) {
ColumnMeta that;
label57: {
that = (ColumnMeta)o;
if (this.database != null) {
if (this.database.equalsIgnoreCase(that.database)) {
break label57;
}
} else if (that.database == null) {
break label57;
}
return false;
}
label50: {
if (this.schema != null) {
if (this.schema.equalsIgnoreCase(that.schema)) {
break label50;
}
} else if (that.schema == null) {
break label50;
}
return false;
}
if (this.table != null) {
if (!this.table.equalsIgnoreCase(that.table)) {
return false;
}
} else if (that.table != null) {
return false;
}
if (this.column != null) {
if (!this.column.equalsIgnoreCase(that.column)) {
return false;
}
} else if (that.column != null) {
return false;
}
return true;
} else {
return false;
}
}
public int hashCode() {
int result = 17;
result = 31 * result + (this.database != null ? this.database.hashCode() : 0);
result = 31 * result + (this.schema != null ? this.schema.hashCode() : 0);
result = 31 * result + (this.table != null ? this.table.hashCode() : 0);
result = 31 * result + (this.column != null ? this.column.hashCode() : 0);
return result;
}
}
package util;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class ThreadLocalVariable {
private static ThreadLocal<Map> threadLocal = new ThreadLocal();
public ThreadLocalVariable() {
}
public static void remove() {
threadLocal.remove();
}
public static ThreadLocal<Map> getThreadLocal() {
return threadLocal;
}
public static boolean checkColumn(String schema, String table, String column) {
Map map = (Map)threadLocal.get();
if (map == null) {
return true;
} else {
Object columns = map.get("columns");
if (columns != null) {
Set<ColumnMeta> columnsSet = (HashSet)columns;
if (columnsSet.isEmpty()) {
return true;
} else {
ColumnMeta temp = new ColumnMeta(schema, table, column);
return columnsSet.contains(temp);
}
} else {
return true;
}
}
}
public static void setcolumns(Set<ColumnMeta> columnMetas) {
remove();
Map threadMap = new HashMap();
threadMap.put("columns", columnMetas);
ThreadLocal<Map> threadLocal = getThreadLocal();
threadLocal.set(threadMap);
}
}
...@@ -57,7 +57,7 @@ import java.util.HashMap; ...@@ -57,7 +57,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils; import com.chenyang.druid.util.StringUtils;
import util.DataUtil; import util.DataUtil;
import util.JdbcUtil; import util.JdbcUtil;
import util.SqlUtil; import util.SqlUtil;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -606,7 +606,7 @@ public class SqlServerParse { ...@@ -606,7 +606,7 @@ public class SqlServerParse {
public static String getSqlType(String sql, String dbType) { public static String getSqlType(String sql, String dbType) {
String sqlType = JdbcUtil.getSqlType(sql, dbType); String sqlType = JdbcUtil.getSqlType(sql, dbType);
if (org.apache.commons.lang.StringUtils.isNotEmpty(sqlType) && !"with_select".equalsIgnoreCase(sqlType)) { if (com.chenyang.druid.util.StringUtils.isNotEmpty(sqlType) && !"with_select".equalsIgnoreCase(sqlType)) {
return sqlType; return sqlType;
} else { } else {
SQLStatement sqlStatement = null; SQLStatement sqlStatement = null;
......
package util.sqlparse.visitor.common.scope;
import com.chenyang.druid.DbType;
import util.sqlparse.visitor.common.bean.FieldInfo;
import util.sqlparse.visitor.common.bean.TableInfo;
import util.sqlparse.visitor.common.memo.FieldMemo;
import util.sqlparse.visitor.common.memo.TableMemo;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class SQLParseUtils {
public SQLParseUtils() {
}
public static void getAtomTables(DbType dbType, FieldMemo field, List<TableMemo> tables, Map<String, TableInfo> tableMap, Map<String, TableInfo> atomTableMap) {
if (tables != null && tables.size() != 0) {
boolean common = false;
switch (dbType) {
default:
common = true;
if (common) {
Iterator i$ = tables.iterator();
while(i$.hasNext()) {
TableMemo table = (TableMemo)i$.next();
if (table.getChildren().size() == 0) {
TableInfo tableInfo = (TableInfo)tableMap.get(table.getAtomName());
if (tableInfo != null) {
atomTableMap.put(tableInfo.getAtomName(), tableInfo);
}
}
}
getTables(field, field.scope, tableMap, atomTableMap);
}
}
}
}
static void getTables(FieldMemo field, Scope scope, Map<String, TableInfo> tableMap, Map<String, TableInfo> atomTableMap) {
String name = field.name;
Iterator i$ = scope.getChildren().iterator();
while(true) {
Scope child;
label55:
while(true) {
if (!i$.hasNext()) {
return;
}
child = (Scope)i$.next();
List<FieldMemo> childFieldMap = child.getFieldMap().orderValues();
if (childFieldMap.isEmpty()) {
break;
}
FieldMemo fieldMemo = null;
Iterator i$3 = childFieldMap.iterator();
while(i$3.hasNext()) {
FieldMemo item = (FieldMemo)i$3.next();
if (item.name != null && item.alias != null && item.alias.equalsIgnoreCase(name)) {
fieldMemo = item;
break;
}
}
if (fieldMemo != null && !fieldMemo.tables.isEmpty() && fieldMemo.isSelectItem) {
i$3 = fieldMemo.tables.iterator();
while(true) {
if (!i$3.hasNext()) {
break label55;
}
TableMemo table = (TableMemo)i$3.next();
TableInfo tableInfo = (TableInfo)tableMap.get(table.getAtomName());
if (tableInfo != null) {
atomTableMap.put(tableInfo.getAtomName(), tableInfo);
}
}
}
}
getTables(field, child, tableMap, atomTableMap);
}
}
public static void getFieldInfos(FieldMemo fieldMemo, Map<String, FieldInfo> fields, Map<String, FieldInfo> output) {
getFieldInfosInternal(fieldMemo, fields, false, output);
}
public static void getSelectFieldInfos(FieldMemo fieldMemo, Map<String, FieldInfo> fields, Map<String, FieldInfo> output) {
getFieldInfosInternal(fieldMemo, fields, true, output);
}
static void getFieldInfosInternal(FieldMemo fieldMemo, Map<String, FieldInfo> fields, boolean onlySelectItem, Map<String, FieldInfo> output) {
if (fieldMemo.children != null && fieldMemo.children.size() != 0) {
Iterator i$ = fieldMemo.children.iterator();
while(i$.hasNext()) {
FieldMemo child = (FieldMemo)i$.next();
if (onlySelectItem) {
if (fieldMemo.scope == child.scope) {
getFieldInfosInternal(child, fields, onlySelectItem, output);
} else if (child.isSelectItem) {
getFieldInfosInternal(child, fields, onlySelectItem, output);
}
} else {
getFieldInfosInternal(child, fields, onlySelectItem, output);
}
}
} else {
String name = fieldMemo.getAtomName();
if (fields.containsKey(name)) {
FieldInfo fieldInfo = (FieldInfo)fields.get(name);
fieldInfo.getMemos().add(fieldMemo);
output.put(name, fieldInfo);
}
}
}
}
package util.sqlparse.visitor.common.scope; package util.sqlparse.visitor.common.scope;
import bean.Column; import bean.Column;
import com.chenyang.druid.sql.ast.SQLExpr; import com.chenyang.druid.sql.ast.*;
import com.chenyang.druid.sql.ast.SQLObject;
import com.chenyang.druid.sql.ast.SQLOrderBy;
import com.chenyang.druid.sql.ast.SQLOver;
import com.chenyang.druid.sql.ast.expr.SQLAllColumnExpr; import com.chenyang.druid.sql.ast.expr.SQLAllColumnExpr;
import com.chenyang.druid.sql.ast.expr.SQLBinaryOpExpr; import com.chenyang.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.chenyang.druid.sql.ast.expr.SQLCaseExpr; import com.chenyang.druid.sql.ast.expr.SQLCaseExpr;
...@@ -1138,6 +1135,28 @@ public class Scope extends ID { ...@@ -1138,6 +1135,28 @@ public class Scope extends ID {
field = value; field = value;
break; break;
} }
// 增加额外的查找逻辑:如果exprs为空但字段名称匹配
if (!found && value.exprs.isEmpty() && expr instanceof SQLName) {
String exprName = ((SQLName)expr).getSimpleName();
if (value.name != null && value.name.equalsIgnoreCase(exprName)) {
// 将表达式添加到字段的exprs列表中
value.exprs.add(expr);
field = value;
break;
}
}
// 增加更宽松的查找:通过字段名称匹配
if (!found && expr instanceof SQLName) {
String exprName = ((SQLName)expr).getSimpleName();
if (value.name != null && value.name.equalsIgnoreCase(exprName)) {
// 将表达式添加到字段的exprs列表中
value.exprs.add(expr);
field = value;
break;
}
}
} }
if (field != null) { if (field != null) {
......
...@@ -4,7 +4,7 @@ import bean.DataBase; ...@@ -4,7 +4,7 @@ import bean.DataBase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils; import com.chenyang.druid.util.StringUtils;
import org.bson.BsonString; import org.bson.BsonString;
import util.sqlparse.visitor.common.memo.FieldMemo; import util.sqlparse.visitor.common.memo.FieldMemo;
import util.sqlparse.visitor.common.memo.TableMemo; import util.sqlparse.visitor.common.memo.TableMemo;
......
...@@ -9,7 +9,7 @@ import java.util.ArrayList; ...@@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import com.chenyang.druid.util.StringUtils;
import org.bson.BsonDocument; import org.bson.BsonDocument;
import org.bson.BsonDouble; import org.bson.BsonDouble;
import util.StringJoin; import util.StringJoin;
...@@ -237,7 +237,7 @@ public class ScopeVisitor implements MongoVisitor<ParseResult> { ...@@ -237,7 +237,7 @@ public class ScopeVisitor implements MongoVisitor<ParseResult> {
BsonBasicNode bfilter = (BsonBasicNode)json; BsonBasicNode bfilter = (BsonBasicNode)json;
if (bfilter.value() instanceof String) { if (bfilter.value() instanceof String) {
String name = (String)bfilter.value(); String name = (String)bfilter.value();
if (StringUtils.isNotBlank(name) && name.length() > 0) { if (StringUtils.isNotEmpty(name) && name.length() > 0) {
if (name.substring(0, 1).equals("$")) { if (name.substring(0, 1).equals("$")) {
name = name.substring(1); name = name.substring(1);
} }
......
...@@ -4,7 +4,7 @@ import bean.DataBase; ...@@ -4,7 +4,7 @@ import bean.DataBase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils; import com.chenyang.druid.util.StringUtils;
import util.sqlparse.visitor.common.Objects; import util.sqlparse.visitor.common.Objects;
public class WhereVisitor implements MongoVisitor<Boolean> { public class WhereVisitor implements MongoVisitor<Boolean> {
......
...@@ -40,10 +40,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -40,10 +40,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
public void perform(List<SQLStatement> statements) { public void perform(List<SQLStatement> statements) {
if (statements != null && statements.size() != 0) { if (statements != null && statements.size() != 0) {
Iterator var2 = statements.iterator(); Iterator i$ = statements.iterator();
while(var2.hasNext()) { while(i$.hasNext()) {
SQLStatement statement = (SQLStatement)var2.next(); SQLStatement statement = (SQLStatement)i$.next();
statement.accept(this); statement.accept(this);
} }
...@@ -56,7 +56,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -56,7 +56,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLSelectStatement" + x.toString()); System.out.println("enter SQLSelectStatement" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -69,7 +69,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -69,7 +69,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(SQLInsertStatement x) { public boolean visit(SQLInsertStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -86,7 +86,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -86,7 +86,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(OracleMultiInsertStatement x) { public boolean visit(OracleMultiInsertStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -95,7 +95,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -95,7 +95,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(SQLUpdateStatement x) { public boolean visit(SQLUpdateStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -104,7 +104,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -104,7 +104,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(SQLMergeStatement x) { public boolean visit(SQLMergeStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -113,7 +113,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -113,7 +113,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(OracleUpdateStatement x) { public boolean visit(OracleUpdateStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -122,7 +122,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -122,7 +122,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(SQLDeleteStatement x) { public boolean visit(SQLDeleteStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -131,7 +131,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -131,7 +131,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(OracleDeleteStatement x) { public boolean visit(OracleDeleteStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -144,7 +144,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -144,7 +144,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLWithSubqueryClause" + x.toString()); System.out.println("enter SQLWithSubqueryClause" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -161,7 +161,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -161,7 +161,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString()); System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -178,7 +178,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -178,7 +178,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString()); System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -195,7 +195,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -195,7 +195,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter OracleSelectQueryBlock " + x.toString()); System.out.println("enter OracleSelectQueryBlock " + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -208,7 +208,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -208,7 +208,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(SQLUnionQuery x) { public boolean visit(SQLUnionQuery x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -217,7 +217,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -217,7 +217,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public boolean visit(SQLLateralViewTableSource x) { public boolean visit(SQLLateralViewTableSource x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -230,7 +230,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -230,7 +230,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLSubqueryTableSource" + x.toString()); System.out.println("enter SQLSubqueryTableSource" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -247,7 +247,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -247,7 +247,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter OracleSelectSubqueryTableSource" + x.toString()); System.out.println("enter OracleSelectSubqueryTableSource" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -268,7 +268,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -268,7 +268,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLUnionQueryTableSource" + x.toString()); System.out.println("enter SQLUnionQueryTableSource" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -303,7 +303,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -303,7 +303,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter OracleSelectTableReference " + x); System.out.println("enter OracleSelectTableReference " + x);
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
} else if (this.debug) { } else if (this.debug) {
System.out.println("begin OracleSelectTableReference" + x.toString()); System.out.println("begin OracleSelectTableReference" + x.toString());
} }
...@@ -312,7 +312,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -312,7 +312,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
} }
public void endVisit(OracleSelectTableReference x) { public void endVisit(OracleSelectTableReference x) {
if (!(x.getExpr() instanceof SQLIdentifierExpr) && !(x.getParent() instanceof SQLPropertyExpr)) { if (!(x.getExpr() instanceof SQLIdentifierExpr) && !(x.getExpr() instanceof SQLPropertyExpr)) {
if (this.debug) { if (this.debug) {
System.out.println("exit OracleSelectTableReference " + x); System.out.println("exit OracleSelectTableReference " + x);
} }
...@@ -326,10 +326,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -326,10 +326,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
protected void acceptChild(List<? extends SQLObject> children) { protected void acceptChild(List<? extends SQLObject> children) {
if (children != null && children.size() != 0) { if (children != null && children.size() != 0) {
Iterator var2 = children.iterator(); Iterator i$ = children.iterator();
while(var2.hasNext()) { while(i$.hasNext()) {
SQLObject child = (SQLObject)var2.next(); SQLObject child = (SQLObject)i$.next();
child.accept(this); child.accept(this);
} }
...@@ -344,10 +344,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor { ...@@ -344,10 +344,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
protected void visitChild(List<? extends SQLObject> x) { protected void visitChild(List<? extends SQLObject> x) {
if (x != null && x.size() != 0) { if (x != null && x.size() != 0) {
Iterator var2 = x.iterator(); Iterator i$ = x.iterator();
while(var2.hasNext()) { while(i$.hasNext()) {
SQLObject sqlObject = (SQLObject)var2.next(); SQLObject sqlObject = (SQLObject)i$.next();
this.visitChild(sqlObject); this.visitChild(sqlObject);
} }
......
package util.sqlparse.visitor.oracle.visitor;
import com.chenyang.druid.sql.ast.SQLObject;
import com.chenyang.druid.sql.ast.statement.*;
import com.chenyang.druid.sql.dialect.oracle.ast.stmt.OracleSelectJoin;
import com.chenyang.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
import com.chenyang.druid.sql.dialect.oracle.ast.stmt.OracleSelectTableReference;
import com.chenyang.druid.sql.dialect.oracle.visitor.DefaultOracleASTVisitor;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;
import com.chenyang.druid.stat.TableStat;
import util.sqlparse.visitor.common.scope.Scope;
public class PassViewVisitor extends DefaultOracleASTVisitor {
protected Scope scope;
protected String schema;
public PassViewVisitor(Scope scope, String schema) {
this.scope = scope;
this.schema = schema;
}
public boolean visit(OracleSelectJoin from) {
visit((SQLJoinTableSource)from);
return false;
}
public boolean visit(SQLJoinTableSource from) {
SQLJoinTableSource jts = from;
if (jts.getLeft() instanceof SQLExprTableSource || jts.getLeft() instanceof OracleSelectTableReference) {
SQLSelect subSelect = getViewTableSource(jts.getLeft());
if (subSelect != null)
subSelect.accept((SQLASTVisitor)this);
} else {
jts.getLeft().accept((SQLASTVisitor)this);
}
if (jts.getRight() instanceof SQLExprTableSource || jts.getRight() instanceof OracleSelectTableReference) {
SQLSelect subSelect = getViewTableSource(jts.getRight());
if (subSelect != null)
subSelect.accept((SQLASTVisitor)this);
} else {
jts.getRight().accept((SQLASTVisitor)this);
}
return false;
}
public boolean visit(OracleSelectTableReference from) {
if (from instanceof SQLExprTableSource || from instanceof OracleSelectTableReference) {
SQLSelect subSelect = getViewTableSource((SQLTableSource)from);
if (subSelect != null) {
subSelect.accept((SQLASTVisitor)this);
} else {
String selfSchema = from.getSchema();
if (null == selfSchema || selfSchema.length() == 0)
from.setSchema(this.schema);
}
}
return false;
}
private SQLSelect getViewTableSource(SQLTableSource ts) {
SQLExprTableSource e = (SQLExprTableSource)ts;
String name = e.getTableName();
if (name == null)
return null;
String schema = (e.getSchema() == null) ? this.scope.getDefaultSchema() : e.getSchema();
SQLSelect view = this.scope.context.getView(schema.toLowerCase(), name.toLowerCase());
if (view != null &&
this.scope.context.sqlType == TableStat.Mode.Select) {
SQLSubqueryTableSource subQuery = new SQLSubqueryTableSource();
String alias = (e.getAlias() == null) ? e.getTableName() : e.getAlias();
subQuery.setAlias(alias);
subQuery.setSelect(view.clone());
SQLObject parent = ts.getParent();
if (parent instanceof OracleSelectQueryBlock) {
OracleSelectQueryBlock block = (OracleSelectQueryBlock)parent;
block.setFrom((SQLTableSource)subQuery);
subQuery.setParent(parent);
} else if (parent instanceof OracleSelectJoin) {
OracleSelectJoin join = (OracleSelectJoin)parent;
if (join.getLeft() == ts) {
join.setLeft((SQLTableSource)subQuery);
} else {
join.setRight((SQLTableSource)subQuery);
}
}
return subQuery.getSelect();
}
return null;
}
}
...@@ -5,6 +5,7 @@ import bean.Schema; ...@@ -5,6 +5,7 @@ import bean.Schema;
import bean.Table; import bean.Table;
import bean.View; import bean.View;
import com.chenyang.druid.util.StringUtils; import com.chenyang.druid.util.StringUtils;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import util.getdata.DatabaseCache; import util.getdata.DatabaseCache;
import util.sqlparse.visitor.common.names.NameWrapper; import util.sqlparse.visitor.common.names.NameWrapper;
...@@ -63,7 +64,7 @@ public class PostgresqlNameWrapper extends NameWrapper { ...@@ -63,7 +64,7 @@ public class PostgresqlNameWrapper extends NameWrapper {
} else { } else {
String column = c.getColumnName(); String column = c.getColumnName();
if (column != null && column.length() != 0) { if (column != null && column.length() != 0) {
ColInfo colInfo = this.getColumnInfo(c); NameWrapper.ColInfo colInfo = this.getColumnInfo(c);
if (colInfo.schema == null) { if (colInfo.schema == null) {
colInfo.schema = this.defschema; colInfo.schema = this.defschema;
} }
...@@ -91,13 +92,18 @@ public class PostgresqlNameWrapper extends NameWrapper { ...@@ -91,13 +92,18 @@ public class PostgresqlNameWrapper extends NameWrapper {
if (sch != null) { if (sch != null) {
return sch; return sch;
} else { } else {
for(Map.Entry<String, Schema> pair : schemas.entrySet()) { Iterator i$ = schemas.entrySet().iterator();
if (((String)pair.getKey()).equalsIgnoreCase(schema)) {
return (Schema)pair.getValue(); Map.Entry pair;
do {
if (!i$.hasNext()) {
return null;
} }
}
return null; pair = (Map.Entry)i$.next();
} while(!((String)pair.getKey()).equalsIgnoreCase(schema));
return (Schema)pair.getValue();
} }
} }
} }
...@@ -119,25 +125,31 @@ public class PostgresqlNameWrapper extends NameWrapper { ...@@ -119,25 +125,31 @@ public class PostgresqlNameWrapper extends NameWrapper {
} else { } else {
table = table.trim(); table = table.trim();
Map<String, Table> tables = this.cache.getTables(); Map<String, Table> tables = this.cache.getTables();
String id;
if (table.startsWith("\"")) { if (table.startsWith("\"")) {
table = this.unwrapName(table); table = this.unwrapName(table);
String id = this.cache.getSchemaTableId(sch.getName(), table); id = this.cache.getSchemaTableId(sch.getName(), table);
return (Table)tables.get(id); return (Table)tables.get(id);
} else { } else {
table = this.unwrapName(table); table = this.unwrapName(table);
table = table.toUpperCase(); table = table.toUpperCase();
String id = this.cache.getSchemaTableId(sch.getName(), table); id = this.cache.getSchemaTableId(sch.getName(), table);
Table tb = (Table)tables.get(id); Table tb = (Table)tables.get(id);
if (tb != null) { if (tb != null) {
return tb; return tb;
} else { } else {
for(Map.Entry<String, Table> pair : tables.entrySet()) { Iterator i$ = tables.entrySet().iterator();
if (((String)pair.getKey()).equalsIgnoreCase(id)) {
return (Table)pair.getValue(); Map.Entry pair;
do {
if (!i$.hasNext()) {
return null;
} }
}
return null; pair = (Map.Entry)i$.next();
} while(!((String)pair.getKey()).equalsIgnoreCase(id));
return (Table)pair.getValue();
} }
} }
} }
...@@ -156,7 +168,7 @@ public class PostgresqlNameWrapper extends NameWrapper { ...@@ -156,7 +168,7 @@ public class PostgresqlNameWrapper extends NameWrapper {
} }
} }
public void unwrapColumn(ColInfo colInfo) { public void unwrapColumn(NameWrapper.ColInfo colInfo) {
String schema = colInfo.schema; String schema = colInfo.schema;
String table = colInfo.table; String table = colInfo.table;
String col = colInfo.column; String col = colInfo.column;
...@@ -175,8 +187,10 @@ public class PostgresqlNameWrapper extends NameWrapper { ...@@ -175,8 +187,10 @@ public class PostgresqlNameWrapper extends NameWrapper {
col = col.trim(); col = col.trim();
boolean isCase = col.startsWith("\""); boolean isCase = col.startsWith("\"");
col = this.unwrapName(col); col = this.unwrapName(col);
Iterator i$ = tb.getColumnList().iterator();
for(Column column : tb.getColumnList()) { while(i$.hasNext()) {
Column column = (Column)i$.next();
if (isCase) { if (isCase) {
if (column.getColumnName().equals(col)) { if (column.getColumnName().equals(col)) {
colInfo.column = column.getColumnName(); colInfo.column = column.getColumnName();
......
...@@ -14,6 +14,7 @@ import com.chenyang.druid.sql.ast.statement.SQLSelectQuery; ...@@ -14,6 +14,7 @@ import com.chenyang.druid.sql.ast.statement.SQLSelectQuery;
import com.chenyang.druid.sql.ast.statement.SQLSelectStatement; import com.chenyang.druid.sql.ast.statement.SQLSelectStatement;
import com.chenyang.druid.sql.ast.statement.SQLTableSource; import com.chenyang.druid.sql.ast.statement.SQLTableSource;
import com.chenyang.druid.sql.ast.statement.SQLUpdateStatement; import com.chenyang.druid.sql.ast.statement.SQLUpdateStatement;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import util.JdbcUtil; import util.JdbcUtil;
...@@ -25,6 +26,9 @@ import util.sqlparse.visitor.postgresql.PostgresqlNameWrapper; ...@@ -25,6 +26,9 @@ import util.sqlparse.visitor.postgresql.PostgresqlNameWrapper;
import util.sqlparse.visitor.postgresql.SQLParser; import util.sqlparse.visitor.postgresql.SQLParser;
public class Desensitization { public class Desensitization {
public Desensitization() {
}
public Map parseColumn(Map params) { public Map parseColumn(Map params) {
return this.parseData(params); return this.parseData(params);
} }
...@@ -36,8 +40,10 @@ public class Desensitization { ...@@ -36,8 +40,10 @@ public class Desensitization {
params.put("newSql", sql); params.put("newSql", sql);
String url = (String)params.get("url"); String url = (String)params.get("url");
String ipPort = PostgreSqlParse.getIpPort(url); String ipPort = PostgreSqlParse.getIpPort(url);
Iterator i$ = JdbcUtil.dataBaseList.iterator();
for(DataBase base : JdbcUtil.dataBaseList) { while(i$.hasNext()) {
DataBase base = (DataBase)i$.next();
if (base.getIp_port().equalsIgnoreCase(ipPort)) { if (base.getIp_port().equalsIgnoreCase(ipPort)) {
dataBase = base; dataBase = base;
} }
...@@ -61,9 +67,14 @@ public class Desensitization { ...@@ -61,9 +67,14 @@ public class Desensitization {
SQLResult result = this.getSqlResult(params); SQLResult result = this.getSqlResult(params);
List<TableInfo> tables = result.tables; List<TableInfo> tables = result.tables;
params.put("isMatched", "false"); params.put("isMatched", "false");
Iterator i$ = tables.iterator();
while(i$.hasNext()) {
TableInfo table = (TableInfo)i$.next();
Iterator i$1 = table.getMemos().iterator();
for(TableInfo table : tables) { while(i$1.hasNext()) {
for(TableMemo tableMemo : table.getMemos()) { TableMemo tableMemo = (TableMemo)i$1.next();
String sourceName = PostgresqlNameWrapper.normalize(tableMemo.name); String sourceName = PostgresqlNameWrapper.normalize(tableMemo.name);
boolean isMatched = JdbcUtil.followRulesCaseSens(sourceName, "\"?" + replaceTable + "\"?"); boolean isMatched = JdbcUtil.followRulesCaseSens(sourceName, "\"?" + replaceTable + "\"?");
if (isMatched) { if (isMatched) {
...@@ -97,7 +108,7 @@ public class Desensitization { ...@@ -97,7 +108,7 @@ public class Desensitization {
if (ts == null) { if (ts == null) {
return 0; return 0;
} else { } else {
for(SQLObject cursor = ts; cursor != null; cursor = cursor.getParent()) { for(SQLObject cursor = ts; cursor != null; cursor = ((SQLObject)cursor).getParent()) {
if (cursor instanceof SQLUpdateStatement) { if (cursor instanceof SQLUpdateStatement) {
return 0; return 0;
} }
...@@ -145,8 +156,10 @@ public class Desensitization { ...@@ -145,8 +156,10 @@ public class Desensitization {
params.put("newSql", sql); params.put("newSql", sql);
String url = (String)params.get("url"); String url = (String)params.get("url");
String ipPort = PostgreSqlParse.getIpPort(url); String ipPort = PostgreSqlParse.getIpPort(url);
Iterator i$ = JdbcUtil.dataBaseList.iterator();
for(DataBase base : JdbcUtil.dataBaseList) { while(i$.hasNext()) {
DataBase base = (DataBase)i$.next();
if (base.getIp_port().equalsIgnoreCase(ipPort)) { if (base.getIp_port().equalsIgnoreCase(ipPort)) {
dataBase = base; dataBase = base;
} }
......
...@@ -9,12 +9,15 @@ import com.chenyang.druid.sql.ast.expr.SQLMethodInvokeExpr; ...@@ -9,12 +9,15 @@ import com.chenyang.druid.sql.ast.expr.SQLMethodInvokeExpr;
import com.chenyang.druid.sql.ast.expr.SQLPropertyExpr; import com.chenyang.druid.sql.ast.expr.SQLPropertyExpr;
import com.chenyang.druid.sql.ast.statement.SQLSelectItem; import com.chenyang.druid.sql.ast.statement.SQLSelectItem;
import com.chenyang.druid.sql.ast.statement.SQLSelectQueryBlock; import com.chenyang.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.chenyang.druid.util.StringUtils;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.chenyang.druid.util.StringUtils;
import util.JdbcUtil; import util.JdbcUtil;
import util.ThreadLocalVariable;
import util.sqlparse.visitor.common.bean.FieldInfo; import util.sqlparse.visitor.common.bean.FieldInfo;
import util.sqlparse.visitor.common.bean.SQLResult; import util.sqlparse.visitor.common.bean.SQLResult;
import util.sqlparse.visitor.common.memo.FieldMemo; import util.sqlparse.visitor.common.memo.FieldMemo;
...@@ -43,17 +46,34 @@ public class FieldReplaceController { ...@@ -43,17 +46,34 @@ public class FieldReplaceController {
List<FieldInfo> fields = this.result.outputs; List<FieldInfo> fields = this.result.outputs;
Set<SQLObject> parsed = new HashSet(); Set<SQLObject> parsed = new HashSet();
this.params.put("isMatched", "false"); this.params.put("isMatched", "false");
Iterator i$ = fields.iterator();
while(true) {
label40:
while(i$.hasNext()) {
FieldInfo fieldInfo = (FieldInfo)i$.next();
if (fieldInfo.getRelations().size() <= 0) {
if (this.isHit(fieldInfo, this.result.isCaseSensitive)) {
this.repalceFromRef(fieldInfo.getMemo(), parsed);
this.params.put("isMatched", "true");
}
} else {
Iterator i$1 = fieldInfo.getRelations().iterator();
for(FieldInfo fieldInfo : fields) { while(true) {
if (fieldInfo.getRelations().size() <= 0) { FieldInfo fieldInfo1;
if (this.isHit(fieldInfo, this.result.isCaseSensitive)) { do {
this.repalceFromRef(fieldInfo.getMemo(), parsed); if (!i$1.hasNext()) {
this.params.put("isMatched", "true"); continue label40;
} }
} else {
for(FieldInfo fieldInfo1 : fieldInfo.getRelations()) { fieldInfo1 = (FieldInfo)i$1.next();
if (this.isHit(fieldInfo1, this.result.isCaseSensitive)) { } while(!this.isHit(fieldInfo1, this.result.isCaseSensitive));
for(FieldMemo memo : fieldInfo1.getMemos()) {
Iterator i$2 = fieldInfo1.getMemos().iterator();
while(i$2.hasNext()) {
FieldMemo memo = (FieldMemo)i$2.next();
this.repalceFromRef(memo, parsed); this.repalceFromRef(memo, parsed);
} }
...@@ -62,9 +82,10 @@ public class FieldReplaceController { ...@@ -62,9 +82,10 @@ public class FieldReplaceController {
} }
} }
} }
}
this.params.put("newSql", statement.toString()); this.params.put("newSql", statement.toString());
return;
}
} }
private void repalceFromRef(FieldMemo memo, Set<SQLObject> parsed) { private void repalceFromRef(FieldMemo memo, Set<SQLObject> parsed) {
...@@ -149,15 +170,19 @@ public class FieldReplaceController { ...@@ -149,15 +170,19 @@ public class FieldReplaceController {
} else { } else {
String tableName = GreenplumNameWrapper.normalize(fieldMemo.table.name); String tableName = GreenplumNameWrapper.normalize(fieldMemo.table.name);
String schema = GreenplumNameWrapper.normalize(fieldMemo.table.schema); String schema = GreenplumNameWrapper.normalize(fieldMemo.table.schema);
if (isCaseSensitive) { if (!ThreadLocalVariable.checkColumn(schema, tableName, columnName)) {
if (JdbcUtil.followRulesCaseSens(columnName, this.replaceColumn) && JdbcUtil.followRulesCaseSens(tableName, this.replaceTable) && JdbcUtil.followRulesCaseSens(schema, this.replaceSchema)) { return false;
} else {
if (isCaseSensitive) {
if (JdbcUtil.followRulesCaseSens(columnName, this.replaceColumn) && JdbcUtil.followRulesCaseSens(tableName, this.replaceTable) && JdbcUtil.followRulesCaseSens(schema, this.replaceSchema)) {
return true;
}
} else if (JdbcUtil.followRules(columnName, this.replaceColumn) && JdbcUtil.followRules(tableName, this.replaceTable) && JdbcUtil.followRules(schema, this.replaceSchema)) {
return true; return true;
} }
} else if (JdbcUtil.followRules(columnName, this.replaceColumn) && JdbcUtil.followRules(tableName, this.replaceTable) && JdbcUtil.followRules(schema, this.replaceSchema)) {
return true;
}
return false; return false;
}
} }
} else { } else {
return true; return true;
......
...@@ -45,6 +45,7 @@ import com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem; ...@@ -45,6 +45,7 @@ import com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem;
import com.chenyang.druid.sql.ast.statement.SQLValuesTableSource; import com.chenyang.druid.sql.ast.statement.SQLValuesTableSource;
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import util.sqlparse.visitor.common.memo.FieldMemo; import util.sqlparse.visitor.common.memo.FieldMemo;
import util.sqlparse.visitor.common.memo.ValueMemo; import util.sqlparse.visitor.common.memo.ValueMemo;
...@@ -108,21 +109,26 @@ public class FieldVisitor extends ParseVisitor { ...@@ -108,21 +109,26 @@ public class FieldVisitor extends ParseVisitor {
private void setListExpr(SQLExpr valueExpr, SQLObject parent) { private void setListExpr(SQLExpr valueExpr, SQLObject parent) {
SQLObject pa = parent.getParent(); SQLObject pa = parent.getParent();
SQLListExpr columns;
int i;
List valueItems;
int index;
ValueMemo value;
if (pa instanceof SQLUpdateSetItem) { if (pa instanceof SQLUpdateSetItem) {
SQLUpdateSetItem setItem = (SQLUpdateSetItem)pa; SQLUpdateSetItem setItem = (SQLUpdateSetItem)pa;
SQLListExpr columns = (SQLListExpr)setItem.getColumn(); columns = (SQLListExpr)setItem.getColumn();
int index = 0; i = 0;
SQLListExpr item = (SQLListExpr)parent; SQLListExpr item = (SQLListExpr)parent;
List<SQLExpr> items = item.getItems(); valueItems = item.getItems();
for(int i = 0; i < items.size(); ++i) { for(index = 0; index < valueItems.size(); ++index) {
if (items.get(i) == valueExpr) { if (valueItems.get(index) == valueExpr) {
index = i; i = index;
break; break;
} }
} }
ValueMemo value = this.getValueMemo((SQLExpr)columns.getItems().get(index), valueExpr); value = this.getValueMemo((SQLExpr)columns.getItems().get(i), valueExpr);
value.setRef(valueExpr); value.setRef(valueExpr);
value.setExpr(parent); value.setExpr(parent);
value.setValue(this.getValue(valueExpr)); value.setValue(this.getValue(valueExpr));
...@@ -131,15 +137,15 @@ public class FieldVisitor extends ParseVisitor { ...@@ -131,15 +137,15 @@ public class FieldVisitor extends ParseVisitor {
this.scope.getValues().add(value); this.scope.getValues().add(value);
} else if (pa instanceof SQLAssignItem) { } else if (pa instanceof SQLAssignItem) {
SQLAssignItem assignItem = (SQLAssignItem)pa; SQLAssignItem assignItem = (SQLAssignItem)pa;
SQLListExpr target = (SQLListExpr)assignItem.getTarget(); columns = (SQLListExpr)assignItem.getTarget();
SQLListExpr value = (SQLListExpr)assignItem.getValue(); SQLListExpr value2 = (SQLListExpr)assignItem.getValue();
List<SQLExpr> targetItems = target.getItems(); List<SQLExpr> targetItems = columns.getItems();
List<SQLExpr> valueItems = value.getItems(); valueItems = value2.getItems();
int index = 0; index = 0;
for(int i = 0; i < valueItems.size(); ++i) { for(int i1 = 0; i1 < valueItems.size(); ++i1) {
if (valueItems.get(i) == valueExpr) { if (valueItems.get(i1) == valueExpr) {
index = i; index = i1;
break; break;
} }
} }
...@@ -148,26 +154,26 @@ public class FieldVisitor extends ParseVisitor { ...@@ -148,26 +154,26 @@ public class FieldVisitor extends ParseVisitor {
val.setRef(valueExpr); val.setRef(valueExpr);
val.setExpr(parent); val.setExpr(parent);
val.setValue(this.getValue(valueExpr)); val.setValue(this.getValue(valueExpr));
val.setPreDefined(value.toString().equals("?")); val.setPreDefined(value2.toString().equals("?"));
val.setOperator("SET"); val.setOperator("SET");
this.scope.getValues().add(val); this.scope.getValues().add(val);
} else if (pa instanceof SQLValuesTableSource) { } else if (pa instanceof SQLValuesTableSource) {
SQLValuesTableSource tableSource = (SQLValuesTableSource)pa; SQLValuesTableSource tableSource = (SQLValuesTableSource)pa;
int index = 0; index = 0;
for(int i = 0; i < ((SQLListExpr)parent).getItems().size(); ++i) { for(i = 0; i < ((SQLListExpr)parent).getItems().size(); ++i) {
if (((SQLListExpr)parent).getItems().get(i) == valueExpr) { if (((SQLListExpr)parent).getItems().get(i) == valueExpr) {
index = i; index = i;
break; break;
} }
} }
List<SQLName> columns = tableSource.getColumns(); List<SQLName> columns1 = tableSource.getColumns();
if (columns != null && columns.size() > 0) { if (columns1 != null && columns1.size() > 0) {
int size = columns.size(); int size = columns1.size();
index %= size; index %= size;
SQLExpr columnExpr = (SQLExpr)columns.get(index); SQLExpr columnExpr = (SQLExpr)columns1.get(index);
ValueMemo value = this.getValueMemo(columnExpr, valueExpr); value = this.getValueMemo(columnExpr, valueExpr);
value.setRef(valueExpr); value.setRef(valueExpr);
value.setExpr(parent); value.setExpr(parent);
value.setValue(this.getValue(valueExpr)); value.setValue(this.getValue(valueExpr));
...@@ -293,12 +299,13 @@ public class FieldVisitor extends ParseVisitor { ...@@ -293,12 +299,13 @@ public class FieldVisitor extends ParseVisitor {
if (x instanceof SQLBinaryOpExpr) { if (x instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr bin = (SQLBinaryOpExpr)x; SQLBinaryOpExpr bin = (SQLBinaryOpExpr)x;
if (bin.getOperator() != null) { if (bin.getOperator() != null) {
SQLExpr cmp;
switch (bin.getOperator()) { switch (bin.getOperator()) {
case Like: case Like:
case Like2: case Like2:
case Like4: case Like4:
case Likec: case Likec:
SQLExpr cmp = bin.getLeft().equals(y) ? bin.getRight() : bin.getLeft(); cmp = bin.getLeft().equals(y) ? bin.getRight() : bin.getLeft();
operators.add("LIKE"); operators.add("LIKE");
return cmp; return cmp;
case Equality: case Equality:
...@@ -306,9 +313,9 @@ public class FieldVisitor extends ParseVisitor { ...@@ -306,9 +313,9 @@ public class FieldVisitor extends ParseVisitor {
case GreaterThanOrEqual: case GreaterThanOrEqual:
case LessThan: case LessThan:
case LessThanOrEqual: case LessThanOrEqual:
SQLExpr cmp2 = bin.getLeft().equals(y) ? bin.getRight() : bin.getLeft(); cmp = bin.getLeft().equals(y) ? bin.getRight() : bin.getLeft();
operators.add(bin.getOperator().getName().toUpperCase()); operators.add(bin.getOperator().getName().toUpperCase());
return cmp2; return cmp;
case BooleanAnd: case BooleanAnd:
case BooleanOr: case BooleanOr:
if (y instanceof SQLExpr) { if (y instanceof SQLExpr) {
...@@ -373,8 +380,10 @@ public class FieldVisitor extends ParseVisitor { ...@@ -373,8 +380,10 @@ public class FieldVisitor extends ParseVisitor {
if (insert.getQuery() != null) { if (insert.getQuery() != null) {
SQLSelect query = insert.getQuery(); SQLSelect query = insert.getQuery();
Scope selectScope = this.scope.getScope(query); Scope selectScope = this.scope.getScope(query);
Iterator i$ = selectScope.getFieldMap().orderValues().iterator();
for(FieldMemo orderValue : selectScope.getFieldMap().orderValues()) { while(i$.hasNext()) {
FieldMemo orderValue = (FieldMemo)i$.next();
if (orderValue.isSelectItem) { if (orderValue.isSelectItem) {
fields.add(orderValue); fields.add(orderValue);
} }
...@@ -382,22 +391,24 @@ public class FieldVisitor extends ParseVisitor { ...@@ -382,22 +391,24 @@ public class FieldVisitor extends ParseVisitor {
} }
} }
int size;
ValueMemo value;
if (columns != null && columns.size() > 0) { if (columns != null && columns.size() > 0) {
int size = columns.size(); size = columns.size();
index %= size; index %= size;
SQLExpr columnExpr = (SQLExpr)columns.get(index); SQLExpr columnExpr = (SQLExpr)columns.get(index);
ValueMemo value = this.getValueMemo(columnExpr, valueExpr); value = this.getValueMemo(columnExpr, valueExpr);
value.ref = valueExpr; value.ref = valueExpr;
value.expr = parent; value.expr = parent;
value.value = this.getValue(valueExpr); value.value = this.getValue(valueExpr);
value.isPreDefined = value.toString().equals("?"); value.isPreDefined = value.toString().equals("?");
value.operator = "SET"; value.operator = "SET";
this.scope.getValues().add(value); this.scope.getValues().add(value);
} else if (fields != null) { } else if (fields != null && fields.size() > 0) {
int size = fields.size(); size = fields.size();
index %= size; index %= size;
FieldMemo field = (FieldMemo)fields.get(index); FieldMemo field = (FieldMemo)fields.get(index);
ValueMemo value = new ValueMemo(); value = new ValueMemo();
value.field = field; value.field = field;
value.ref = valueExpr; value.ref = valueExpr;
value.expr = parent; value.expr = parent;
...@@ -478,27 +489,29 @@ public class FieldVisitor extends ParseVisitor { ...@@ -478,27 +489,29 @@ public class FieldVisitor extends ParseVisitor {
private void setLimit(SQLExpr valueExpr, SQLObject parent) { private void setLimit(SQLExpr valueExpr, SQLObject parent) {
SQLLimit limit = (SQLLimit)parent; SQLLimit limit = (SQLLimit)parent;
ValueMemo value;
FieldMemo field;
if (limit.getOffset() != null && limit.getOffset() == valueExpr) { if (limit.getOffset() != null && limit.getOffset() == valueExpr) {
ValueMemo value = new ValueMemo(); value = new ValueMemo();
value.ref = limit.getOffset(); value.ref = limit.getOffset();
value.expr = parent; value.expr = parent;
value.value = this.getValue(valueExpr); value.value = this.getValue(valueExpr);
value.isPreDefined = valueExpr.toString().equals("?"); value.isPreDefined = valueExpr.toString().equals("?");
value.operator = "LIMIT"; value.operator = "LIMIT";
FieldMemo field = new FieldMemo(); field = new FieldMemo();
field.name = parent + "limit_offset"; field.name = parent + "limit_offset";
value.field = field; value.field = field;
this.scope.getValues().add(value); this.scope.getValues().add(value);
} }
if (limit.getRowCount() != null && limit.getRowCount() == valueExpr) { if (limit.getRowCount() != null && limit.getRowCount() == valueExpr) {
ValueMemo value = new ValueMemo(); value = new ValueMemo();
value.ref = limit.getRowCount(); value.ref = limit.getRowCount();
value.expr = parent; value.expr = parent;
value.value = this.getValue(valueExpr); value.value = this.getValue(valueExpr);
value.isPreDefined = valueExpr.toString().equals("?"); value.isPreDefined = valueExpr.toString().equals("?");
value.operator = "LIMIT"; value.operator = "LIMIT";
FieldMemo field = new FieldMemo(); field = new FieldMemo();
field.name = parent + "limit_rowcount"; field.name = parent + "limit_rowcount";
value.field = field; value.field = field;
this.scope.getValues().add(value); this.scope.getValues().add(value);
...@@ -523,7 +536,12 @@ public class FieldVisitor extends ParseVisitor { ...@@ -523,7 +536,12 @@ public class FieldVisitor extends ParseVisitor {
} }
private ValueMemo getValueMemo(SQLExpr x, SQLExpr valueExpr, boolean nullIfNoField) { private ValueMemo getValueMemo(SQLExpr x, SQLExpr valueExpr, boolean nullIfNoField) {
ValueMemo value = this.scope.getCurrent().getFieldValueInfo(x); Scope current = this.scope.getCurrent();
if (current.getFieldMap().isEmpty() && !current.getChildren().isEmpty()) {
current = (Scope)current.getChildren().get(0);
}
ValueMemo value = current.getFieldValueInfo(x);
if (value == null && !nullIfNoField) { if (value == null && !nullIfNoField) {
value = new ValueMemo(valueExpr); value = new ValueMemo(valueExpr);
FieldMemo field = new FieldMemo(); FieldMemo field = new FieldMemo();
...@@ -645,4 +663,4 @@ public class FieldVisitor extends ParseVisitor { ...@@ -645,4 +663,4 @@ public class FieldVisitor extends ParseVisitor {
this.setValue(x); this.setValue(x);
return true; return true;
} }
} }
\ No newline at end of file
...@@ -71,15 +71,22 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGAlterTabl ...@@ -71,15 +71,22 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGAlterTabl
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGAlterTableValidateConstraint; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGAlterTableValidateConstraint;
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGColumnDefinition; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGColumnDefinition;
import com.chenyang.druid.sql.dialect.postgresql.visitor.PGASTVisitor; import com.chenyang.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import java.util.Iterator;
import java.util.List; import java.util.List;
import util.sqlparse.visitor.Formater; import util.sqlparse.visitor.Formater;
public class FormatVisitor extends Formater implements PGASTVisitor { public class FormatVisitor extends Formater implements PGASTVisitor {
private boolean debug = false; private boolean debug = false;
public FormatVisitor() {
}
public void perform(List<SQLStatement> statements) { public void perform(List<SQLStatement> statements) {
if (statements != null && statements.size() != 0) { if (statements != null && statements.size() != 0) {
for(SQLStatement statement : statements) { Iterator i$ = statements.iterator();
while(i$.hasNext()) {
SQLStatement statement = (SQLStatement)i$.next();
statement.accept(this); statement.accept(this);
} }
......
...@@ -25,6 +25,7 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement; ...@@ -25,6 +25,7 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
import com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor; import com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor;
import java.util.Iterator;
import java.util.List; import java.util.List;
import util.sqlparse.visitor.common.scope.Scope; import util.sqlparse.visitor.common.scope.Scope;
...@@ -38,7 +39,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -38,7 +39,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
public void perform(List<SQLStatement> statements) { public void perform(List<SQLStatement> statements) {
if (statements != null && statements.size() != 0) { if (statements != null && statements.size() != 0) {
for(SQLStatement statement : statements) { Iterator i$ = statements.iterator();
while(i$.hasNext()) {
SQLStatement statement = (SQLStatement)i$.next();
statement.accept(this); statement.accept(this);
} }
...@@ -51,7 +55,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -51,7 +55,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLSelectStatement" + x.toString()); System.out.println("enter SQLSelectStatement" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -64,7 +68,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -64,7 +68,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(SQLInsertStatement x) { public boolean visit(SQLInsertStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -81,7 +85,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -81,7 +85,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(SQLUpdateStatement x) { public boolean visit(SQLUpdateStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -90,7 +94,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -90,7 +94,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(PGUpdateStatement x) { public boolean visit(PGUpdateStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -99,7 +103,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -99,7 +103,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(SQLDeleteStatement x) { public boolean visit(SQLDeleteStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -108,7 +112,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -108,7 +112,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(PGDeleteStatement x) { public boolean visit(PGDeleteStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -117,7 +121,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -117,7 +121,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(PGGrantStatement x) { public boolean visit(PGGrantStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -126,7 +130,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -126,7 +130,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(SQLRevokeStatement x) { public boolean visit(SQLRevokeStatement x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -139,7 +143,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -139,7 +143,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLWithSubqueryClause" + x.toString()); System.out.println("enter SQLWithSubqueryClause" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -156,7 +160,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -156,7 +160,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString()); System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -173,7 +177,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -173,7 +177,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter PGSelectQueryBlock " + x.toString()); System.out.println("enter PGSelectQueryBlock " + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -194,7 +198,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -194,7 +198,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(SQLUnionQuery x) { public boolean visit(SQLUnionQuery x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -203,7 +207,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -203,7 +207,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
} }
public boolean visit(SQLLateralViewTableSource x) { public boolean visit(SQLLateralViewTableSource x) {
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -216,7 +220,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -216,7 +220,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLSubqueryTableSource" + x.toString()); System.out.println("enter SQLSubqueryTableSource" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -233,7 +237,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -233,7 +237,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter PGSubqueryTableSource" + x.toString()); System.out.println("enter PGSubqueryTableSource" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -254,7 +258,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -254,7 +258,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLUnionQueryTableSource" + x.toString()); System.out.println("enter SQLUnionQueryTableSource" + x.toString());
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
return true; return true;
} }
...@@ -282,7 +286,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -282,7 +286,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter PGExprTableSource " + x); System.out.println("enter PGExprTableSource " + x);
} }
this.scope.enterScope((SQLObject)x); this.scope.enterScope(x);
} else if (this.debug) { } else if (this.debug) {
System.out.println("begin PGExprTableSource" + x.toString()); System.out.println("begin PGExprTableSource" + x.toString());
} }
...@@ -305,7 +309,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -305,7 +309,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected void acceptChild(List<? extends SQLObject> children) { protected void acceptChild(List<? extends SQLObject> children) {
if (children != null && children.size() != 0) { if (children != null && children.size() != 0) {
for(SQLObject child : children) { Iterator i$ = children.iterator();
while(i$.hasNext()) {
SQLObject child = (SQLObject)i$.next();
child.accept(this); child.accept(this);
} }
...@@ -320,7 +327,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -320,7 +327,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected void visitChild(List<? extends SQLObject> x) { protected void visitChild(List<? extends SQLObject> x) {
if (x != null && x.size() != 0) { if (x != null && x.size() != 0) {
for(SQLObject sqlObject : x) { Iterator i$ = x.iterator();
while(i$.hasNext()) {
SQLObject sqlObject = (SQLObject)i$.next();
this.visitChild(sqlObject); this.visitChild(sqlObject);
} }
...@@ -330,4 +340,4 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor { ...@@ -330,4 +340,4 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected boolean isEqual(String name1, String name2) { protected boolean isEqual(String name1, String name2) {
return this.scope.dialector.isEqual(name1, name2); return this.scope.dialector.isEqual(name1, name2);
} }
} }
\ No newline at end of file
...@@ -45,7 +45,7 @@ public class ReplaceVisitor extends ParseVisitor { ...@@ -45,7 +45,7 @@ public class ReplaceVisitor extends ParseVisitor {
this.scope.setReplaceInfo(replaceInfo); this.scope.setReplaceInfo(replaceInfo);
} }
return super.visit((SQLBinaryOpExpr)x); return super.visit(x);
} }
public String visitReplace(SQLStatement stmt, ReplaceInfo replaceInfo, String encType, String secretKey) { public String visitReplace(SQLStatement stmt, ReplaceInfo replaceInfo, String encType, String secretKey) {
...@@ -89,4 +89,4 @@ public class ReplaceVisitor extends ParseVisitor { ...@@ -89,4 +89,4 @@ public class ReplaceVisitor extends ParseVisitor {
return value; return value;
} }
} }
\ No newline at end of file
...@@ -25,6 +25,7 @@ import com.chenyang.druid.sql.ast.statement.SQLUpdateStatement; ...@@ -25,6 +25,7 @@ import com.chenyang.druid.sql.ast.statement.SQLUpdateStatement;
import com.chenyang.druid.sql.dialect.postgresql.ast.expr.tablesource.PGExprTableSource; import com.chenyang.druid.sql.dialect.postgresql.ast.expr.tablesource.PGExprTableSource;
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -62,41 +63,64 @@ public class RowVisitController { ...@@ -62,41 +63,64 @@ public class RowVisitController {
Pattern pattern = Pattern.compile("\"?" + tempTableRegex + "\"?"); Pattern pattern = Pattern.compile("\"?" + tempTableRegex + "\"?");
List<TableInfo> tables = this.result.tables; List<TableInfo> tables = this.result.tables;
Set<SQLObject> parsed = new HashSet(); Set<SQLObject> parsed = new HashSet();
Iterator i$ = tables.iterator();
label53:
while(true) {
TableInfo table;
String name;
do {
if (!i$.hasNext()) {
this.params.put("newSql", statement.toString());
return;
}
for(TableInfo table : tables) { table = (TableInfo)i$.next();
String name = PostgresqlNameWrapper.normalize(table.getTable().name); name = PostgresqlNameWrapper.normalize(table.getTable().name);
if (pattern.matcher(name).matches()) { } while(!pattern.matcher(name).matches());
for(TableMemo memo : table.getMemos()) {
SQLObject ref = memo.ref; List<TableMemo> memos = table.getMemos();
if (!parsed.contains(ref) && ref instanceof SQLTableSource) { Iterator i$2 = memos.iterator();
this.params.put("isMatched", "true");
switch (this.result.statementType) { while(true) {
case select: while(true) {
this.select(ref, table); SQLObject ref;
continue; do {
case insert: do {
this.insert(ref, table); if (!i$2.hasNext()) {
break; continue label53;
case update: }
this.update(ref, table);
break; TableMemo memo = (TableMemo)i$2.next();
case replace: ref = memo.ref;
this.replace(ref, table); } while(parsed.contains(ref));
break; } while(!(ref instanceof SQLTableSource));
case delete:
this.delete(ref, table); this.params.put("isMatched", "true");
break; switch (this.result.statementType) {
default: case select:
this.params.put("isMatched", "false"); this.select(ref, table);
} continue;
case insert:
parsed.add(ref); this.insert(ref, table);
break;
case update:
this.update(ref, table);
break;
case replace:
this.replace(ref, table);
break;
case delete:
this.delete(ref, table);
break;
default:
this.params.put("isMatched", "false");
} }
parsed.add(ref);
} }
} }
} }
this.params.put("newSql", statement.toString());
} }
} }
...@@ -232,7 +256,11 @@ public class RowVisitController { ...@@ -232,7 +256,11 @@ public class RowVisitController {
SQLExpr expr = this.createBinaryExpr(alias); SQLExpr expr = this.createBinaryExpr(alias);
SQLSelectQuery query = select.getQuery(); SQLSelectQuery query = select.getQuery();
if (query instanceof SQLUnionQuery) { if (query instanceof SQLUnionQuery) {
for(SQLSelectQuery relation : ((SQLUnionQuery)query).getRelations()) { List<SQLSelectQuery> relations = ((SQLUnionQuery)query).getRelations();
Iterator i$ = relations.iterator();
while(i$.hasNext()) {
SQLSelectQuery relation = (SQLSelectQuery)i$.next();
if (relation instanceof PGSelectQueryBlock) { if (relation instanceof PGSelectQueryBlock) {
SQLTableSource from = ((PGSelectQueryBlock)relation).getFrom(); SQLTableSource from = ((PGSelectQueryBlock)relation).getFrom();
if (this.tableMatch(from, alias)) { if (this.tableMatch(from, alias)) {
...@@ -347,3 +375,4 @@ public class RowVisitController { ...@@ -347,3 +375,4 @@ public class RowVisitController {
return true; return true;
} }
} }
...@@ -13,6 +13,7 @@ import com.chenyang.druid.sql.ast.statement.SQLMergeStatement; ...@@ -13,6 +13,7 @@ import com.chenyang.druid.sql.ast.statement.SQLMergeStatement;
import com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem; import com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem;
import com.chenyang.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr; import com.chenyang.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -37,8 +38,11 @@ public class ValueReplacer { ...@@ -37,8 +38,11 @@ public class ValueReplacer {
public void replaceValues(List<ValueInfo> values) { public void replaceValues(List<ValueInfo> values) {
if (values != null && values.size() != 0) { if (values != null && values.size() != 0) {
for(ValueMemo value : values) { Iterator i$ = values.iterator();
this.replaceValue(value, null);
while(i$.hasNext()) {
ValueMemo value = (ValueInfo)i$.next();
this.replaceValue(value, (String)null);
} }
} }
...@@ -205,7 +209,10 @@ public class ValueReplacer { ...@@ -205,7 +209,10 @@ public class ValueReplacer {
if (field.getChildren().size() == 0 && this.replace != null && this.replace.containsKey(this.replace.get(field.getAtomName()))) { if (field.getChildren().size() == 0 && this.replace != null && this.replace.containsKey(this.replace.get(field.getAtomName()))) {
output.add(field.getAtomName()); output.add(field.getAtomName());
} else { } else {
for(FieldMemo child : field.children) { Iterator i$ = field.children.iterator();
while(i$.hasNext()) {
FieldMemo child = (FieldMemo)i$.next();
this.getAtomFields(child, output); this.getAtomFields(child, output);
} }
...@@ -214,15 +221,15 @@ public class ValueReplacer { ...@@ -214,15 +221,15 @@ public class ValueReplacer {
private SQLExpr createValueExpr(ValueMemo value, SQLObject parent, String newVal) { private SQLExpr createValueExpr(ValueMemo value, SQLObject parent, String newVal) {
SQLTextLiteralExpr expr = new MySqlCharExpr(); SQLTextLiteralExpr expr = new MySqlCharExpr();
expr.setParent(parent); ((SQLTextLiteralExpr)expr).setParent(parent);
if (newVal != null) { if (newVal != null) {
expr.setText(newVal); ((SQLTextLiteralExpr)expr).setText(newVal);
} else { } else {
String val = value.value.toString(); String val = value.value.toString();
if (this.replace != null && this.replace.containsKey(value.field.getAtomName())) { if (this.replace != null && this.replace.containsKey(value.field.getAtomName())) {
expr.setText((String)this.replace.get(value.field.getAtomName())); ((SQLTextLiteralExpr)expr).setText((String)this.replace.get(value.field.getAtomName()));
} else { } else {
expr.setText(val); ((SQLTextLiteralExpr)expr).setText(val);
} }
} }
......
...@@ -10,6 +10,7 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock; ...@@ -10,6 +10,7 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement; import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
import com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor; import com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
public class WhereVisitor extends DefaultPGASTVisitor { public class WhereVisitor extends DefaultPGASTVisitor {
...@@ -20,9 +21,15 @@ public class WhereVisitor extends DefaultPGASTVisitor { ...@@ -20,9 +21,15 @@ public class WhereVisitor extends DefaultPGASTVisitor {
return this.wheres; return this.wheres;
} }
public WhereVisitor() {
}
public void perform(List<SQLStatement> statements) { public void perform(List<SQLStatement> statements) {
if (statements != null && statements.size() != 0) { if (statements != null && statements.size() != 0) {
for(SQLStatement statement : statements) { Iterator i$ = statements.iterator();
while(i$.hasNext()) {
SQLStatement statement = (SQLStatement)i$.next();
statement.accept(this); statement.accept(this);
} }
......
#网关地址
gatewayurl=https://172.19.1.167:9005
#插件对应的网关项目的projectId
projectid=a22254df-da51-421f-b5a0-e66ba1d74b4a
#插件同步数据的方式(推/拉)
dataSynchronousMode=pull
#轮询时间(默认1分钟)
pullInterval=60000
#是否记录本地同步日志
isSave=false
#加密标识
encryption.label=jm_
#单个字符加密后连接起来用某个字符进行分割
encryption.like.split=#
##like是否执行按照单个字符进行加密开关。1表示按照单个字符进行加密。0表示按照字符串整体进行加密, 默认不开启
encryption.like.open=1
#is remote enc/dec
encryption.remote=0
#是否采用远程加密卡加解密,false不使用加密卡,true使用加密卡,encryption.remote=1表示远程加解密
ccoresdf=false
mode=CCORESDF
#key location cache or (cache and file)
encryption.keyCache=1
#插件集成的项目启动后,向平台时注册自己的端口号标识
rootport=54321
#秘钥存放位置
encryption.location=/home/ghca/data/encryption.properties
#完整性规则存放位置
digest.location=/home/ghca/data/digest.properties
#外部配置文件信息地址
encryption.config.location=/home/ghca/data/plugin/config.properties
#驱动列表,如有多个以#分割
encryption.drivers=
#插件是否打印日志,如果为空或者为0不打印日志信息,1为打印日志信息
encryption.log=0
#插件是否开启sql查询时where条件like替换功能,1为开启,0为不开启
replaceSql=0
#是否根据登录账号开启脱敏功能,1为开启,0为未开启
maskingRule=0
#密文分隔符
encryption.separator=_jm
#******************************** 规则配置信息 ***********************************
#localfile/gateway
encryption.rule-origin=gateway
#localfile/gateway
masking.rule-origin=gateway
#reload config
rule.load-period=30
#gateway config
gateway.protocol=https
gateway.host=172.19.1.167
gateway.port=9005
#0:ry系统,1:masking 系统
getUserType=0
\ No newline at end of file
#网关地址
gatewayurl=https://172.19.1.167:9005
#插件对应的网关项目的projectId
projectid=5e75836f-da94-4a6c-b897-a131bdc23107
#插件同步数据的方式(推/拉)
dataSynchronousMode=pull
#轮询时间(默认1分钟)
pullInterval=60000
#是否记录本地同步日志
isSave=false
#加密标识
encryption.label=jm_
#单个字符加密后连接起来用某个字符进行分割
encryption.like.split=#
##like是否执行按照单个字符进行加密开关。1表示按照单个字符进行加密。0表示按照字符串整体进行加密, 默认不开启
encryption.like.open=1
#is remote enc/dec
encryption.remote=0
#是否采用远程加密卡加解密,false不使用加密卡,true使用加密卡,encryption.remote=1表示远程加解密
ccoresdf=false
mode=CCORESDF
#key location cache or (cache and file)
encryption.keyCache=1
#插件集成的项目启动后,向平台时注册自己的端口号标识
rootport=54321
#秘钥存放位置
encryption.location=/home/ghca/data/encryption.properties
#完整性规则存放位置
digest.location=/home/ghca/data/digest.properties
#外部配置文件信息地址
encryption.config.location=/home/ghca/data/plugin/config.properties
#驱动列表,如有多个以#分割
encryption.drivers=
#插件是否打印日志,如果为空或者为0不打印日志信息,1为打印日志信息
encryption.log=0
#插件是否开启sql查询时where条件like替换功能,1为开启,0为不开启
replaceSql=0
#是否根据登录账号开启脱敏功能,1为开启,0为未开启
maskingRule=0
#密文分隔符
encryption.separator=_jm
#******************************** 规则配置信息 ***********************************
#localfile/gateway
encryption.rule-origin=gateway
#localfile/gateway
masking.rule-origin=gateway
#reload config
rule.load-period=30
#gateway config
gateway.protocol=https
gateway.host=172.19.1.167
gateway.port=9005
#0:ry系统,1:masking 系统
getUserType=0
\ No newline at end of file
#网关地址
gatewayurl=https://172.19.1.167:9005
#插件对应的网关项目的projectId
projectid=6d486188-ee80-42d3-8183-fbaf4016044e
#插件同步数据的方式(推/拉)
dataSynchronousMode=pull
#轮询时间(默认1分钟)
pullInterval=60000
#是否记录本地同步日志
isSave=false
#加密标识
encryption.label=jm_
#单个字符加密后连接起来用某个字符进行分割
encryption.like.split=#
##like是否执行按照单个字符进行加密开关。1表示按照单个字符进行加密。0表示按照字符串整体进行加密, 默认不开启
encryption.like.open=1
#is remote enc/dec
encryption.remote=0
#是否采用远程加密卡加解密,false不使用加密卡,true使用加密卡,encryption.remote=1表示远程加解密
ccoresdf=false
mode=CCORESDF
#key location cache or (cache and file)
encryption.keyCache=1
#插件集成的项目启动后,向平台时注册自己的端口号标识
rootport=54321
#秘钥存放位置
encryption.location=/home/ghca/data/encryption.properties
#完整性规则存放位置
digest.location=/home/ghca/data/digest.properties
#外部配置文件信息地址
encryption.config.location=/home/ghca/data/plugin/config.properties
#驱动列表,如有多个以#分割
encryption.drivers=
#插件是否打印日志,如果为空或者为0不打印日志信息,1为打印日志信息
encryption.log=0
#插件是否开启sql查询时where条件like替换功能,1为开启,0为不开启
replaceSql=0
#是否根据登录账号开启脱敏功能,1为开启,0为未开启
maskingRule=0
#密文分隔符
encryption.separator=_jm
#******************************** 规则配置信息 ***********************************
#localfile/gateway
encryption.rule-origin=gateway
#localfile/gateway
masking.rule-origin=gateway
#reload config
rule.load-period=30
#gateway config
gateway.protocol=https
gateway.host=172.19.1.167
gateway.port=9005
#0:ry系统,1:masking 系统
getUserType=0
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论