Commit daadfce1 by wuchao

修复bug

parent f88168cb
<?xml version="1.0" encoding="UTF-8"?>
<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/resources" charset="UTF-8" />
</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;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.chenyang.druid.util.StringUtils;
import util.DataUtil;
import util.JdbcUtil;
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 {
public static String getSqlType(String sql, String 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;
} else {
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;
import bean.Column;
import com.chenyang.druid.sql.ast.SQLExpr;
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.*;
import com.chenyang.druid.sql.ast.expr.SQLAllColumnExpr;
import com.chenyang.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.chenyang.druid.sql.ast.expr.SQLCaseExpr;
......@@ -1138,6 +1135,28 @@ public class Scope extends ID {
field = value;
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) {
......
......@@ -4,7 +4,7 @@ import bean.DataBase;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.chenyang.druid.util.StringUtils;
import org.bson.BsonString;
import util.sqlparse.visitor.common.memo.FieldMemo;
import util.sqlparse.visitor.common.memo.TableMemo;
......
......@@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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.BsonDouble;
import util.StringJoin;
......@@ -237,7 +237,7 @@ public class ScopeVisitor implements MongoVisitor<ParseResult> {
BsonBasicNode bfilter = (BsonBasicNode)json;
if (bfilter.value() instanceof String) {
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("$")) {
name = name.substring(1);
}
......
......@@ -4,7 +4,7 @@ import bean.DataBase;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.chenyang.druid.util.StringUtils;
import util.sqlparse.visitor.common.Objects;
public class WhereVisitor implements MongoVisitor<Boolean> {
......
......@@ -40,10 +40,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
public void perform(List<SQLStatement> statements) {
if (statements != null && statements.size() != 0) {
Iterator var2 = statements.iterator();
Iterator i$ = statements.iterator();
while(var2.hasNext()) {
SQLStatement statement = (SQLStatement)var2.next();
while(i$.hasNext()) {
SQLStatement statement = (SQLStatement)i$.next();
statement.accept(this);
}
......@@ -56,7 +56,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLSelectStatement" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -69,7 +69,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(SQLInsertStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -86,7 +86,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(OracleMultiInsertStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -95,7 +95,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(SQLUpdateStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -104,7 +104,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(SQLMergeStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -113,7 +113,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(OracleUpdateStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -122,7 +122,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(SQLDeleteStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -131,7 +131,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(OracleDeleteStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -144,7 +144,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLWithSubqueryClause" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -161,7 +161,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -178,7 +178,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -195,7 +195,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter OracleSelectQueryBlock " + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -208,7 +208,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(SQLUnionQuery x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -217,7 +217,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public boolean visit(SQLLateralViewTableSource x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -230,7 +230,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLSubqueryTableSource" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -247,7 +247,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter OracleSelectSubqueryTableSource" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -268,7 +268,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter SQLUnionQueryTableSource" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -303,7 +303,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System.out.println("enter OracleSelectTableReference " + x);
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
} else if (this.debug) {
System.out.println("begin OracleSelectTableReference" + x.toString());
}
......@@ -312,7 +312,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
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) {
System.out.println("exit OracleSelectTableReference " + x);
}
......@@ -326,10 +326,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
protected void acceptChild(List<? extends SQLObject> children) {
if (children != null && children.size() != 0) {
Iterator var2 = children.iterator();
Iterator i$ = children.iterator();
while(var2.hasNext()) {
SQLObject child = (SQLObject)var2.next();
while(i$.hasNext()) {
SQLObject child = (SQLObject)i$.next();
child.accept(this);
}
......@@ -344,10 +344,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
protected void visitChild(List<? extends SQLObject> x) {
if (x != null && x.size() != 0) {
Iterator var2 = x.iterator();
Iterator i$ = x.iterator();
while(var2.hasNext()) {
SQLObject sqlObject = (SQLObject)var2.next();
while(i$.hasNext()) {
SQLObject sqlObject = (SQLObject)i$.next();
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;
import bean.Table;
import bean.View;
import com.chenyang.druid.util.StringUtils;
import java.util.Iterator;
import java.util.Map;
import util.getdata.DatabaseCache;
import util.sqlparse.visitor.common.names.NameWrapper;
......@@ -63,7 +64,7 @@ public class PostgresqlNameWrapper extends NameWrapper {
} else {
String column = c.getColumnName();
if (column != null && column.length() != 0) {
ColInfo colInfo = this.getColumnInfo(c);
NameWrapper.ColInfo colInfo = this.getColumnInfo(c);
if (colInfo.schema == null) {
colInfo.schema = this.defschema;
}
......@@ -91,13 +92,18 @@ public class PostgresqlNameWrapper extends NameWrapper {
if (sch != null) {
return sch;
} else {
for(Map.Entry<String, Schema> pair : schemas.entrySet()) {
if (((String)pair.getKey()).equalsIgnoreCase(schema)) {
return (Schema)pair.getValue();
Iterator i$ = schemas.entrySet().iterator();
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 {
} else {
table = table.trim();
Map<String, Table> tables = this.cache.getTables();
String id;
if (table.startsWith("\"")) {
table = this.unwrapName(table);
String id = this.cache.getSchemaTableId(sch.getName(), table);
id = this.cache.getSchemaTableId(sch.getName(), table);
return (Table)tables.get(id);
} else {
table = this.unwrapName(table);
table = table.toUpperCase();
String id = this.cache.getSchemaTableId(sch.getName(), table);
id = this.cache.getSchemaTableId(sch.getName(), table);
Table tb = (Table)tables.get(id);
if (tb != null) {
return tb;
} else {
for(Map.Entry<String, Table> pair : tables.entrySet()) {
if (((String)pair.getKey()).equalsIgnoreCase(id)) {
return (Table)pair.getValue();
Iterator i$ = tables.entrySet().iterator();
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 {
}
}
public void unwrapColumn(ColInfo colInfo) {
public void unwrapColumn(NameWrapper.ColInfo colInfo) {
String schema = colInfo.schema;
String table = colInfo.table;
String col = colInfo.column;
......@@ -175,8 +187,10 @@ public class PostgresqlNameWrapper extends NameWrapper {
col = col.trim();
boolean isCase = col.startsWith("\"");
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 (column.getColumnName().equals(col)) {
colInfo.column = column.getColumnName();
......
......@@ -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.SQLTableSource;
import com.chenyang.druid.sql.ast.statement.SQLUpdateStatement;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import util.JdbcUtil;
......@@ -25,6 +26,9 @@ import util.sqlparse.visitor.postgresql.PostgresqlNameWrapper;
import util.sqlparse.visitor.postgresql.SQLParser;
public class Desensitization {
public Desensitization() {
}
public Map parseColumn(Map params) {
return this.parseData(params);
}
......@@ -36,8 +40,10 @@ public class Desensitization {
params.put("newSql", sql);
String url = (String)params.get("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)) {
dataBase = base;
}
......@@ -61,9 +67,14 @@ public class Desensitization {
SQLResult result = this.getSqlResult(params);
List<TableInfo> tables = result.tables;
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) {
for(TableMemo tableMemo : table.getMemos()) {
while(i$1.hasNext()) {
TableMemo tableMemo = (TableMemo)i$1.next();
String sourceName = PostgresqlNameWrapper.normalize(tableMemo.name);
boolean isMatched = JdbcUtil.followRulesCaseSens(sourceName, "\"?" + replaceTable + "\"?");
if (isMatched) {
......@@ -97,7 +108,7 @@ public class Desensitization {
if (ts == null) {
return 0;
} else {
for(SQLObject cursor = ts; cursor != null; cursor = cursor.getParent()) {
for(SQLObject cursor = ts; cursor != null; cursor = ((SQLObject)cursor).getParent()) {
if (cursor instanceof SQLUpdateStatement) {
return 0;
}
......@@ -145,8 +156,10 @@ public class Desensitization {
params.put("newSql", sql);
String url = (String)params.get("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)) {
dataBase = base;
}
......
......@@ -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.statement.SQLSelectItem;
import com.chenyang.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.chenyang.druid.util.StringUtils;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.chenyang.druid.util.StringUtils;
import util.JdbcUtil;
import util.ThreadLocalVariable;
import util.sqlparse.visitor.common.bean.FieldInfo;
import util.sqlparse.visitor.common.bean.SQLResult;
import util.sqlparse.visitor.common.memo.FieldMemo;
......@@ -43,17 +46,34 @@ public class FieldReplaceController {
List<FieldInfo> fields = this.result.outputs;
Set<SQLObject> parsed = new HashSet();
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) {
if (fieldInfo.getRelations().size() <= 0) {
if (this.isHit(fieldInfo, this.result.isCaseSensitive)) {
this.repalceFromRef(fieldInfo.getMemo(), parsed);
this.params.put("isMatched", "true");
}
} else {
for(FieldInfo fieldInfo1 : fieldInfo.getRelations()) {
if (this.isHit(fieldInfo1, this.result.isCaseSensitive)) {
for(FieldMemo memo : fieldInfo1.getMemos()) {
while(true) {
FieldInfo fieldInfo1;
do {
if (!i$1.hasNext()) {
continue label40;
}
fieldInfo1 = (FieldInfo)i$1.next();
} while(!this.isHit(fieldInfo1, this.result.isCaseSensitive));
Iterator i$2 = fieldInfo1.getMemos().iterator();
while(i$2.hasNext()) {
FieldMemo memo = (FieldMemo)i$2.next();
this.repalceFromRef(memo, parsed);
}
......@@ -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) {
......@@ -149,15 +170,19 @@ public class FieldReplaceController {
} else {
String tableName = GreenplumNameWrapper.normalize(fieldMemo.table.name);
String schema = GreenplumNameWrapper.normalize(fieldMemo.table.schema);
if (isCaseSensitive) {
if (JdbcUtil.followRulesCaseSens(columnName, this.replaceColumn) && JdbcUtil.followRulesCaseSens(tableName, this.replaceTable) && JdbcUtil.followRulesCaseSens(schema, this.replaceSchema)) {
if (!ThreadLocalVariable.checkColumn(schema, tableName, columnName)) {
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;
}
} else if (JdbcUtil.followRules(columnName, this.replaceColumn) && JdbcUtil.followRules(tableName, this.replaceTable) && JdbcUtil.followRules(schema, this.replaceSchema)) {
return true;
}
return false;
return false;
}
}
} else {
return true;
......
......@@ -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.dialect.postgresql.ast.stmt.PGInsertStatement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import util.sqlparse.visitor.common.memo.FieldMemo;
import util.sqlparse.visitor.common.memo.ValueMemo;
......@@ -108,21 +109,26 @@ public class FieldVisitor extends ParseVisitor {
private void setListExpr(SQLExpr valueExpr, SQLObject parent) {
SQLObject pa = parent.getParent();
SQLListExpr columns;
int i;
List valueItems;
int index;
ValueMemo value;
if (pa instanceof SQLUpdateSetItem) {
SQLUpdateSetItem setItem = (SQLUpdateSetItem)pa;
SQLListExpr columns = (SQLListExpr)setItem.getColumn();
int index = 0;
columns = (SQLListExpr)setItem.getColumn();
i = 0;
SQLListExpr item = (SQLListExpr)parent;
List<SQLExpr> items = item.getItems();
valueItems = item.getItems();
for(int i = 0; i < items.size(); ++i) {
if (items.get(i) == valueExpr) {
index = i;
for(index = 0; index < valueItems.size(); ++index) {
if (valueItems.get(index) == valueExpr) {
i = index;
break;
}
}
ValueMemo value = this.getValueMemo((SQLExpr)columns.getItems().get(index), valueExpr);
value = this.getValueMemo((SQLExpr)columns.getItems().get(i), valueExpr);
value.setRef(valueExpr);
value.setExpr(parent);
value.setValue(this.getValue(valueExpr));
......@@ -131,15 +137,15 @@ public class FieldVisitor extends ParseVisitor {
this.scope.getValues().add(value);
} else if (pa instanceof SQLAssignItem) {
SQLAssignItem assignItem = (SQLAssignItem)pa;
SQLListExpr target = (SQLListExpr)assignItem.getTarget();
SQLListExpr value = (SQLListExpr)assignItem.getValue();
List<SQLExpr> targetItems = target.getItems();
List<SQLExpr> valueItems = value.getItems();
int index = 0;
for(int i = 0; i < valueItems.size(); ++i) {
if (valueItems.get(i) == valueExpr) {
index = i;
columns = (SQLListExpr)assignItem.getTarget();
SQLListExpr value2 = (SQLListExpr)assignItem.getValue();
List<SQLExpr> targetItems = columns.getItems();
valueItems = value2.getItems();
index = 0;
for(int i1 = 0; i1 < valueItems.size(); ++i1) {
if (valueItems.get(i1) == valueExpr) {
index = i1;
break;
}
}
......@@ -148,26 +154,26 @@ public class FieldVisitor extends ParseVisitor {
val.setRef(valueExpr);
val.setExpr(parent);
val.setValue(this.getValue(valueExpr));
val.setPreDefined(value.toString().equals("?"));
val.setPreDefined(value2.toString().equals("?"));
val.setOperator("SET");
this.scope.getValues().add(val);
} else if (pa instanceof SQLValuesTableSource) {
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) {
index = i;
break;
}
}
List<SQLName> columns = tableSource.getColumns();
if (columns != null && columns.size() > 0) {
int size = columns.size();
List<SQLName> columns1 = tableSource.getColumns();
if (columns1 != null && columns1.size() > 0) {
int size = columns1.size();
index %= size;
SQLExpr columnExpr = (SQLExpr)columns.get(index);
ValueMemo value = this.getValueMemo(columnExpr, valueExpr);
SQLExpr columnExpr = (SQLExpr)columns1.get(index);
value = this.getValueMemo(columnExpr, valueExpr);
value.setRef(valueExpr);
value.setExpr(parent);
value.setValue(this.getValue(valueExpr));
......@@ -293,12 +299,13 @@ public class FieldVisitor extends ParseVisitor {
if (x instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr bin = (SQLBinaryOpExpr)x;
if (bin.getOperator() != null) {
SQLExpr cmp;
switch (bin.getOperator()) {
case Like:
case Like2:
case Like4:
case Likec:
SQLExpr cmp = bin.getLeft().equals(y) ? bin.getRight() : bin.getLeft();
cmp = bin.getLeft().equals(y) ? bin.getRight() : bin.getLeft();
operators.add("LIKE");
return cmp;
case Equality:
......@@ -306,9 +313,9 @@ public class FieldVisitor extends ParseVisitor {
case GreaterThanOrEqual:
case LessThan:
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());
return cmp2;
return cmp;
case BooleanAnd:
case BooleanOr:
if (y instanceof SQLExpr) {
......@@ -373,8 +380,10 @@ public class FieldVisitor extends ParseVisitor {
if (insert.getQuery() != null) {
SQLSelect query = insert.getQuery();
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) {
fields.add(orderValue);
}
......@@ -382,22 +391,24 @@ public class FieldVisitor extends ParseVisitor {
}
}
int size;
ValueMemo value;
if (columns != null && columns.size() > 0) {
int size = columns.size();
size = columns.size();
index %= size;
SQLExpr columnExpr = (SQLExpr)columns.get(index);
ValueMemo value = this.getValueMemo(columnExpr, valueExpr);
value = this.getValueMemo(columnExpr, valueExpr);
value.ref = valueExpr;
value.expr = parent;
value.value = this.getValue(valueExpr);
value.isPreDefined = value.toString().equals("?");
value.operator = "SET";
this.scope.getValues().add(value);
} else if (fields != null) {
int size = fields.size();
} else if (fields != null && fields.size() > 0) {
size = fields.size();
index %= size;
FieldMemo field = (FieldMemo)fields.get(index);
ValueMemo value = new ValueMemo();
value = new ValueMemo();
value.field = field;
value.ref = valueExpr;
value.expr = parent;
......@@ -478,27 +489,29 @@ public class FieldVisitor extends ParseVisitor {
private void setLimit(SQLExpr valueExpr, SQLObject parent) {
SQLLimit limit = (SQLLimit)parent;
ValueMemo value;
FieldMemo field;
if (limit.getOffset() != null && limit.getOffset() == valueExpr) {
ValueMemo value = new ValueMemo();
value = new ValueMemo();
value.ref = limit.getOffset();
value.expr = parent;
value.value = this.getValue(valueExpr);
value.isPreDefined = valueExpr.toString().equals("?");
value.operator = "LIMIT";
FieldMemo field = new FieldMemo();
field = new FieldMemo();
field.name = parent + "limit_offset";
value.field = field;
this.scope.getValues().add(value);
}
if (limit.getRowCount() != null && limit.getRowCount() == valueExpr) {
ValueMemo value = new ValueMemo();
value = new ValueMemo();
value.ref = limit.getRowCount();
value.expr = parent;
value.value = this.getValue(valueExpr);
value.isPreDefined = valueExpr.toString().equals("?");
value.operator = "LIMIT";
FieldMemo field = new FieldMemo();
field = new FieldMemo();
field.name = parent + "limit_rowcount";
value.field = field;
this.scope.getValues().add(value);
......@@ -523,7 +536,12 @@ public class FieldVisitor extends ParseVisitor {
}
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) {
value = new ValueMemo(valueExpr);
FieldMemo field = new FieldMemo();
......@@ -645,4 +663,4 @@ public class FieldVisitor extends ParseVisitor {
this.setValue(x);
return true;
}
}
}
\ No newline at end of file
......@@ -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.PGColumnDefinition;
import com.chenyang.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import java.util.Iterator;
import java.util.List;
import util.sqlparse.visitor.Formater;
public class FormatVisitor extends Formater implements PGASTVisitor {
private boolean debug = false;
public FormatVisitor() {
}
public void perform(List<SQLStatement> statements) {
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);
}
......
......@@ -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.PGUpdateStatement;
import com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor;
import java.util.Iterator;
import java.util.List;
import util.sqlparse.visitor.common.scope.Scope;
......@@ -38,7 +39,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
public void perform(List<SQLStatement> statements) {
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);
}
......@@ -51,7 +55,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLSelectStatement" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -64,7 +68,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(SQLInsertStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -81,7 +85,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(SQLUpdateStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -90,7 +94,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(PGUpdateStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -99,7 +103,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(SQLDeleteStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -108,7 +112,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(PGDeleteStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -117,7 +121,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(PGGrantStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -126,7 +130,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(SQLRevokeStatement x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -139,7 +143,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLWithSubqueryClause" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -156,7 +160,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLWithSubqueryClause.Entry" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -173,7 +177,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter PGSelectQueryBlock " + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -194,7 +198,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(SQLUnionQuery x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -203,7 +207,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public boolean visit(SQLLateralViewTableSource x) {
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -216,7 +220,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLSubqueryTableSource" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -233,7 +237,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter PGSubqueryTableSource" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -254,7 +258,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter SQLUnionQueryTableSource" + x.toString());
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
return true;
}
......@@ -282,7 +286,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System.out.println("enter PGExprTableSource " + x);
}
this.scope.enterScope((SQLObject)x);
this.scope.enterScope(x);
} else if (this.debug) {
System.out.println("begin PGExprTableSource" + x.toString());
}
......@@ -305,7 +309,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected void acceptChild(List<? extends SQLObject> children) {
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);
}
......@@ -320,7 +327,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected void visitChild(List<? extends SQLObject> x) {
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);
}
......@@ -330,4 +340,4 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected boolean isEqual(String name1, String name2) {
return this.scope.dialector.isEqual(name1, name2);
}
}
}
\ No newline at end of file
......@@ -45,7 +45,7 @@ public class ReplaceVisitor extends ParseVisitor {
this.scope.setReplaceInfo(replaceInfo);
}
return super.visit((SQLBinaryOpExpr)x);
return super.visit(x);
}
public String visitReplace(SQLStatement stmt, ReplaceInfo replaceInfo, String encType, String secretKey) {
......@@ -89,4 +89,4 @@ public class ReplaceVisitor extends ParseVisitor {
return value;
}
}
}
\ No newline at end of file
......@@ -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.stmt.PGSelectQueryBlock;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -62,41 +63,64 @@ public class RowVisitController {
Pattern pattern = Pattern.compile("\"?" + tempTableRegex + "\"?");
List<TableInfo> tables = this.result.tables;
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) {
String name = PostgresqlNameWrapper.normalize(table.getTable().name);
if (pattern.matcher(name).matches()) {
for(TableMemo memo : table.getMemos()) {
SQLObject ref = memo.ref;
if (!parsed.contains(ref) && ref instanceof SQLTableSource) {
this.params.put("isMatched", "true");
switch (this.result.statementType) {
case select:
this.select(ref, table);
continue;
case insert:
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);
table = (TableInfo)i$.next();
name = PostgresqlNameWrapper.normalize(table.getTable().name);
} while(!pattern.matcher(name).matches());
List<TableMemo> memos = table.getMemos();
Iterator i$2 = memos.iterator();
while(true) {
while(true) {
SQLObject ref;
do {
do {
if (!i$2.hasNext()) {
continue label53;
}
TableMemo memo = (TableMemo)i$2.next();
ref = memo.ref;
} while(parsed.contains(ref));
} while(!(ref instanceof SQLTableSource));
this.params.put("isMatched", "true");
switch (this.result.statementType) {
case select:
this.select(ref, table);
continue;
case insert:
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 {
SQLExpr expr = this.createBinaryExpr(alias);
SQLSelectQuery query = select.getQuery();
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) {
SQLTableSource from = ((PGSelectQueryBlock)relation).getFrom();
if (this.tableMatch(from, alias)) {
......@@ -347,3 +375,4 @@ public class RowVisitController {
return true;
}
}
......@@ -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.dialect.mysql.ast.expr.MySqlCharExpr;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -37,8 +38,11 @@ public class ValueReplacer {
public void replaceValues(List<ValueInfo> values) {
if (values != null && values.size() != 0) {
for(ValueMemo value : values) {
this.replaceValue(value, null);
Iterator i$ = values.iterator();
while(i$.hasNext()) {
ValueMemo value = (ValueInfo)i$.next();
this.replaceValue(value, (String)null);
}
}
......@@ -205,7 +209,10 @@ public class ValueReplacer {
if (field.getChildren().size() == 0 && this.replace != null && this.replace.containsKey(this.replace.get(field.getAtomName()))) {
output.add(field.getAtomName());
} else {
for(FieldMemo child : field.children) {
Iterator i$ = field.children.iterator();
while(i$.hasNext()) {
FieldMemo child = (FieldMemo)i$.next();
this.getAtomFields(child, output);
}
......@@ -214,15 +221,15 @@ public class ValueReplacer {
private SQLExpr createValueExpr(ValueMemo value, SQLObject parent, String newVal) {
SQLTextLiteralExpr expr = new MySqlCharExpr();
expr.setParent(parent);
((SQLTextLiteralExpr)expr).setParent(parent);
if (newVal != null) {
expr.setText(newVal);
((SQLTextLiteralExpr)expr).setText(newVal);
} else {
String val = value.value.toString();
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 {
expr.setText(val);
((SQLTextLiteralExpr)expr).setText(val);
}
}
......
......@@ -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.visitor.DefaultPGASTVisitor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class WhereVisitor extends DefaultPGASTVisitor {
......@@ -20,9 +21,15 @@ public class WhereVisitor extends DefaultPGASTVisitor {
return this.wheres;
}
public WhereVisitor() {
}
public void perform(List<SQLStatement> statements) {
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);
}
......
#网关地址
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论