Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
dc35d382
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,发现更多精彩内容 >>
提交
dc35d382
编写于
8月 22, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #2567, InsertValueEngine => InsertValuesFactory
上级
d34a2ab9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
20 deletion
+21
-20
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/encrypt/engine/dml/EncryptInsertOptimizeEngine.java
...imize/encrypt/engine/dml/EncryptInsertOptimizeEngine.java
+2
-3
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java
...ize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java
+3
-4
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/segment/insert/value/InsertValuesFactory.java
...ze/sharding/segment/insert/value/InsertValuesFactory.java
+9
-6
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/SQLRewriteEngine.java
.../apache/shardingsphere/core/rewrite/SQLRewriteEngine.java
+7
-7
未找到文件。
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/encrypt/engine/dml/EncryptInsertOptimizeEngine.java
浏览文件 @
dc35d382
...
...
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.core.optimize.encrypt.engine.EncryptOptimizeEng
import
org.apache.shardingsphere.core.optimize.encrypt.segment.EncryptInsertColumns
;
import
org.apache.shardingsphere.core.optimize.encrypt.statement.EncryptInsertOptimizedStatement
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.InsertOptimizeResultUnit
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.value.InsertValue
Engine
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.value.InsertValue
sFactory
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
...
...
@@ -40,9 +40,8 @@ public final class EncryptInsertOptimizeEngine implements EncryptOptimizeEngine<
@Override
public
EncryptInsertOptimizedStatement
optimize
(
final
EncryptRule
encryptRule
,
final
TableMetas
tableMetas
,
final
String
sql
,
final
List
<
Object
>
parameters
,
final
InsertStatement
sqlStatement
)
{
InsertValueEngine
insertValueEngine
=
new
InsertValueEngine
();
EncryptInsertOptimizedStatement
result
=
new
EncryptInsertOptimizedStatement
(
sqlStatement
,
new
EncryptInsertColumns
(
tableMetas
,
sqlStatement
),
insertValueEngine
.
createInsertValues
(
sqlStatement
));
sqlStatement
,
new
EncryptInsertColumns
(
tableMetas
,
sqlStatement
),
InsertValuesFactory
.
createInsertValues
(
sqlStatement
));
int
derivedColumnsCount
=
encryptRule
.
getAssistedQueryAndPlainColumnCount
(
sqlStatement
.
getTable
().
getTableName
());
int
parametersCount
=
0
;
Collection
<
String
>
columnNames
=
getColumnNames
(
tableMetas
,
sqlStatement
);
...
...
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java
浏览文件 @
dc35d382
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.core.optimize.sharding.segment.condition.engine
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.GeneratedKey
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.InsertOptimizeResultUnit
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.ShardingInsertColumns
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.value.InsertValue
Engine
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.value.InsertValue
sFactory
;
import
org.apache.shardingsphere.core.optimize.sharding.statement.dml.ShardingInsertOptimizedStatement
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.column.ColumnSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.column.OnDuplicateKeyColumnsSegment
;
...
...
@@ -54,8 +54,7 @@ public final class ShardingInsertOptimizeEngine implements ShardingOptimizeEngin
final
TableMetas
tableMetas
,
final
String
sql
,
final
List
<
Object
>
parameters
,
final
InsertStatement
sqlStatement
)
{
InsertClauseShardingConditionEngine
shardingConditionEngine
=
new
InsertClauseShardingConditionEngine
(
shardingRule
);
ShardingInsertColumns
insertColumns
=
new
ShardingInsertColumns
(
shardingRule
,
tableMetas
,
sqlStatement
);
InsertValueEngine
insertValueEngine
=
new
InsertValueEngine
();
Collection
<
InsertValue
>
insertValues
=
insertValueEngine
.
createInsertValues
(
sqlStatement
);
Collection
<
InsertValue
>
insertValues
=
InsertValuesFactory
.
createInsertValues
(
sqlStatement
);
Optional
<
GeneratedKey
>
generatedKey
=
GeneratedKey
.
getGenerateKey
(
shardingRule
,
parameters
,
sqlStatement
,
insertColumns
,
insertValues
);
boolean
isGeneratedValue
=
generatedKey
.
isPresent
()
&&
generatedKey
.
get
().
isGenerated
();
Iterator
<
Comparable
<?>>
generatedValues
=
isGeneratedValue
?
generatedKey
.
get
().
getGeneratedValues
().
iterator
()
:
null
;
...
...
@@ -66,7 +65,7 @@ public final class ShardingInsertOptimizeEngine implements ShardingOptimizeEngin
allColumnNames
.
addAll
(
shardingRule
.
getEncryptRule
().
getAssistedQueryAndPlainColumns
(
sqlStatement
.
getTable
().
getTableName
()));
List
<
ShardingCondition
>
shardingConditions
=
shardingConditionEngine
.
createShardingConditions
(
sqlStatement
,
parameters
,
allColumnNames
,
insertValues
,
generatedKey
.
orNull
());
ShardingInsertOptimizedStatement
result
=
new
ShardingInsertOptimizedStatement
(
sqlStatement
,
shardingConditions
,
insertColumns
,
insertValueEngine
.
createInsertValues
(
sqlStatement
),
generatedKey
.
orNull
());
sqlStatement
,
shardingConditions
,
insertColumns
,
InsertValuesFactory
.
createInsertValues
(
sqlStatement
),
generatedKey
.
orNull
());
String
tableName
=
sqlStatement
.
getTable
().
getTableName
();
checkDuplicateKeyForShardingKey
(
shardingRule
,
sqlStatement
,
tableName
);
int
derivedColumnsCount
=
getDerivedColumnsCount
(
shardingRule
,
tableName
,
isGeneratedValue
);
...
...
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/segment/insert/value/InsertValue
Engine
.java
→
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/segment/insert/value/InsertValue
sFactory
.java
浏览文件 @
dc35d382
...
...
@@ -17,6 +17,8 @@
package
org.apache.shardingsphere.core.optimize.sharding.segment.insert.value
;
import
lombok.AccessLevel
;
import
lombok.NoArgsConstructor
;
import
org.apache.shardingsphere.core.optimize.api.segment.InsertValue
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.InsertValuesSegment
;
...
...
@@ -29,11 +31,12 @@ import java.util.LinkedList;
import
java.util.List
;
/**
* Insert value
engine
.
* Insert value
s factory
.
*
* @author zhangliang
*/
public
final
class
InsertValueEngine
{
@NoArgsConstructor
(
access
=
AccessLevel
.
PRIVATE
)
public
final
class
InsertValuesFactory
{
/**
* Create insert values.
...
...
@@ -41,11 +44,11 @@ public final class InsertValueEngine {
* @param insertStatement insert statement
* @return insert values
*/
public
Collection
<
InsertValue
>
createInsertValues
(
final
InsertStatement
insertStatement
)
{
return
(
insertStatement
.
getSetAssignment
().
isPresent
()
)
?
getInsertValues
(
insertStatement
.
getSetAssignment
().
get
())
:
getInsertValues
(
insertStatement
.
getValues
());
public
static
Collection
<
InsertValue
>
createInsertValues
(
final
InsertStatement
insertStatement
)
{
return
insertStatement
.
getSetAssignment
().
isPresent
(
)
?
getInsertValues
(
insertStatement
.
getSetAssignment
().
get
())
:
getInsertValues
(
insertStatement
.
getValues
());
}
private
Collection
<
InsertValue
>
getInsertValues
(
final
SetAssignmentsSegment
setAssignmentsSegment
)
{
private
static
Collection
<
InsertValue
>
getInsertValues
(
final
SetAssignmentsSegment
setAssignmentsSegment
)
{
Collection
<
InsertValue
>
result
=
new
LinkedList
<>();
List
<
ExpressionSegment
>
columnValues
=
new
LinkedList
<>();
for
(
AssignmentSegment
each
:
setAssignmentsSegment
.
getAssignments
())
{
...
...
@@ -55,7 +58,7 @@ public final class InsertValueEngine {
return
result
;
}
private
Collection
<
InsertValue
>
getInsertValues
(
final
Collection
<
InsertValuesSegment
>
insertValuesSegments
)
{
private
static
Collection
<
InsertValue
>
getInsertValues
(
final
Collection
<
InsertValuesSegment
>
insertValuesSegments
)
{
Collection
<
InsertValue
>
result
=
new
LinkedList
<>();
for
(
InsertValuesSegment
each
:
insertValuesSegments
)
{
result
.
add
(
new
InsertValue
(
each
.
getValues
()));
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/SQLRewriteEngine.java
浏览文件 @
dc35d382
...
...
@@ -90,20 +90,20 @@ public final class SQLRewriteEngine {
}
private
OptimizedStatement
encryptOptimizedStatement
(
final
EncryptRule
encryptRule
,
final
OptimizedStatement
optimizedStatement
)
{
if
(
is
NeededToEncryp
t
(
encryptRule
,
optimizedStatement
))
{
encryptInsertOptimize
ResultUnit
(
encryptRule
,
optimizedStatement
);
if
(
is
EncryptWithInser
t
(
encryptRule
,
optimizedStatement
))
{
encryptInsertOptimize
dStatement
(
encryptRule
,
(
InsertOptimizedStatement
)
optimizedStatement
);
}
return
optimizedStatement
;
}
private
boolean
is
NeededToEncryp
t
(
final
EncryptRule
encryptRule
,
final
OptimizedStatement
optimizedStatement
)
{
private
boolean
is
EncryptWithInser
t
(
final
EncryptRule
encryptRule
,
final
OptimizedStatement
optimizedStatement
)
{
return
optimizedStatement
instanceof
InsertOptimizedStatement
&&
!
encryptRule
.
getEncryptTableNames
().
isEmpty
();
}
private
void
encryptInsertOptimize
ResultUnit
(
final
EncryptRule
encryptRule
,
final
OptimizedStatement
o
ptimizedStatement
)
{
for
(
InsertOptimizeResultUnit
unit
:
((
InsertOptimizedStatement
)
optimizedStatement
)
.
getUnits
())
{
for
(
String
each
:
((
InsertOptimizedStatement
)
optimizedStatement
)
.
getInsertColumns
().
getRegularColumnNames
())
{
encryptInsertOptimizeResult
(
encryptRule
,
unit
,
o
ptimizedStatement
.
getTables
().
getSingleTableName
(),
each
);
private
void
encryptInsertOptimize
dStatement
(
final
EncryptRule
encryptRule
,
final
InsertOptimizedStatement
insertO
ptimizedStatement
)
{
for
(
InsertOptimizeResultUnit
unit
:
insertOptimizedStatement
.
getUnits
())
{
for
(
String
each
:
insertOptimizedStatement
.
getInsertColumns
().
getRegularColumnNames
())
{
encryptInsertOptimizeResult
(
encryptRule
,
unit
,
insertO
ptimizedStatement
.
getTables
().
getSingleTableName
(),
each
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录