| | |
| | | |
| | | import com.alibaba.druid.sql.SQLUtils; |
| | | import com.alibaba.druid.sql.ast.SQLExpr; |
| | | import com.alibaba.druid.sql.ast.SQLObject; |
| | | import com.alibaba.druid.sql.ast.SQLStatement; |
| | | import com.alibaba.druid.sql.ast.statement.*; |
| | | import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement; |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | MySqlStatementParser parser = new MySqlStatementParser(sql); |
| | | SQLSelectStatement sqlStatement = (SQLSelectStatement) parser.parseSelect(); |
| | | |
| | | SQLSelect sqlSelect = sqlStatement.getSelect(); |
| | | if (sqlSelect.getQuery() instanceof SQLSelectQueryBlock) { |
| | | // 非union的查询语句 |
| | | return selectSqlRoutine( sqlStatement,aesKeysTable); |
| | | } else if (sqlSelect.getQuery() instanceof SQLUnionQuery) { |
| | | // union的查询语句 |
| | | return selectSqlUnion( sql, sqlStatement, aesKeysTable); |
| | | }else { |
| | | return selectSqlRoutine( sqlStatement,aesKeysTable); |
| | | } |
| | | } |
| | | |
| | | /**查询加密数据处理,只对查询做处理,select返回不做处理(Union特殊语句) |
| | | * @param sql sql语句 |
| | | * @param aesKeysTable aes秘钥 |
| | | * @return |
| | | */ |
| | | public static String selectSqlUnion(String sql,SQLSelectStatement sqlStatement,Map<String,Map<String,String>> aesKeysTable){ |
| | | |
| | | //获取表和别名 |
| | | ExportTableAliasVisitor visitorTable = new ExportTableAliasVisitor(); |
| | |
| | | } |
| | | |
| | | |
| | | /**查询加密数据处理,只对查询做处理,select返回不做处理(备份) |
| | | * @param sql sql语句 |
| | | /**查询加密数据处理,只对查询做处理,select返回不做处理(常规语句) |
| | | * @param sqlStatement sql语句 |
| | | * @param aesKeysTable aes秘钥 |
| | | * @return |
| | | */ |
| | | public static String selectSqlDemo(String sql,Map<String,Map<String,String>> aesKeysTable){ |
| | | |
| | | MySqlStatementParser parser = new MySqlStatementParser(sql); |
| | | SQLSelectStatement sqlStatement = (SQLSelectStatement) parser.parseSelect(); |
| | | //获取格式化的slq语句 |
| | | sql = sqlStatement.toString(); |
| | | |
| | | |
| | | public static String selectSqlRoutine(SQLSelectStatement sqlStatement,Map<String,Map<String,String>> aesKeysTable){ |
| | | |
| | | //解析select查询 |
| | | //SQLSelect sqlSelect = sqlStatement.getSelect() |
| | |
| | | b = false; |
| | | logger.error("解析sql报错:"+e.getMessage()); |
| | | } |
| | | |
| | | if(!b){ |
| | | return "err"; |
| | | } |
| | |
| | | } |
| | | |
| | | //处理where需要加密得字段 |
| | | sql = sqlWhere.toString(); |
| | | String sql = sqlWhere.toString(); |
| | | if(!StringUtils.isEmpty(sql)){ |
| | | Map<String,String> aesKeys = null; |
| | | String aeskey = null; |