Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
cad07432
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,发现更多精彩内容 >>
提交
cad07432
编写于
9月 03, 2019
作者:
L
liya.cookie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
show logicColumn when desc EncryptTable
上级
6140cc1a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
12 deletion
+35
-12
sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dal/desc/DescribeTableMergedResult.java
...sphere/core/merge/dal/desc/DescribeTableMergedResult.java
+12
-7
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dal/desc/DescribeTableMergedResultTest.java
...re/core/merge/dal/desc/DescribeTableMergedResultTest.java
+23
-5
未找到文件。
sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dal/desc/DescribeTableMergedResult.java
浏览文件 @
cad07432
...
...
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.core.merge.dql.common.MemoryMergedResult;
import
org.apache.shardingsphere.core.merge.dql.common.MemoryQueryResultRow
;
import
org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.core.strategy.encrypt.EncryptTable
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
...
...
@@ -63,13 +64,21 @@ public class DescribeTableMergedResult extends MemoryMergedResult {
private
Iterator
<
MemoryQueryResultRow
>
init
(
final
List
<
QueryResult
>
queryResults
)
throws
SQLException
{
String
logicTableName
=
optimizedStatement
.
getTables
().
getSingleTableName
();
Map
<
String
,
EncryptTable
>
tables
=
shardingRule
.
getEncryptRule
().
getTables
();
boolean
encrypted
=
tables
.
containsKey
(
logicTableName
);
List
<
MemoryQueryResultRow
>
result
=
new
LinkedList
<>();
for
(
QueryResult
each
:
queryResults
)
{
while
(
each
.
next
())
{
MemoryQueryResultRow
memoryResultSetRow
=
new
MemoryQueryResultRow
(
each
);
String
actualColumn
=
memoryResultSetRow
.
getCell
(
1
).
toString
();
if
(
hide
(
logicTableName
,
actualColumn
))
{
continue
;
if
(
encrypted
)
{
EncryptTable
encryptTable
=
tables
.
get
(
logicTableName
);
String
columnName
=
memoryResultSetRow
.
getCell
(
1
).
toString
();
if
(
encryptTable
.
getAssistedQueryColumns
().
contains
(
columnName
))
{
continue
;
}
if
(
encryptTable
.
getCipherColumns
().
contains
(
columnName
))
{
memoryResultSetRow
.
setCell
(
1
,
encryptTable
.
getLogicColumn
(
columnName
));
}
}
result
.
add
(
memoryResultSetRow
);
}
...
...
@@ -80,10 +89,6 @@ public class DescribeTableMergedResult extends MemoryMergedResult {
return
result
.
iterator
();
}
private
boolean
hide
(
final
String
logicTable
,
final
String
actualColumn
)
{
return
shardingRule
.
getEncryptRule
().
getAssistedQueryColumns
(
logicTable
).
contains
(
actualColumn
);
}
@Override
public
boolean
next
()
throws
SQLException
{
if
(
memoryResultSetRows
.
hasNext
())
{
...
...
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dal/desc/DescribeTableMergedResultTest.java
浏览文件 @
cad07432
...
...
@@ -24,14 +24,17 @@ import org.apache.shardingsphere.core.optimize.api.segment.Tables;
import
org.apache.shardingsphere.core.optimize.api.statement.OptimizedStatement
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.core.strategy.encrypt.EncryptTable
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.SQLException
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
...
...
@@ -97,8 +100,16 @@ public class DescribeTableMergedResultTest {
}
@Test
public
void
assertNextForEmptyQueryResult
()
throws
SQLException
{
ShardingRule
shardingRule
=
mock
(
ShardingRule
.
class
);
public
void
assertNextForEmptyQueryResultWithoutEncryptRule
()
throws
SQLException
{
ShardingRule
shardingRule
=
mockShardingRuleWithoutEncryptRule
();
List
<
QueryResult
>
queryResults
=
Collections
.
emptyList
();
DescribeTableMergedResult
describeTableMergedResult
=
new
DescribeTableMergedResult
(
shardingRule
,
queryResults
,
optimizedStatement
);
assertFalse
(
describeTableMergedResult
.
next
());
}
@Test
public
void
assertNextForEmptyQueryResultWithEncryptRule
()
throws
SQLException
{
ShardingRule
shardingRule
=
mockShardingRuleWithEncryptRule
();
List
<
QueryResult
>
queryResults
=
Collections
.
emptyList
();
DescribeTableMergedResult
describeTableMergedResult
=
new
DescribeTableMergedResult
(
shardingRule
,
queryResults
,
optimizedStatement
);
assertFalse
(
describeTableMergedResult
.
next
());
...
...
@@ -112,8 +123,8 @@ public class DescribeTableMergedResultTest {
assertEquals
(
describeTableMergedResult
.
getValue
(
1
,
String
.
class
),
"id"
);
assertEquals
(
describeTableMergedResult
.
getValue
(
"Field"
,
String
.
class
),
"id"
);
assertTrue
(
describeTableMergedResult
.
next
());
assertEquals
(
describeTableMergedResult
.
getValue
(
1
,
String
.
class
),
"name"
);
assertEquals
(
describeTableMergedResult
.
getValue
(
"Field"
,
String
.
class
),
"name"
);
assertEquals
(
describeTableMergedResult
.
getValue
(
1
,
String
.
class
),
"
logic_
name"
);
assertEquals
(
describeTableMergedResult
.
getValue
(
"Field"
,
String
.
class
),
"
logic_
name"
);
assertTrue
(
describeTableMergedResult
.
next
());
assertEquals
(
describeTableMergedResult
.
getValue
(
1
,
String
.
class
),
"pre_name"
);
assertEquals
(
describeTableMergedResult
.
getValue
(
"Field"
,
String
.
class
),
"pre_name"
);
...
...
@@ -179,6 +190,7 @@ public class DescribeTableMergedResultTest {
private
ShardingRule
mockShardingRuleWithoutEncryptRule
()
{
ShardingRule
shardingRule
=
mock
(
ShardingRule
.
class
);
EncryptRule
encryptRule
=
mock
(
EncryptRule
.
class
);
when
(
encryptRule
.
getTables
()).
thenReturn
(
Collections
.<
String
,
EncryptTable
>
emptyMap
());
when
(
shardingRule
.
getEncryptRule
()).
thenReturn
(
encryptRule
);
return
shardingRule
;
}
...
...
@@ -186,8 +198,14 @@ public class DescribeTableMergedResultTest {
private
ShardingRule
mockShardingRuleWithEncryptRule
()
{
ShardingRule
shardingRule
=
mock
(
ShardingRule
.
class
);
EncryptRule
encryptRule
=
mock
(
EncryptRule
.
class
);
when
(
encryptRule
.
getAssistedQueryColumns
(
"user"
)).
thenReturn
(
Arrays
.
asList
(
"name_assisted"
));
EncryptTable
encryptTable
=
mock
(
EncryptTable
.
class
);
Map
<
String
,
EncryptTable
>
tables
=
new
HashMap
<>();
tables
.
put
(
"user"
,
encryptTable
);
when
(
shardingRule
.
getEncryptRule
()).
thenReturn
(
encryptRule
);
when
(
encryptRule
.
getTables
()).
thenReturn
(
tables
);
when
(
encryptTable
.
getAssistedQueryColumns
()).
thenReturn
(
Arrays
.
asList
(
"name_assisted"
));
when
(
encryptTable
.
getCipherColumns
()).
thenReturn
(
Arrays
.
asList
(
"name"
));
when
(
encryptTable
.
getLogicColumn
(
"name"
)).
thenReturn
(
"logic_name"
);
return
shardingRule
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录