Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
76ab5cb5
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76ab5cb5
编写于
9月 06, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #2567, refactor SQLRewriteEngine for encrypt
上级
587824a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
20 deletion
+13
-20
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/SQLRewriteEngine.java
.../apache/shardingsphere/core/rewrite/SQLRewriteEngine.java
+13
-20
未找到文件。
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/SQLRewriteEngine.java
浏览文件 @
76ab5cb5
...
...
@@ -40,6 +40,7 @@ import org.apache.shardingsphere.core.rule.BaseRule;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
org.apache.shardingsphere.core.rule.MasterSlaveRule
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.core.strategy.encrypt.EncryptTable
;
import
org.apache.shardingsphere.spi.encrypt.ShardingEncryptor
;
import
org.apache.shardingsphere.spi.encrypt.ShardingQueryAssistedEncryptor
;
...
...
@@ -106,34 +107,26 @@ public final class SQLRewriteEngine {
return
optimizedStatement
instanceof
InsertOptimizedStatement
&&
!
encryptRule
.
getEncryptTableNames
().
isEmpty
();
}
private
void
encryptInsertOptimizedStatement
(
final
EncryptRule
encryptRule
,
final
Sharding
InsertOptimizedStatement
insertOptimizedStatement
)
{
private
void
encryptInsertOptimizedStatement
(
final
EncryptRule
encryptRule
,
final
InsertOptimizedStatement
insertOptimizedStatement
)
{
String
tableName
=
insertOptimizedStatement
.
getTables
().
getSingleTableName
();
for
(
InsertValue
insertValue
:
insertOptimizedStatement
.
getInsertValues
())
{
for
(
String
each
:
insertOptimizedStatement
.
getColumnNames
())
{
Optional
<
ShardingEncryptor
>
shardingEncryptor
=
encryptRule
.
findShardingEncryptor
(
tableName
,
each
);
if
(
shardingEncryptor
.
isPresent
())
{
encryptInsertValue
(
encryptRule
,
shardingEncryptor
.
get
(),
insertOptimizedStatement
,
insertValue
,
each
);
}
}
Optional
<
EncryptTable
>
encryptTable
=
encryptRule
.
findEncryptTable
(
tableName
);
if
(!
encryptTable
.
isPresent
())
{
return
;
}
}
private
void
encryptInsertOptimizedStatement
(
final
EncryptRule
encryptRule
,
final
EncryptInsertOptimizedStatement
insertOptimizedStatement
)
{
String
tableName
=
insertOptimizedStatement
.
getTables
().
getSingleTableName
();
for
(
InsertValue
insertValue
:
insertOptimizedStatement
.
getInsertValues
())
{
for
(
String
each
:
insertOptimizedStatement
.
getColumnNames
())
{
Optional
<
ShardingEncryptor
>
shardingEncryptor
=
encryptRule
.
findShardingEncryptor
(
tableName
,
each
);
if
(
shardingEncryptor
.
isPresent
())
{
encryptInsertValue
(
encryptRule
,
shardingEncryptor
.
get
(),
insertOptimizedStatement
,
insertValue
,
each
);
for
(
String
each
:
encryptTable
.
get
().
getLogicColumns
())
{
int
columnIndex
=
insertOptimizedStatement
.
getColumnNames
().
indexOf
(
each
);
Optional
<
ShardingEncryptor
>
shardingEncryptor
=
encryptRule
.
findShardingEncryptor
(
tableName
,
each
);
if
(
shardingEncryptor
.
isPresent
())
{
for
(
InsertValue
insertValue
:
insertOptimizedStatement
.
getInsertValues
())
{
encryptInsertValue
(
encryptRule
,
shardingEncryptor
.
get
(),
tableName
,
columnIndex
,
insertValue
,
each
);
}
}
}
}
private
void
encryptInsertValue
(
final
EncryptRule
encryptRule
,
final
ShardingEncryptor
shardingEncryptor
,
final
InsertOptimizedStatement
insertOptimizedStatement
,
final
InsertValue
insertValue
,
final
String
encryptLogicColumnName
)
{
String
tableName
=
insertOptimizedStatement
.
getTables
().
getSingleTableName
();
Object
originalValue
=
insertValue
.
getValue
(
insertOptimizedStatement
.
getColumnNames
().
indexOf
(
encryptLogicColumnName
));
final
String
tableName
,
final
int
columnIndex
,
final
InsertValue
insertValue
,
final
String
encryptLogicColumnName
)
{
Object
originalValue
=
insertValue
.
getValue
(
columnIndex
);
insertValue
.
setValue
(
encryptLogicColumnName
,
shardingEncryptor
.
encrypt
(
originalValue
));
if
(
shardingEncryptor
instanceof
ShardingQueryAssistedEncryptor
)
{
Optional
<
String
>
assistedColumnName
=
encryptRule
.
findAssistedQueryColumn
(
tableName
,
encryptLogicColumnName
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录