Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
9661bba4
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,发现更多精彩内容 >>
提交
9661bba4
编写于
9月 01, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #2567, remove ShardingInsertOptimizedStatement.createInsertValue()
上级
1447d3c0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
52 deletion
+21
-52
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java
...ize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java
+11
-2
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/statement/dml/ShardingInsertOptimizedStatement.java
...rding/statement/dml/ShardingInsertOptimizedStatement.java
+0
-20
sharding-core/sharding-core-optimize/src/test/java/org/apache/shardingsphere/core/optimize/sharding/segment/insert/InsertOptimizedStatementTest.java
...sharding/segment/insert/InsertOptimizedStatementTest.java
+2
-6
sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriteEngineTest.java
...e/core/rewrite/rewriter/ShardingSQLRewriteEngineTest.java
+8
-24
未找到文件。
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/engnie/dml/ShardingInsertOptimizeEngine.java
浏览文件 @
9661bba4
...
...
@@ -36,6 +36,7 @@ import java.util.Arrays;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
...
...
@@ -69,9 +70,9 @@ public final class ShardingInsertOptimizeEngine implements ShardingOptimizeEngin
ShardingInsertOptimizedStatement
result
=
new
ShardingInsertOptimizedStatement
(
sqlStatement
,
shardingConditions
,
columnNames
,
generatedKey
.
orNull
());
checkDuplicateKeyForShardingKey
(
shardingRule
,
sqlStatement
,
tableName
);
int
parametersOffset
=
0
;
Collection
<
String
>
encryptDerivedColumnNames
=
shardingRule
.
getEncryptRule
().
getAssistedQueryAndPlainColumns
(
tableName
);
for
(
Collection
<
ExpressionSegment
>
each
:
sqlStatement
.
getAllValueExpressions
())
{
Collection
<
String
>
encryptDerivedColumnNames
=
shardingRule
.
getEncryptRule
().
getAssistedQueryAndPlainColumns
(
tableName
);
InsertValue
insertValue
=
result
.
createInsertValue
(
generateKeyColumnName
.
orNull
(),
encryptDerivedColumnNames
,
each
,
derivedColumnsCount
,
parameters
,
parametersOffset
);
InsertValue
insertValue
=
createInsertValue
(
columnNames
,
generateKeyColumnName
.
orNull
(),
encryptDerivedColumnNames
,
each
,
derivedColumnsCount
,
parameters
,
parametersOffset
);
result
.
addInsertValue
(
insertValue
);
Object
[]
currentParameters
=
insertValue
.
getParameters
();
if
(
isGeneratedValue
)
{
...
...
@@ -118,6 +119,14 @@ public final class ShardingInsertOptimizeEngine implements ShardingOptimizeEngin
return
false
;
}
private
InsertValue
createInsertValue
(
final
Collection
<
String
>
columnNames
,
final
String
generateKeyColumnName
,
final
Collection
<
String
>
derivedColumnNames
,
final
Collection
<
ExpressionSegment
>
assignments
,
final
int
derivedColumnsCount
,
final
List
<
Object
>
parameters
,
final
int
parametersOffset
)
{
List
<
String
>
allColumnNames
=
new
LinkedList
<>(
columnNames
);
allColumnNames
.
add
(
generateKeyColumnName
);
allColumnNames
.
addAll
(
derivedColumnNames
);
return
new
InsertValue
(
allColumnNames
,
assignments
,
derivedColumnsCount
,
parameters
,
parametersOffset
);
}
private
void
fillAssistedQueryInsertValue
(
final
ShardingRule
shardingRule
,
final
String
tableName
,
final
Collection
<
String
>
columnNames
,
final
InsertValue
insertValue
,
final
List
<
Object
>
parameters
)
{
for
(
String
each
:
columnNames
)
{
...
...
sharding-core/sharding-core-optimize/src/main/java/org/apache/shardingsphere/core/optimize/sharding/statement/dml/ShardingInsertOptimizedStatement.java
浏览文件 @
9661bba4
...
...
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.core.optimize.encrypt.condition.EncryptConditio
import
org.apache.shardingsphere.core.optimize.sharding.segment.condition.ShardingCondition
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.condition.ShardingConditions
;
import
org.apache.shardingsphere.core.optimize.sharding.segment.insert.GeneratedKey
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
java.util.Collection
;
...
...
@@ -61,25 +60,6 @@ public final class ShardingInsertOptimizedStatement extends ShardingConditionOpt
this
.
generatedKey
=
generatedKey
;
}
/**
* Create insert value.
*
* @param generateKeyColumnName generate key column name
* @param derivedColumnNames derived column names
* @param assignments assignments
* @param derivedColumnsCount derived columns count
* @param parameters SQL parameters
* @param parametersOffset offset of SQL parameters
* @return insert value
*/
public
InsertValue
createInsertValue
(
final
String
generateKeyColumnName
,
final
Collection
<
String
>
derivedColumnNames
,
final
Collection
<
ExpressionSegment
>
assignments
,
final
int
derivedColumnsCount
,
final
List
<
Object
>
parameters
,
final
int
parametersOffset
)
{
List
<
String
>
allColumnNames
=
new
LinkedList
<>(
columnNames
);
allColumnNames
.
add
(
generateKeyColumnName
);
allColumnNames
.
addAll
(
derivedColumnNames
);
return
new
InsertValue
(
allColumnNames
,
assignments
,
derivedColumnsCount
,
parameters
,
parametersOffset
);
}
/**
* Add insert value.
*
...
...
sharding-core/sharding-core-optimize/src/test/java/org/apache/shardingsphere/core/optimize/sharding/segment/insert/InsertOptimizedStatementTest.java
浏览文件 @
9661bba4
...
...
@@ -27,9 +27,7 @@ import org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement;
import
org.junit.Test
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertNull
;
...
...
@@ -44,10 +42,8 @@ public final class InsertOptimizedStatementTest {
ExpressionSegment
assignment1
=
new
LiteralExpressionSegment
(
0
,
0
,
1
);
ExpressionSegment
assignment2
=
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
);
ExpressionSegment
assignment3
=
new
LiteralExpressionSegment
(
0
,
0
,
"test"
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.
asList
(
assignment1
,
assignment2
,
assignment3
);
List
<
Object
>
parameters
=
Collections
.<
Object
>
singletonList
(
"parameter"
);
InsertValue
insertValue
=
insertClauseOptimizedStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
1
,
parameters
,
0
);
insertClauseOptimizedStatement
.
addInsertValue
(
insertValue
);
insertClauseOptimizedStatement
.
addInsertValue
(
new
InsertValue
(
Arrays
.
asList
(
"id"
,
"value"
,
"status"
,
"id"
),
Arrays
.
asList
(
assignment1
,
assignment2
,
assignment3
),
1
,
Collections
.<
Object
>
singletonList
(
"parameter"
),
0
));
assertThat
(
insertClauseOptimizedStatement
.
getInsertValues
().
get
(
0
).
getValueExpressions
().
length
,
is
(
4
));
assertThat
(
insertClauseOptimizedStatement
.
getInsertValues
().
get
(
0
).
getValueExpressions
()[
0
],
is
(
assignment1
));
assertThat
(
insertClauseOptimizedStatement
.
getInsertValues
().
get
(
0
).
getValueExpressions
()[
1
],
is
(
assignment2
));
...
...
sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriteEngineTest.java
浏览文件 @
9661bba4
...
...
@@ -221,9 +221,7 @@ public final class ShardingSQLRewriteEngineTest {
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Arrays
.
asList
(
"name"
,
"age"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
2
));
List
<
Object
>
parameters
=
Arrays
.<
Object
>
asList
(
"x"
,
1
,
1
);
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
0
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Arrays
.
asList
(
"name"
,
"age"
,
"id"
),
assignments
,
0
,
Arrays
.<
Object
>
asList
(
"x"
,
1
,
1
),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -246,9 +244,7 @@ public final class ShardingSQLRewriteEngineTest {
insertStatement
.
getAllSQLSegments
().
add
(
new
TableSegment
(
12
,
20
,
"`table_x`"
));
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Collections
.
singletonList
(
"name"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
));
List
<
Object
>
parameters
=
Arrays
.<
Object
>
asList
(
"Bill"
,
1
);
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
0
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Collections
.
singletonList
(
"id"
),
assignments
,
0
,
Arrays
.<
Object
>
asList
(
"Bill"
,
1
),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -271,9 +267,7 @@ public final class ShardingSQLRewriteEngineTest {
insertStatement
.
getAllSQLSegments
().
add
(
new
TableSegment
(
12
,
20
,
"`table_x`"
));
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Collections
.
singletonList
(
"name"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
));
List
<
Object
>
parameters
=
Collections
.
emptyList
();
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
0
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Collections
.
singletonList
(
"id"
),
assignments
,
0
,
Collections
.
emptyList
(),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -296,9 +290,7 @@ public final class ShardingSQLRewriteEngineTest {
insertStatement
.
getAllSQLSegments
().
add
(
new
TableSegment
(
12
,
20
,
"`table_x`"
));
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Collections
.
singletonList
(
"name"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
));
List
<
Object
>
parameters
=
Collections
.
emptyList
();
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
0
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Collections
.
singletonList
(
"id"
),
assignments
,
0
,
Collections
.
emptyList
(),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -320,9 +312,7 @@ public final class ShardingSQLRewriteEngineTest {
insertStatement
.
getAllSQLSegments
().
add
(
new
TableSegment
(
12
,
20
,
"`table_x`"
));
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Arrays
.
asList
(
"name"
,
"id"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
));
List
<
Object
>
parameters
=
Collections
.
emptyList
();
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
1
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Arrays
.
asList
(
"name"
,
"id"
,
"id"
),
assignments
,
1
,
Collections
.
emptyList
(),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -345,9 +335,7 @@ public final class ShardingSQLRewriteEngineTest {
insertStatement
.
getAllSQLSegments
().
add
(
new
InsertValuesSegment
(
29
,
35
,
Collections
.<
ExpressionSegment
>
emptyList
()));
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Arrays
.
asList
(
"name"
,
"id"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
));
List
<
Object
>
parameters
=
Collections
.
emptyList
();
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
0
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Arrays
.
asList
(
"name"
,
"id"
,
"id"
),
assignments
,
0
,
Collections
.
emptyList
(),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -369,9 +357,7 @@ public final class ShardingSQLRewriteEngineTest {
insertStatement
.
getAllSQLSegments
().
add
(
new
TableSegment
(
12
,
20
,
"`table_x`"
));
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Collections
.
singletonList
(
"name"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
));
List
<
Object
>
parameters
=
Arrays
.<
Object
>
asList
(
"x"
,
1
);
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Collections
.<
String
>
emptyList
(),
assignments
,
0
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Collections
.
singletonList
(
"id"
),
assignments
,
0
,
Arrays
.<
Object
>
asList
(
"x"
,
1
),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
@@ -974,9 +960,7 @@ public final class ShardingSQLRewriteEngineTest {
ShardingInsertOptimizedStatement
shardingStatement
=
new
ShardingInsertOptimizedStatement
(
insertStatement
,
Collections
.<
ShardingCondition
>
emptyList
(),
Collections
.
singletonList
(
"name"
),
null
);
Collection
<
ExpressionSegment
>
assignments
=
Arrays
.<
ExpressionSegment
>
asList
(
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
),
new
LiteralExpressionSegment
(
0
,
0
,
1
),
new
LiteralExpressionSegment
(
0
,
0
,
10
));
List
<
Object
>
parameters
=
Collections
.
emptyList
();
InsertValue
insertValue
=
shardingStatement
.
createInsertValue
(
"id"
,
Arrays
.
asList
(
"plain"
,
"query"
),
assignments
,
3
,
parameters
,
0
);
shardingStatement
.
addInsertValue
(
insertValue
);
shardingStatement
.
addInsertValue
(
new
InsertValue
(
Arrays
.
asList
(
"name"
,
"id"
,
"plain"
,
"query"
),
assignments
,
3
,
Collections
.
emptyList
(),
0
));
shardingStatement
.
getInsertValues
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
SQLRouteResult
result
=
new
SQLRouteResult
(
shardingStatement
,
new
EncryptTransparentOptimizedStatement
(
insertStatement
));
result
.
setRoutingResult
(
new
RoutingResult
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录