Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
ce7e1f18
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,发现更多精彩内容 >>
未验证
提交
ce7e1f18
编写于
6月 05, 2019
作者:
L
Liang Zhang
提交者:
GitHub
6月 05, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2501 from tristaZero/dev
Split InsertSetAddItemsToken
上级
2f145397
5c8ed7bc
变更
44
隐藏空白更改
内联
并排
Showing
44 changed file
with
462 addition
and
321 deletion
+462
-321
sharding-core/sharding-core-entry/src/main/java/org/apache/shardingsphere/core/BaseShardingEngine.java
...va/org/apache/shardingsphere/core/BaseShardingEngine.java
+1
-1
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/encrypt/dml/EncryptSetAssignmentsFiller.java
...parse/filler/encrypt/dml/EncryptSetAssignmentsFiller.java
+1
-41
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/encrypt/dml/insert/EncryptInsertValuesFiller.java
.../filler/encrypt/dml/insert/EncryptInsertValuesFiller.java
+0
-15
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/sharding/dml/insert/ShardingInsertValuesFiller.java
...iller/sharding/dml/insert/ShardingInsertValuesFiller.java
+0
-14
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/sharding/dml/update/ShardingSetAssignmentsFiller.java
...ler/sharding/dml/update/ShardingSetAssignmentsFiller.java
+0
-46
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/AbstractSQLStatement.java
...sphere/core/parse/sql/statement/AbstractSQLStatement.java
+12
-11
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/SQLStatement.java
...shardingsphere/core/parse/sql/statement/SQLStatement.java
+9
-9
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java
...here/core/parse/integrate/asserts/SQLStatementAssert.java
+0
-5
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/token/InsertValuesTokenAssert.java
...arse/integrate/asserts/token/InsertValuesTokenAssert.java
+0
-65
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/jaxb/token/ExpectedInsertValuesToken.java
...parse/integrate/jaxb/token/ExpectedInsertValuesToken.java
+0
-34
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/jaxb/token/ExpectedTokens.java
...phere/core/parse/integrate/jaxb/token/ExpectedTokens.java
+0
-3
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/resources/parser/dml/insert.xml
...-core-parse-test/src/test/resources/parser/dml/insert.xml
+0
-25
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/placeholder/InsertSetAddGeneratedKeyPlaceholder.java
...rite/placeholder/InsertSetAddGeneratedKeyPlaceholder.java
+52
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/BaseSQLRewriter.java
...shardingsphere/core/rewrite/rewriter/BaseSQLRewriter.java
+1
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/EncryptSQLRewriter.java
...rdingsphere/core/rewrite/rewriter/EncryptSQLRewriter.java
+8
-8
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriter.java
...dingsphere/core/rewrite/rewriter/ShardingSQLRewriter.java
+36
-6
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/BaseTokenGenerateEngine.java
...ingsphere/core/rewrite/token/BaseTokenGenerateEngine.java
+2
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/EncryptTokenGenerateEngine.java
...sphere/core/rewrite/token/EncryptTokenGenerateEngine.java
+4
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/ShardingTokenGenerateEngine.java
...phere/core/rewrite/token/ShardingTokenGenerateEngine.java
+2
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertSetAddAssistedColumnsTokenGenerator.java
.../generator/InsertSetAddAssistedColumnsTokenGenerator.java
+68
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertSetAddGeneratedKeyTokenGenerator.java
...ken/generator/InsertSetAddGeneratedKeyTokenGenerator.java
+61
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertSetEncryptValueTokenGenerator.java
.../token/generator/InsertSetEncryptValueTokenGenerator.java
+68
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertValuesTokenGenerator.java
...e/rewrite/token/generator/InsertValuesTokenGenerator.java
+54
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/AggregationDistinctToken.java
...ere/core/rewrite/token/pojo/AggregationDistinctToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/Attachable.java
...he/shardingsphere/core/rewrite/token/pojo/Attachable.java
+1
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/EncryptColumnToken.java
...ingsphere/core/rewrite/token/pojo/EncryptColumnToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/IndexToken.java
...he/shardingsphere/core/rewrite/token/pojo/IndexToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertAssistedColumnsToken.java
...e/core/rewrite/token/pojo/InsertAssistedColumnsToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertColumnsToken.java
...ingsphere/core/rewrite/token/pojo/InsertColumnsToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertGeneratedKeyToken.java
...here/core/rewrite/token/pojo/InsertGeneratedKeyToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertSetAddAssistedColumnsToken.java
.../rewrite/token/pojo/InsertSetAddAssistedColumnsToken.java
+3
-4
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertSetAddGeneratedKeyToken.java
...ore/rewrite/token/pojo/InsertSetAddGeneratedKeyToken.java
+37
-0
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertSetEncryptValueToken.java
...e/core/rewrite/token/pojo/InsertSetEncryptValueToken.java
+1
-2
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertValuesToken.java
...dingsphere/core/rewrite/token/pojo/InsertValuesToken.java
+1
-2
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java
...e/shardingsphere/core/rewrite/token/pojo/OffsetToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OrderByToken.java
.../shardingsphere/core/rewrite/token/pojo/OrderByToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RemoveToken.java
...e/shardingsphere/core/rewrite/token/pojo/RemoveToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java
...shardingsphere/core/rewrite/token/pojo/RowCountToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectItemPrefixToken.java
...sphere/core/rewrite/token/pojo/SelectItemPrefixToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectItemsToken.java
...rdingsphere/core/rewrite/token/pojo/SelectItemsToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/Substitutable.java
...shardingsphere/core/rewrite/token/pojo/Substitutable.java
+1
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/TableToken.java
...he/shardingsphere/core/rewrite/token/pojo/TableToken.java
+0
-1
sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java
...sphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java
+32
-12
sharding-core/sharding-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml
...ng-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml
+7
-2
未找到文件。
sharding-core/sharding-core-entry/src/main/java/org/apache/shardingsphere/core/BaseShardingEngine.java
浏览文件 @
ce7e1f18
...
@@ -103,7 +103,7 @@ public abstract class BaseShardingEngine {
...
@@ -103,7 +103,7 @@ public abstract class BaseShardingEngine {
private
Collection
<
RouteUnit
>
rewriteAndConvert
(
final
List
<
Object
>
parameters
,
final
SQLRouteResult
sqlRouteResult
)
{
private
Collection
<
RouteUnit
>
rewriteAndConvert
(
final
List
<
Object
>
parameters
,
final
SQLRouteResult
sqlRouteResult
)
{
SQLRewriteEngine
rewriteEngine
=
new
SQLRewriteEngine
(
shardingRule
,
sqlRouteResult
.
getSqlStatement
(),
parameters
);
SQLRewriteEngine
rewriteEngine
=
new
SQLRewriteEngine
(
shardingRule
,
sqlRouteResult
.
getSqlStatement
(),
parameters
);
ShardingSQLRewriter
shardingSQLRewriter
=
new
ShardingSQLRewriter
(
shardingRule
,
databaseType
,
sqlRouteResult
);
ShardingSQLRewriter
shardingSQLRewriter
=
new
ShardingSQLRewriter
(
shardingRule
,
databaseType
,
sqlRouteResult
,
sqlRouteResult
.
getOptimizeResult
()
);
EncryptSQLRewriter
encryptSQLRewriter
=
new
EncryptSQLRewriter
(
shardingRule
.
getEncryptRule
().
getEncryptorEngine
(),
sqlRouteResult
.
getSqlStatement
(),
sqlRouteResult
.
getOptimizeResult
());
EncryptSQLRewriter
encryptSQLRewriter
=
new
EncryptSQLRewriter
(
shardingRule
.
getEncryptRule
().
getEncryptorEngine
(),
sqlRouteResult
.
getSqlStatement
(),
sqlRouteResult
.
getOptimizeResult
());
rewriteEngine
.
init
(
shardingSQLRewriter
,
encryptSQLRewriter
);
rewriteEngine
.
init
(
shardingSQLRewriter
,
encryptSQLRewriter
);
Collection
<
RouteUnit
>
result
=
new
LinkedHashSet
<>();
Collection
<
RouteUnit
>
result
=
new
LinkedHashSet
<>();
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/encrypt/dml/EncryptSetAssignmentsFiller.java
浏览文件 @
ce7e1f18
...
@@ -17,26 +17,17 @@
...
@@ -17,26 +17,17 @@
package
org.apache.shardingsphere.core.parse.filler.encrypt.dml
;
package
org.apache.shardingsphere.core.parse.filler.encrypt.dml
;
import
com.google.common.base.Optional
;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.core.parse.filler.api.EncryptRuleAwareFiller
;
import
org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller
;
import
org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller
;
import
org.apache.shardingsphere.core.parse.sql.context.condition.Column
;
import
org.apache.shardingsphere.core.parse.sql.context.condition.Column
;
import
org.apache.shardingsphere.core.parse.sql.context.insertvalue.InsertValue
;
import
org.apache.shardingsphere.core.parse.sql.context.insertvalue.InsertValue
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertSetAddItemsToken
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertSetEncryptValueToken
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
org.apache.shardingsphere.spi.encrypt.ShardingEncryptor
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -46,9 +37,7 @@ import java.util.List;
...
@@ -46,9 +37,7 @@ import java.util.List;
* @author zhangliang
* @author zhangliang
*/
*/
@Setter
@Setter
public
final
class
EncryptSetAssignmentsFiller
implements
SQLSegmentFiller
<
SetAssignmentsSegment
>,
EncryptRuleAwareFiller
{
public
final
class
EncryptSetAssignmentsFiller
implements
SQLSegmentFiller
<
SetAssignmentsSegment
>
{
private
EncryptRule
encryptRule
;
@Override
@Override
public
void
fill
(
final
SetAssignmentsSegment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
public
void
fill
(
final
SetAssignmentsSegment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
...
@@ -66,45 +55,16 @@ public final class EncryptSetAssignmentsFiller implements SQLSegmentFiller<SetAs
...
@@ -66,45 +55,16 @@ public final class EncryptSetAssignmentsFiller implements SQLSegmentFiller<SetAs
InsertValue
insertValue
=
getInsertValue
(
sqlSegment
,
insertStatement
);
InsertValue
insertValue
=
getInsertValue
(
sqlSegment
,
insertStatement
);
insertStatement
.
getValues
().
add
(
insertValue
);
insertStatement
.
getValues
().
add
(
insertValue
);
insertStatement
.
setParametersIndex
(
insertValue
.
getParametersCount
());
insertStatement
.
setParametersIndex
(
insertValue
.
getParametersCount
());
fillWithInsertSetAddItemsToken
(
insertStatement
,
sqlSegment
);
}
}
private
InsertValue
getInsertValue
(
final
SetAssignmentsSegment
sqlSegment
,
final
InsertStatement
insertStatement
)
{
private
InsertValue
getInsertValue
(
final
SetAssignmentsSegment
sqlSegment
,
final
InsertStatement
insertStatement
)
{
List
<
ExpressionSegment
>
columnValues
=
new
LinkedList
<>();
List
<
ExpressionSegment
>
columnValues
=
new
LinkedList
<>();
for
(
AssignmentSegment
each
:
sqlSegment
.
getAssignments
())
{
for
(
AssignmentSegment
each
:
sqlSegment
.
getAssignments
())
{
columnValues
.
add
(
each
.
getValue
());
columnValues
.
add
(
each
.
getValue
());
fillWithInsertSetEncryptValueToken
(
insertStatement
,
each
,
each
.
getValue
());
}
}
return
new
InsertValue
(
columnValues
);
return
new
InsertValue
(
columnValues
);
}
}
private
void
fillWithInsertSetEncryptValueToken
(
final
InsertStatement
insertStatement
,
final
AssignmentSegment
segment
,
final
ExpressionSegment
columnValue
)
{
Optional
<
ShardingEncryptor
>
shardingEncryptor
=
encryptRule
.
getEncryptorEngine
().
getShardingEncryptor
(
insertStatement
.
getTables
().
getSingleTableName
(),
segment
.
getColumn
().
getName
());
if
(
shardingEncryptor
.
isPresent
()
&&
!(
columnValue
instanceof
ParameterMarkerExpressionSegment
))
{
insertStatement
.
getSQLTokens
().
add
(
new
InsertSetEncryptValueToken
(
segment
.
getValue
().
getStartIndex
(),
segment
.
getValue
().
getStopIndex
(),
segment
.
getColumn
().
getName
()));
}
}
private
void
fillWithInsertSetAddItemsToken
(
final
InsertStatement
insertStatement
,
final
SetAssignmentsSegment
sqlSegment
)
{
Collection
<
String
>
columnNames
=
getQueryAssistedColumn
(
insertStatement
);
if
(
columnNames
.
isEmpty
())
{
return
;
}
List
<
AssignmentSegment
>
assignments
=
new
ArrayList
<>(
sqlSegment
.
getAssignments
());
insertStatement
.
getSQLTokens
().
add
(
new
InsertSetAddItemsToken
(
assignments
.
get
(
assignments
.
size
()
-
1
).
getStopIndex
()
+
1
,
columnNames
));
}
private
Collection
<
String
>
getQueryAssistedColumn
(
final
InsertStatement
insertStatement
)
{
Collection
<
String
>
result
=
new
LinkedList
<>();
for
(
String
each
:
insertStatement
.
getColumnNames
())
{
Optional
<
String
>
assistedColumnName
=
encryptRule
.
getEncryptorEngine
().
getAssistedQueryColumn
(
insertStatement
.
getTables
().
getSingleTableName
(),
each
);
if
(
assistedColumnName
.
isPresent
())
{
result
.
add
(
assistedColumnName
.
get
());
}
}
return
result
;
}
private
void
fillUpdate
(
final
SetAssignmentsSegment
sqlSegment
,
final
UpdateStatement
updateStatement
)
{
private
void
fillUpdate
(
final
SetAssignmentsSegment
sqlSegment
,
final
UpdateStatement
updateStatement
)
{
String
tableName
=
updateStatement
.
getTables
().
getSingleTableName
();
String
tableName
=
updateStatement
.
getTables
().
getSingleTableName
();
for
(
AssignmentSegment
each
:
sqlSegment
.
getAssignments
())
{
for
(
AssignmentSegment
each
:
sqlSegment
.
getAssignments
())
{
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/encrypt/dml/insert/EncryptInsertValuesFiller.java
浏览文件 @
ce7e1f18
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
org.apache.shardingsphere.core.parse.filler.encrypt.dml.insert
;
package
org.apache.shardingsphere.core.parse.filler.encrypt.dml.insert
;
import
com.google.common.base.Optional
;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.core.parse.filler.api.EncryptRuleAwareFiller
;
import
org.apache.shardingsphere.core.parse.filler.api.EncryptRuleAwareFiller
;
import
org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller
;
import
org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller
;
...
@@ -25,7 +24,6 @@ import org.apache.shardingsphere.core.parse.sql.context.insertvalue.InsertValue;
...
@@ -25,7 +24,6 @@ import org.apache.shardingsphere.core.parse.sql.context.insertvalue.InsertValue;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.InsertValuesSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.InsertValuesSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertValuesToken
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -53,7 +51,6 @@ public final class EncryptInsertValuesFiller implements SQLSegmentFiller<InsertV
...
@@ -53,7 +51,6 @@ public final class EncryptInsertValuesFiller implements SQLSegmentFiller<InsertV
private
void
reviseInsertStatement
(
final
InsertStatement
insertStatement
,
final
InsertValuesSegment
sqlSegment
)
{
private
void
reviseInsertStatement
(
final
InsertStatement
insertStatement
,
final
InsertValuesSegment
sqlSegment
)
{
reviseInsertColumnNames
(
insertStatement
);
reviseInsertColumnNames
(
insertStatement
);
setNeededToAppendAssistedColumns
(
insertStatement
);
setNeededToAppendAssistedColumns
(
insertStatement
);
fillWithInsertValuesToken
(
insertStatement
,
sqlSegment
);
}
}
...
@@ -67,16 +64,4 @@ public final class EncryptInsertValuesFiller implements SQLSegmentFiller<InsertV
...
@@ -67,16 +64,4 @@ public final class EncryptInsertValuesFiller implements SQLSegmentFiller<InsertV
insertStatement
.
setNeededToAppendAssistedColumns
(
true
);
insertStatement
.
setNeededToAppendAssistedColumns
(
true
);
}
}
}
}
private
void
fillWithInsertValuesToken
(
final
InsertStatement
insertStatement
,
final
InsertValuesSegment
sqlSegment
)
{
Optional
<
InsertValuesToken
>
insertValuesToken
=
insertStatement
.
findSQLToken
(
InsertValuesToken
.
class
);
if
(
insertValuesToken
.
isPresent
())
{
int
startIndex
=
insertValuesToken
.
get
().
getStartIndex
()
<
sqlSegment
.
getStartIndex
()
?
insertValuesToken
.
get
().
getStartIndex
()
:
sqlSegment
.
getStartIndex
();
int
stopIndex
=
insertValuesToken
.
get
().
getStopIndex
()
>
sqlSegment
.
getStopIndex
()
?
insertValuesToken
.
get
().
getStopIndex
()
:
sqlSegment
.
getStopIndex
();
insertStatement
.
getSQLTokens
().
remove
(
insertValuesToken
.
get
());
insertStatement
.
getSQLTokens
().
add
(
new
InsertValuesToken
(
startIndex
,
stopIndex
));
}
else
{
insertStatement
.
getSQLTokens
().
add
(
new
InsertValuesToken
(
sqlSegment
.
getStartIndex
(),
sqlSegment
.
getStopIndex
()));
}
}
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/sharding/dml/insert/ShardingInsertValuesFiller.java
浏览文件 @
ce7e1f18
...
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.SimpleEx
...
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.SimpleEx
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertValuesToken
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -87,7 +86,6 @@ public final class ShardingInsertValuesFiller implements SQLSegmentFiller<Insert
...
@@ -87,7 +86,6 @@ public final class ShardingInsertValuesFiller implements SQLSegmentFiller<Insert
reviseInsertColumnNames
(
insertStatement
,
sqlSegment
);
reviseInsertColumnNames
(
insertStatement
,
sqlSegment
);
setNeededToAppendGeneratedKey
(
insertStatement
);
setNeededToAppendGeneratedKey
(
insertStatement
);
setNeededToAppendAssistedColumns
(
insertStatement
);
setNeededToAppendAssistedColumns
(
insertStatement
);
fillWithInsertValuesToken
(
insertStatement
,
sqlSegment
);
}
}
private
void
reviseInsertColumnNames
(
final
InsertStatement
insertStatement
,
final
InsertValuesSegment
sqlSegment
)
{
private
void
reviseInsertColumnNames
(
final
InsertStatement
insertStatement
,
final
InsertValuesSegment
sqlSegment
)
{
...
@@ -123,16 +121,4 @@ public final class ShardingInsertValuesFiller implements SQLSegmentFiller<Insert
...
@@ -123,16 +121,4 @@ public final class ShardingInsertValuesFiller implements SQLSegmentFiller<Insert
}
}
return
result
;
return
result
;
}
}
private
void
fillWithInsertValuesToken
(
final
InsertStatement
insertStatement
,
final
InsertValuesSegment
sqlSegment
)
{
Optional
<
InsertValuesToken
>
insertValuesToken
=
insertStatement
.
findSQLToken
(
InsertValuesToken
.
class
);
if
(
insertValuesToken
.
isPresent
())
{
int
startIndex
=
insertValuesToken
.
get
().
getStartIndex
()
<
sqlSegment
.
getStartIndex
()
?
insertValuesToken
.
get
().
getStartIndex
()
:
sqlSegment
.
getStartIndex
();
int
stopIndex
=
insertValuesToken
.
get
().
getStopIndex
()
>
sqlSegment
.
getStopIndex
()
?
insertValuesToken
.
get
().
getStopIndex
()
:
sqlSegment
.
getStopIndex
();
insertStatement
.
getSQLTokens
().
remove
(
insertValuesToken
.
get
());
insertStatement
.
getSQLTokens
().
add
(
new
InsertValuesToken
(
startIndex
,
stopIndex
));
}
else
{
insertStatement
.
getSQLTokens
().
add
(
new
InsertValuesToken
(
sqlSegment
.
getStartIndex
(),
sqlSegment
.
getStopIndex
()));
}
}
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/sharding/dml/update/ShardingSetAssignmentsFiller.java
浏览文件 @
ce7e1f18
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
org.apache.shardingsphere.core.parse.filler.sharding.dml.update
;
package
org.apache.shardingsphere.core.parse.filler.sharding.dml.update
;
import
com.google.common.base.Optional
;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData
;
import
org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData
;
import
org.apache.shardingsphere.core.parse.exception.SQLParsingException
;
import
org.apache.shardingsphere.core.parse.exception.SQLParsingException
;
...
@@ -31,19 +30,13 @@ import org.apache.shardingsphere.core.parse.sql.context.insertvalue.InsertValue;
...
@@ -31,19 +30,13 @@ import org.apache.shardingsphere.core.parse.sql.context.insertvalue.InsertValue;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.SimpleExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.SimpleExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertSetAddItemsToken
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertSetEncryptValueToken
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.spi.encrypt.ShardingEncryptor
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -86,50 +79,11 @@ public final class ShardingSetAssignmentsFiller implements SQLSegmentFiller<SetA
...
@@ -86,50 +79,11 @@ public final class ShardingSetAssignmentsFiller implements SQLSegmentFiller<SetA
fillShardingCondition
(
andCondition
,
columnNames
.
next
(),
insertStatement
.
getTables
().
getSingleTableName
(),
null
,
(
SimpleExpressionSegment
)
each
.
getValue
());
fillShardingCondition
(
andCondition
,
columnNames
.
next
(),
insertStatement
.
getTables
().
getSingleTableName
(),
null
,
(
SimpleExpressionSegment
)
each
.
getValue
());
}
}
columnValues
.
add
(
each
.
getValue
());
columnValues
.
add
(
each
.
getValue
());
fillWithInsertSetEncryptValueToken
(
insertStatement
,
each
,
each
.
getValue
());
}
}
InsertValue
insertValue
=
new
InsertValue
(
columnValues
);
InsertValue
insertValue
=
new
InsertValue
(
columnValues
);
insertStatement
.
getValues
().
add
(
insertValue
);
insertStatement
.
getValues
().
add
(
insertValue
);
insertStatement
.
getRouteCondition
().
getOrConditions
().
add
(
andCondition
);
insertStatement
.
getRouteCondition
().
getOrConditions
().
add
(
andCondition
);
insertStatement
.
setParametersIndex
(
insertValue
.
getParametersCount
());
insertStatement
.
setParametersIndex
(
insertValue
.
getParametersCount
());
fillWithInsertSetAddItemsToken
(
insertStatement
,
sqlSegment
);
}
private
void
fillWithInsertSetEncryptValueToken
(
final
InsertStatement
insertStatement
,
final
AssignmentSegment
segment
,
final
ExpressionSegment
expressionSegment
)
{
Optional
<
ShardingEncryptor
>
shardingEncryptor
=
shardingRule
.
getEncryptRule
().
getEncryptorEngine
().
getShardingEncryptor
(
insertStatement
.
getTables
().
getSingleTableName
(),
segment
.
getColumn
().
getName
());
if
(
shardingEncryptor
.
isPresent
()
&&
!(
expressionSegment
instanceof
ParameterMarkerExpressionSegment
))
{
insertStatement
.
getSQLTokens
().
add
(
new
InsertSetEncryptValueToken
(
segment
.
getValue
().
getStartIndex
(),
segment
.
getValue
().
getStopIndex
(),
segment
.
getColumn
().
getName
()));
}
}
private
void
fillWithInsertSetAddItemsToken
(
final
InsertStatement
insertStatement
,
final
SetAssignmentsSegment
sqlSegment
)
{
Collection
<
String
>
columnNames
=
getQueryAssistedColumn
(
insertStatement
);
if
(
getGeneratedKeyColumn
(
insertStatement
).
isPresent
())
{
columnNames
.
add
(
getGeneratedKeyColumn
(
insertStatement
).
get
());
}
if
(
columnNames
.
isEmpty
())
{
return
;
}
List
<
AssignmentSegment
>
assignments
=
new
ArrayList
<>(
sqlSegment
.
getAssignments
());
insertStatement
.
getSQLTokens
().
add
(
new
InsertSetAddItemsToken
(
assignments
.
get
(
assignments
.
size
()
-
1
).
getStopIndex
()
+
1
,
columnNames
));
}
private
Optional
<
String
>
getGeneratedKeyColumn
(
final
InsertStatement
insertStatement
)
{
String
tableName
=
insertStatement
.
getTables
().
getSingleTableName
();
Optional
<
String
>
generateKeyColumn
=
shardingRule
.
findGenerateKeyColumnName
(
tableName
);
return
generateKeyColumn
.
isPresent
()
&&
!
insertStatement
.
getColumnNames
().
contains
(
generateKeyColumn
.
get
())
?
generateKeyColumn
:
Optional
.<
String
>
absent
();
}
private
Collection
<
String
>
getQueryAssistedColumn
(
final
InsertStatement
insertStatement
)
{
Collection
<
String
>
result
=
new
LinkedList
<>();
for
(
String
each
:
insertStatement
.
getColumnNames
())
{
Optional
<
String
>
assistedColumnName
=
shardingRule
.
getEncryptRule
().
getEncryptorEngine
().
getAssistedQueryColumn
(
insertStatement
.
getTables
().
getSingleTableName
(),
each
);
if
(
assistedColumnName
.
isPresent
())
{
result
.
add
(
assistedColumnName
.
get
());
}
}
return
result
;
}
}
private
int
getColumnCountExcludeAssistedQueryColumns
(
final
InsertStatement
insertStatement
)
{
private
int
getColumnCountExcludeAssistedQueryColumns
(
final
InsertStatement
insertStatement
)
{
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/AbstractSQLStatement.java
浏览文件 @
ce7e1f18
...
@@ -68,17 +68,6 @@ public abstract class AbstractSQLStatement implements SQLStatement {
...
@@ -68,17 +68,6 @@ public abstract class AbstractSQLStatement implements SQLStatement {
sqlTokens
.
add
(
sqlToken
);
sqlTokens
.
add
(
sqlToken
);
}
}
@Override
@SuppressWarnings
(
"unchecked"
)
public
final
<
T
extends
SQLToken
>
Optional
<
T
>
findSQLToken
(
final
Class
<
T
>
sqlTokenType
)
{
for
(
SQLToken
each
:
sqlTokens
)
{
if
(
each
.
getClass
().
equals
(
sqlTokenType
))
{
return
Optional
.
of
((
T
)
each
);
}
}
return
Optional
.
absent
();
}
@Override
@Override
public
final
List
<
SQLToken
>
getSQLTokens
()
{
public
final
List
<
SQLToken
>
getSQLTokens
()
{
Collections
.
sort
(
sqlTokens
);
Collections
.
sort
(
sqlTokens
);
...
@@ -95,4 +84,16 @@ public abstract class AbstractSQLStatement implements SQLStatement {
...
@@ -95,4 +84,16 @@ public abstract class AbstractSQLStatement implements SQLStatement {
}
}
return
Optional
.
absent
();
return
Optional
.
absent
();
}
}
@Override
@SuppressWarnings
(
"unchecked"
)
public
final
<
T
extends
SQLSegment
>
Collection
<
T
>
findSQLSegments
(
final
Class
<
T
>
sqlSegmentType
)
{
Collection
<
T
>
result
=
new
LinkedList
<>();
for
(
SQLSegment
each
:
sqlSegments
)
{
if
(
each
.
getClass
().
equals
(
sqlSegmentType
))
{
result
.
add
((
T
)
each
);
}
}
return
result
;
}
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/SQLStatement.java
浏览文件 @
ce7e1f18
...
@@ -76,15 +76,6 @@ public interface SQLStatement {
...
@@ -76,15 +76,6 @@ public interface SQLStatement {
*/
*/
void
addSQLToken
(
SQLToken
sqlToken
);
void
addSQLToken
(
SQLToken
sqlToken
);
/**
* Find SQL token.
*
* @param sqlTokenType SQL token type
* @param <T> type of SQL token
* @return SQL token
*/
<
T
extends
SQLToken
>
Optional
<
T
>
findSQLToken
(
Class
<
T
>
sqlTokenType
);
/**
/**
* Get SQL tokens.
* Get SQL tokens.
*
*
...
@@ -128,4 +119,13 @@ public interface SQLStatement {
...
@@ -128,4 +119,13 @@ public interface SQLStatement {
* @return SQL segment
* @return SQL segment
*/
*/
<
T
extends
SQLSegment
>
Optional
<
T
>
findSQLSegment
(
Class
<
T
>
sqlSegmentType
);
<
T
extends
SQLSegment
>
Optional
<
T
>
findSQLSegment
(
Class
<
T
>
sqlSegmentType
);
/**
* Find SQL segment.
*
* @param sqlSegmentType SQL segment type
* @param <T> type of SQL segment
* @return SQL segments
*/
<
T
extends
SQLSegment
>
Collection
<
T
>
findSQLSegments
(
Class
<
T
>
sqlSegmentType
);
}
}
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java
浏览文件 @
ce7e1f18
...
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.core.parse.integrate.asserts.meta.TableMetaData
...
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.core.parse.integrate.asserts.meta.TableMetaData
import
org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.TableAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.TableAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.token.TokenAssert
;
import
org.apache.shardingsphere.core.parse.integrate.jaxb.root.ParserResult
;
import
org.apache.shardingsphere.core.parse.integrate.jaxb.root.ParserResult
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.ddl.AlterTableStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.ddl.AlterTableStatement
;
...
@@ -54,8 +53,6 @@ public final class SQLStatementAssert {
...
@@ -54,8 +53,6 @@ public final class SQLStatementAssert {
private
final
ConditionAssert
conditionAssert
;
private
final
ConditionAssert
conditionAssert
;
private
final
TokenAssert
tokenAssert
;
private
final
IndexAssert
indexAssert
;
private
final
IndexAssert
indexAssert
;
private
final
ItemAssert
itemAssert
;
private
final
ItemAssert
itemAssert
;
...
@@ -83,7 +80,6 @@ public final class SQLStatementAssert {
...
@@ -83,7 +80,6 @@ public final class SQLStatementAssert {
expected
=
parserResultSetLoader
.
getParserResult
(
sqlCaseId
);
expected
=
parserResultSetLoader
.
getParserResult
(
sqlCaseId
);
tableAssert
=
new
TableAssert
(
assertMessage
);
tableAssert
=
new
TableAssert
(
assertMessage
);
conditionAssert
=
new
ConditionAssert
(
assertMessage
);
conditionAssert
=
new
ConditionAssert
(
assertMessage
);
tokenAssert
=
new
TokenAssert
(
sqlCaseType
,
assertMessage
);
indexAssert
=
new
IndexAssert
(
sqlCaseType
,
assertMessage
);
indexAssert
=
new
IndexAssert
(
sqlCaseType
,
assertMessage
);
itemAssert
=
new
ItemAssert
(
assertMessage
);
itemAssert
=
new
ItemAssert
(
assertMessage
);
groupByAssert
=
new
GroupByAssert
(
assertMessage
);
groupByAssert
=
new
GroupByAssert
(
assertMessage
);
...
@@ -103,7 +99,6 @@ public final class SQLStatementAssert {
...
@@ -103,7 +99,6 @@ public final class SQLStatementAssert {
if
(
"MySQL"
.
equals
(
databaseType
))
{
if
(
"MySQL"
.
equals
(
databaseType
))
{
conditionAssert
.
assertConditions
(
actual
.
getEncryptCondition
(),
expected
.
getEncryptCondition
());
conditionAssert
.
assertConditions
(
actual
.
getEncryptCondition
(),
expected
.
getEncryptCondition
());
}
}
tokenAssert
.
assertTokens
(
actual
.
getSQLTokens
(),
expected
.
getTokens
());
indexAssert
.
assertParametersIndex
(
actual
.
getParametersIndex
(),
expected
.
getParameters
().
size
());
indexAssert
.
assertParametersIndex
(
actual
.
getParametersIndex
(),
expected
.
getParameters
().
size
());
if
(
actual
instanceof
SelectStatement
)
{
if
(
actual
instanceof
SelectStatement
)
{
assertSelectStatement
((
SelectStatement
)
actual
);
assertSelectStatement
((
SelectStatement
)
actual
);
...
...
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/token/InsertValuesTokenAssert.java
已删除
100644 → 0
浏览文件 @
2f145397
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.parse.integrate.asserts.token
;
import
com.google.common.base.Optional
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage
;
import
org.apache.shardingsphere.core.parse.integrate.jaxb.token.ExpectedInsertValuesToken
;
import
org.apache.shardingsphere.core.parse.integrate.jaxb.token.ExpectedTokens
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertValuesToken
;
import
java.util.Collection
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Multiple insert values token assert.
*
* @author maxiaoguang
*/
@RequiredArgsConstructor
final
class
InsertValuesTokenAssert
{
private
final
SQLStatementAssertMessage
assertMessage
;
void
assertInsertValuesToken
(
final
Collection
<
SQLToken
>
actual
,
final
ExpectedTokens
expected
)
{
Optional
<
InsertValuesToken
>
insertValuesToken
=
getInsertValuesToken
(
actual
);
if
(
insertValuesToken
.
isPresent
())
{
assertInsertValuesToken
(
insertValuesToken
.
get
(),
expected
.
getInsertValuesToken
());
}
else
{
assertNull
(
assertMessage
.
getFullAssertMessage
(
"Insert values token should not exist: "
),
expected
.
getInsertValuesToken
());
}
}
private
void
assertInsertValuesToken
(
final
InsertValuesToken
actual
,
final
ExpectedInsertValuesToken
expected
)
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"Insert values token begin position assertion error: "
),
actual
.
getStartIndex
(),
is
(
expected
.
getBeginPosition
()));
}
private
Optional
<
InsertValuesToken
>
getInsertValuesToken
(
final
Collection
<
SQLToken
>
actual
)
{
for
(
SQLToken
each
:
actual
)
{
if
(
each
instanceof
InsertValuesToken
)
{
return
Optional
.
of
((
InsertValuesToken
)
each
);
}
}
return
Optional
.
absent
();
}
}
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/jaxb/token/ExpectedInsertValuesToken.java
已删除
100644 → 0
浏览文件 @
2f145397
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.parse.integrate.jaxb.token
;
import
lombok.Getter
;
import
lombok.Setter
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlAttribute
;
@Getter
@Setter
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
final
class
ExpectedInsertValuesToken
{
@XmlAttribute
(
name
=
"begin-position"
)
private
int
beginPosition
;
}
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/jaxb/token/ExpectedTokens.java
浏览文件 @
ce7e1f18
...
@@ -40,9 +40,6 @@ public final class ExpectedTokens {
...
@@ -40,9 +40,6 @@ public final class ExpectedTokens {
@XmlElement
(
name
=
"generated-key-token"
)
@XmlElement
(
name
=
"generated-key-token"
)
private
ExpectedGeneratedKeyToken
generatedKeyToken
;
private
ExpectedGeneratedKeyToken
generatedKeyToken
;
@XmlElement
(
name
=
"insert-values-token"
)
private
ExpectedInsertValuesToken
insertValuesToken
;
@XmlElement
(
name
=
"insert-set-token"
)
@XmlElement
(
name
=
"insert-set-token"
)
private
ExpectedInsertSetToken
insertSetToken
;
private
ExpectedInsertSetToken
insertSetToken
;
...
...
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/resources/parser/dml/insert.xml
浏览文件 @
ce7e1f18
...
@@ -23,7 +23,6 @@
...
@@ -23,7 +23,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -43,7 +42,6 @@
...
@@ -43,7 +42,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"67"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -63,7 +61,6 @@
...
@@ -63,7 +61,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -83,7 +80,6 @@
...
@@ -83,7 +80,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -111,7 +107,6 @@
...
@@ -111,7 +107,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
left-delimiter=
"`"
right-delimiter=
"`"
length=
"9"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
left-delimiter=
"`"
right-delimiter=
"`"
length=
"9"
/>
<insert-values-token
begin-position=
"63"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -131,7 +126,6 @@
...
@@ -131,7 +126,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"33"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"33"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"76"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -154,7 +148,6 @@
...
@@ -154,7 +148,6 @@
<table-token
start-index=
"21"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"21"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"39"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"39"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"56"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"56"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"79"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -174,7 +167,6 @@
...
@@ -174,7 +167,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"27"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -214,7 +206,6 @@
...
@@ -214,7 +206,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -254,7 +245,6 @@
...
@@ -254,7 +245,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<insert-values-token
begin-position=
"83"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -277,7 +267,6 @@
...
@@ -277,7 +267,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<insert-values-token
begin-position=
"74"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -340,7 +329,6 @@
...
@@ -340,7 +329,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -386,7 +374,6 @@
...
@@ -386,7 +374,6 @@
<!--<table-token start-index="21" table-name="t_order" length="7" />-->
<!--<table-token start-index="21" table-name="t_order" length="7" />-->
<!--<table-token start-index="39" table-name="t_order" length="7" />-->
<!--<table-token start-index="39" table-name="t_order" length="7" />-->
<!--<table-token start-index="56" table-name="t_order" length="7" />-->
<!--<table-token start-index="56" table-name="t_order" length="7" />-->
<!--<insert-values-token begin-position="79" table-name="t_order"/>-->
<!--<table-token start-index="113" table-name="t_order" length="7" />-->
<!--<table-token start-index="113" table-name="t_order" length="7" />-->
<!--<table-token start-index="137" table-name="t_order" length="7" />-->
<!--<table-token start-index="137" table-name="t_order" length="7" />-->
<!--</tokens>-->
<!--</tokens>-->
...
@@ -408,7 +395,6 @@
...
@@ -408,7 +395,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -436,7 +422,6 @@
...
@@ -436,7 +422,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_order"
length=
"7"
/>
<insert-values-token
begin-position=
"55"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -464,7 +449,6 @@
...
@@ -464,7 +449,6 @@
<!--</tables>-->
<!--</tables>-->
<!--<tokens>-->
<!--<tokens>-->
<!--<table-token start-index="12" table-name="t_order" length="7" />-->
<!--<table-token start-index="12" table-name="t_order" length="7" />-->
<!--<insert-values-token begin-position="55" table-name="t_order"/>-->
<!--</tokens>-->
<!--</tokens>-->
<!--<or-condition>-->
<!--<or-condition>-->
<!--<and-condition>-->
<!--<and-condition>-->
...
@@ -492,7 +476,6 @@
...
@@ -492,7 +476,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<insert-values-token
begin-position=
"83"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -526,7 +509,6 @@
...
@@ -526,7 +509,6 @@
<!--</tables>-->
<!--</tables>-->
<!--<tokens>-->
<!--<tokens>-->
<!--<table-token start-index="12" table-name="t_order_item" length="12" />-->
<!--<table-token start-index="12" table-name="t_order_item" length="12" />-->
<!--<insert-values-token begin-position="74" table-name="t_order_item"/>-->
<!--</tokens>-->
<!--</tokens>-->
<!--<or-condition>-->
<!--<or-condition>-->
<!--<and-condition>-->
<!--<and-condition>-->
...
@@ -554,7 +536,6 @@
...
@@ -554,7 +536,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_place"
length=
"7"
/>
<table-token
start-index=
"12"
table-name=
"t_place"
length=
"7"
/>
<insert-values-token
begin-position=
"64"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -574,7 +555,6 @@
...
@@ -574,7 +555,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<insert-values-token
begin-position=
"31"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -597,7 +577,6 @@
...
@@ -597,7 +577,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<table-token
start-index=
"12"
table-name=
"t_order_item"
length=
"12"
/>
<insert-values-token
begin-position=
"31"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition>
<and-condition>
...
@@ -627,7 +606,6 @@
...
@@ -627,7 +606,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_auto_increment_table"
length=
"22"
/>
<table-token
start-index=
"12"
table-name=
"t_auto_increment_table"
length=
"22"
/>
<insert-values-token
begin-position=
"41"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition/>
<and-condition/>
...
@@ -639,7 +617,6 @@
...
@@ -639,7 +617,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_double_test"
length=
"13"
/>
<table-token
start-index=
"12"
table-name=
"t_double_test"
length=
"13"
/>
<insert-values-token
begin-position=
"38"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition/>
<and-condition/>
...
@@ -652,7 +629,6 @@
...
@@ -652,7 +629,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_null_value_test"
length=
"17"
/>
<table-token
start-index=
"12"
table-name=
"t_null_value_test"
length=
"17"
/>
<insert-values-token
begin-position=
"42"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition/>
<and-condition/>
...
@@ -665,7 +641,6 @@
...
@@ -665,7 +641,6 @@
</tables>
</tables>
<tokens>
<tokens>
<table-token
start-index=
"12"
table-name=
"t_blob_value_test"
length=
"17"
/>
<table-token
start-index=
"12"
table-name=
"t_blob_value_test"
length=
"17"
/>
<insert-values-token
begin-position=
"42"
/>
</tokens>
</tokens>
<or-condition>
<or-condition>
<and-condition/>
<and-condition/>
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/placeholder/InsertSetAddGeneratedKeyPlaceholder.java
0 → 100644
浏览文件 @
ce7e1f18
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.rewrite.placeholder
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.complex.ComplexExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
/**
* Insert set add items placeholder for rewrite.
*
* @author panjuan
*/
@RequiredArgsConstructor
public
final
class
InsertSetAddGeneratedKeyPlaceholder
implements
ShardingPlaceholder
{
private
final
String
columnName
;
private
final
ExpressionSegment
columnValue
;
@Override
public
String
toString
()
{
return
String
.
format
(
", %s = %s"
,
columnName
,
getColumnValue
());
}
private
String
getColumnValue
()
{
if
(
columnValue
instanceof
ParameterMarkerExpressionSegment
)
{
return
"?"
;
}
else
if
(
columnValue
instanceof
LiteralExpressionSegment
)
{
Object
literals
=
((
LiteralExpressionSegment
)
columnValue
).
getLiterals
();
return
literals
instanceof
String
?
String
.
format
(
"'%s'"
,
literals
)
:
literals
.
toString
();
}
return
((
ComplexExpressionSegment
)
columnValue
).
getText
();
}
}
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/BaseSQLRewriter.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.rewriter;
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.rewriter;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.
parse.sql.token
.Substitutable
;
import
org.apache.shardingsphere.core.
rewrite.token.pojo
.Substitutable
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertColumnsToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertColumnsToken
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/EncryptSQLRewriter.java
浏览文件 @
ce7e1f18
...
@@ -31,9 +31,9 @@ import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
...
@@ -31,9 +31,9 @@ import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertAssistedColumnsToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertAssistedColumnsToken
;
import
org.apache.shardingsphere.core.
parse.sql.token.impl.InsertSetAddItem
sToken
;
import
org.apache.shardingsphere.core.
rewrite.token.pojo.InsertSetAddAssistedColumn
sToken
;
import
org.apache.shardingsphere.core.
parse.sql.token.impl
.InsertSetEncryptValueToken
;
import
org.apache.shardingsphere.core.
rewrite.token.pojo
.InsertSetEncryptValueToken
;
import
org.apache.shardingsphere.core.
parse.sql.token.impl
.InsertValuesToken
;
import
org.apache.shardingsphere.core.
rewrite.token.pojo
.InsertValuesToken
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.InsertAssistedColumnsPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.InsertAssistedColumnsPlaceholder
;
...
@@ -119,8 +119,8 @@ public final class EncryptSQLRewriter implements SQLRewriter {
...
@@ -119,8 +119,8 @@ public final class EncryptSQLRewriter implements SQLRewriter {
appendInsertValuesPlaceholder
(
sqlBuilder
,
insertOptimizeResult
);
appendInsertValuesPlaceholder
(
sqlBuilder
,
insertOptimizeResult
);
}
else
if
(
sqlToken
instanceof
InsertSetEncryptValueToken
)
{
}
else
if
(
sqlToken
instanceof
InsertSetEncryptValueToken
)
{
appendInsertSetEncryptValuePlaceholder
(
sqlBuilder
,
(
InsertSetEncryptValueToken
)
sqlToken
,
insertOptimizeResult
);
appendInsertSetEncryptValuePlaceholder
(
sqlBuilder
,
(
InsertSetEncryptValueToken
)
sqlToken
,
insertOptimizeResult
);
}
else
if
(
sqlToken
instanceof
InsertSetAdd
Item
sToken
)
{
}
else
if
(
sqlToken
instanceof
InsertSetAdd
AssistedColumn
sToken
)
{
appendInsertSetAddItemsPlaceholder
(
sqlBuilder
,
(
InsertSetAdd
Item
sToken
)
sqlToken
,
insertOptimizeResult
);
appendInsertSetAddItemsPlaceholder
(
sqlBuilder
,
(
InsertSetAdd
AssistedColumn
sToken
)
sqlToken
,
insertOptimizeResult
);
}
else
if
(
sqlToken
instanceof
InsertAssistedColumnsToken
)
{
}
else
if
(
sqlToken
instanceof
InsertAssistedColumnsToken
)
{
appendInsertAssistedColumnsPlaceholder
(
sqlBuilder
,
(
InsertAssistedColumnsToken
)
sqlToken
);
appendInsertAssistedColumnsPlaceholder
(
sqlBuilder
,
(
InsertAssistedColumnsToken
)
sqlToken
);
}
else
if
(
sqlToken
instanceof
EncryptColumnToken
)
{
}
else
if
(
sqlToken
instanceof
EncryptColumnToken
)
{
...
@@ -140,12 +140,12 @@ public final class EncryptSQLRewriter implements SQLRewriter {
...
@@ -140,12 +140,12 @@ public final class EncryptSQLRewriter implements SQLRewriter {
sqlBuilder
.
appendPlaceholder
(
new
InsertSetEncryptValuePlaceholder
(
insertOptimizeResult
.
getUnits
().
get
(
0
).
getColumnSQLExpression
(
insertSetEncryptValueToken
.
getColumnName
())));
sqlBuilder
.
appendPlaceholder
(
new
InsertSetEncryptValuePlaceholder
(
insertOptimizeResult
.
getUnits
().
get
(
0
).
getColumnSQLExpression
(
insertSetEncryptValueToken
.
getColumnName
())));
}
}
private
void
appendInsertSetAddItemsPlaceholder
(
final
SQLBuilder
sqlBuilder
,
final
InsertSetAdd
ItemsToken
insertSetAddItem
sToken
,
final
InsertOptimizeResult
insertOptimizeResult
)
{
private
void
appendInsertSetAddItemsPlaceholder
(
final
SQLBuilder
sqlBuilder
,
final
InsertSetAdd
AssistedColumnsToken
insertSetAddAssistedColumn
sToken
,
final
InsertOptimizeResult
insertOptimizeResult
)
{
List
<
ExpressionSegment
>
columnValues
=
new
LinkedList
<>();
List
<
ExpressionSegment
>
columnValues
=
new
LinkedList
<>();
for
(
String
each
:
insertSetAdd
Item
sToken
.
getColumnNames
())
{
for
(
String
each
:
insertSetAdd
AssistedColumn
sToken
.
getColumnNames
())
{
columnValues
.
add
(
insertOptimizeResult
.
getUnits
().
get
(
0
).
getColumnSQLExpression
(
each
));
columnValues
.
add
(
insertOptimizeResult
.
getUnits
().
get
(
0
).
getColumnSQLExpression
(
each
));
}
}
sqlBuilder
.
appendPlaceholder
(
new
InsertSetAddItemsPlaceholder
(
new
LinkedList
<>(
insertSetAdd
Item
sToken
.
getColumnNames
()),
columnValues
));
sqlBuilder
.
appendPlaceholder
(
new
InsertSetAddItemsPlaceholder
(
new
LinkedList
<>(
insertSetAdd
AssistedColumn
sToken
.
getColumnNames
()),
columnValues
));
}
}
private
void
appendInsertAssistedColumnsPlaceholder
(
final
SQLBuilder
sqlBuilder
,
final
InsertAssistedColumnsToken
insertAssistedColumnsToken
)
{
private
void
appendInsertAssistedColumnsPlaceholder
(
final
SQLBuilder
sqlBuilder
,
final
InsertAssistedColumnsToken
insertAssistedColumnsToken
)
{
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriter.java
浏览文件 @
ce7e1f18
...
@@ -17,21 +17,22 @@
...
@@ -17,21 +17,22 @@
package
org.apache.shardingsphere.core.rewrite.rewriter
;
package
org.apache.shardingsphere.core.rewrite.rewriter
;
import
com.google.common.base.Optional
;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.constant.DatabaseType
;
import
org.apache.shardingsphere.core.constant.DatabaseType
;
import
org.apache.shardingsphere.core.optimize.result.OptimizeResult
;
import
org.apache.shardingsphere.core.optimize.result.insert.InsertOptimizeResult
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.TextOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.TextOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertGeneratedKeyToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertSetAddGeneratedKeyToken
;
import
org.apache.shardingsphere.core.rewrite.placeholder.InsertGeneratedKeyPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OffsetToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.RowCountToken
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.AggregationDistinctPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.AggregationDistinctPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.IndexPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.IndexPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.InsertGeneratedKeyPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.InsertSetAddGeneratedKeyPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.LimitOffsetPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.LimitOffsetPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.LimitRowCountPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.LimitRowCountPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.OrderByPlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.OrderByPlaceholder
;
...
@@ -40,7 +41,10 @@ import org.apache.shardingsphere.core.rewrite.placeholder.SelectItemsPlaceholder
...
@@ -40,7 +41,10 @@ import org.apache.shardingsphere.core.rewrite.placeholder.SelectItemsPlaceholder
import
org.apache.shardingsphere.core.rewrite.placeholder.TablePlaceholder
;
import
org.apache.shardingsphere.core.rewrite.placeholder.TablePlaceholder
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.AggregationDistinctToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.AggregationDistinctToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.IndexToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.IndexToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertGeneratedKeyToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OffsetToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OrderByToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OrderByToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.RowCountToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.SelectItemPrefixToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.SelectItemPrefixToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.SelectItemsToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.SelectItemsToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.TableToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.TableToken
;
...
@@ -55,7 +59,6 @@ import org.apache.shardingsphere.core.rule.ShardingRule;
...
@@ -55,7 +59,6 @@ import org.apache.shardingsphere.core.rule.ShardingRule;
* @author maxiaoguang
* @author maxiaoguang
* @author panjuan
* @author panjuan
*/
*/
@RequiredArgsConstructor
public
final
class
ShardingSQLRewriter
implements
SQLRewriter
{
public
final
class
ShardingSQLRewriter
implements
SQLRewriter
{
private
final
ShardingRule
shardingRule
;
private
final
ShardingRule
shardingRule
;
...
@@ -64,6 +67,26 @@ public final class ShardingSQLRewriter implements SQLRewriter {
...
@@ -64,6 +67,26 @@ public final class ShardingSQLRewriter implements SQLRewriter {
private
final
SQLRouteResult
sqlRouteResult
;
private
final
SQLRouteResult
sqlRouteResult
;
private
final
InsertOptimizeResult
insertOptimizeResult
;
public
ShardingSQLRewriter
(
final
ShardingRule
shardingRule
,
final
DatabaseType
databaseType
,
final
SQLRouteResult
sqlRouteResult
,
final
OptimizeResult
optimizeResult
)
{
this
.
shardingRule
=
shardingRule
;
this
.
databaseType
=
databaseType
;
this
.
sqlRouteResult
=
sqlRouteResult
;
this
.
insertOptimizeResult
=
getInsertOptimizeResult
(
optimizeResult
);
}
private
InsertOptimizeResult
getInsertOptimizeResult
(
final
OptimizeResult
optimizeResult
)
{
if
(
null
==
optimizeResult
)
{
return
null
;
}
Optional
<
InsertOptimizeResult
>
insertOptimizeResult
=
optimizeResult
.
getInsertOptimizeResult
();
if
(!
insertOptimizeResult
.
isPresent
())
{
return
null
;
}
return
insertOptimizeResult
.
get
();
}
@Override
@Override
public
void
rewrite
(
final
SQLBuilder
sqlBuilder
,
final
ParameterBuilder
parameterBuilder
,
final
SQLToken
sqlToken
)
{
public
void
rewrite
(
final
SQLBuilder
sqlBuilder
,
final
ParameterBuilder
parameterBuilder
,
final
SQLToken
sqlToken
)
{
if
(
sqlToken
instanceof
SelectItemPrefixToken
)
{
if
(
sqlToken
instanceof
SelectItemPrefixToken
)
{
...
@@ -84,6 +107,8 @@ public final class ShardingSQLRewriter implements SQLRewriter {
...
@@ -84,6 +107,8 @@ public final class ShardingSQLRewriter implements SQLRewriter {
appendAggregationDistinctPlaceholder
(
sqlBuilder
,
(
AggregationDistinctToken
)
sqlToken
);
appendAggregationDistinctPlaceholder
(
sqlBuilder
,
(
AggregationDistinctToken
)
sqlToken
);
}
else
if
(
sqlToken
instanceof
InsertGeneratedKeyToken
)
{
}
else
if
(
sqlToken
instanceof
InsertGeneratedKeyToken
)
{
appendInsertGeneratedKeyPlaceholder
(
sqlBuilder
,
(
InsertGeneratedKeyToken
)
sqlToken
);
appendInsertGeneratedKeyPlaceholder
(
sqlBuilder
,
(
InsertGeneratedKeyToken
)
sqlToken
);
}
else
if
(
sqlToken
instanceof
InsertSetAddGeneratedKeyToken
)
{
appendInsertSetAddGeneratedKeyPlaceholder
(
sqlBuilder
,
(
InsertSetAddGeneratedKeyToken
)
sqlToken
,
insertOptimizeResult
);
}
}
}
}
...
@@ -161,6 +186,11 @@ public final class ShardingSQLRewriter implements SQLRewriter {
...
@@ -161,6 +186,11 @@ public final class ShardingSQLRewriter implements SQLRewriter {
sqlBuilder
.
appendPlaceholder
(
new
InsertGeneratedKeyPlaceholder
(
insertGeneratedKeyToken
.
getColumn
(),
insertGeneratedKeyToken
.
isToAddCloseParenthesis
()));
sqlBuilder
.
appendPlaceholder
(
new
InsertGeneratedKeyPlaceholder
(
insertGeneratedKeyToken
.
getColumn
(),
insertGeneratedKeyToken
.
isToAddCloseParenthesis
()));
}
}
private
void
appendInsertSetAddGeneratedKeyPlaceholder
(
final
SQLBuilder
sqlBuilder
,
final
InsertSetAddGeneratedKeyToken
insertSetAddGeneratedKeyToken
,
final
InsertOptimizeResult
insertOptimizeResult
)
{
String
columnName
=
insertSetAddGeneratedKeyToken
.
getColumnName
();
sqlBuilder
.
appendPlaceholder
(
new
InsertSetAddGeneratedKeyPlaceholder
(
columnName
,
insertOptimizeResult
.
getUnits
().
get
(
0
).
getColumnSQLExpression
(
columnName
)));
}
private
boolean
isRewrite
()
{
private
boolean
isRewrite
()
{
return
!
sqlRouteResult
.
getRoutingResult
().
isSingleRouting
();
return
!
sqlRouteResult
.
getRoutingResult
().
isSingleRouting
();
}
}
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/BaseTokenGenerateEngine.java
浏览文件 @
ce7e1f18
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
package
org.apache.shardingsphere.core.rewrite.token
;
package
org.apache.shardingsphere.core.rewrite.token
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertColumnsTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertColumnsTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertValuesTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.SQLTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.SQLTokenGenerator
;
import
org.apache.shardingsphere.core.rule.BaseRule
;
import
org.apache.shardingsphere.core.rule.BaseRule
;
...
@@ -35,6 +36,7 @@ public final class BaseTokenGenerateEngine extends SQLTokenGenerateEngine<BaseRu
...
@@ -35,6 +36,7 @@ public final class BaseTokenGenerateEngine extends SQLTokenGenerateEngine<BaseRu
static
{
static
{
SQL_TOKEN_GENERATORS
.
add
(
new
InsertColumnsTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertColumnsTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertValuesTokenGenerator
());
}
}
@Override
@Override
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/EncryptTokenGenerateEngine.java
浏览文件 @
ce7e1f18
...
@@ -19,6 +19,8 @@ package org.apache.shardingsphere.core.rewrite.token;
...
@@ -19,6 +19,8 @@ package org.apache.shardingsphere.core.rewrite.token;
import
org.apache.shardingsphere.core.rewrite.token.generator.EncryptColumnTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.EncryptColumnTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertAssistedColumnsTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertAssistedColumnsTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertSetAddAssistedColumnsTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertSetEncryptValueTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.SQLTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.SQLTokenGenerator
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
...
@@ -37,6 +39,8 @@ public final class EncryptTokenGenerateEngine extends SQLTokenGenerateEngine<Enc
...
@@ -37,6 +39,8 @@ public final class EncryptTokenGenerateEngine extends SQLTokenGenerateEngine<Enc
static
{
static
{
SQL_TOKEN_GENERATORS
.
add
(
new
EncryptColumnTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
EncryptColumnTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertAssistedColumnsTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertAssistedColumnsTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertSetEncryptValueTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertSetAddAssistedColumnsTokenGenerator
());
}
}
@Override
@Override
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/ShardingTokenGenerateEngine.java
浏览文件 @
ce7e1f18
...
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token;
...
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token;
import
org.apache.shardingsphere.core.rewrite.token.generator.AggregationDistinctTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.AggregationDistinctTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.IndexTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.IndexTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertGeneratedKeyTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertGeneratedKeyTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.InsertSetAddGeneratedKeyTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.OffsetTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.OffsetTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.OrderByTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.OrderByTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.RemoveTokenGenerator
;
import
org.apache.shardingsphere.core.rewrite.token.generator.RemoveTokenGenerator
;
...
@@ -53,6 +54,7 @@ public final class ShardingTokenGenerateEngine extends SQLTokenGenerateEngine<Sh
...
@@ -53,6 +54,7 @@ public final class ShardingTokenGenerateEngine extends SQLTokenGenerateEngine<Sh
SQL_TOKEN_GENERATORS
.
add
(
new
OffsetTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
OffsetTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
RowCountTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
RowCountTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertGeneratedKeyTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertGeneratedKeyTokenGenerator
());
SQL_TOKEN_GENERATORS
.
add
(
new
InsertSetAddGeneratedKeyTokenGenerator
());
}
}
@Override
@Override
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertSetAddAssistedColumnsTokenGenerator.java
0 → 100644
浏览文件 @
ce7e1f18
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertSetAddAssistedColumnsToken
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* Insert set add items token generator.
*
* @author panjuan
*/
public
final
class
InsertSetAddAssistedColumnsTokenGenerator
implements
OptionalSQLTokenGenerator
<
EncryptRule
>
{
@Override
public
Optional
<
InsertSetAddAssistedColumnsToken
>
generateSQLToken
(
final
SQLStatement
sqlStatement
,
final
EncryptRule
encryptRule
)
{
Optional
<
SetAssignmentsSegment
>
setAssignmentsSegment
=
sqlStatement
.
findSQLSegment
(
SetAssignmentsSegment
.
class
);
if
(!(
sqlStatement
instanceof
InsertStatement
&&
setAssignmentsSegment
.
isPresent
()))
{
return
Optional
.
absent
();
}
return
createInsertSetAddItemsToken
((
InsertStatement
)
sqlStatement
,
encryptRule
,
setAssignmentsSegment
.
get
());
}
private
Optional
<
InsertSetAddAssistedColumnsToken
>
createInsertSetAddItemsToken
(
final
InsertStatement
insertStatement
,
final
EncryptRule
encryptRule
,
final
SetAssignmentsSegment
segment
)
{
Collection
<
String
>
columnNames
=
getQueryAssistedColumn
(
insertStatement
,
encryptRule
);
if
(
columnNames
.
isEmpty
())
{
return
Optional
.
absent
();
}
List
<
AssignmentSegment
>
assignments
=
new
ArrayList
<>(
segment
.
getAssignments
());
return
Optional
.
of
(
new
InsertSetAddAssistedColumnsToken
(
assignments
.
get
(
assignments
.
size
()
-
1
).
getStopIndex
()
+
1
,
columnNames
));
}
private
Collection
<
String
>
getQueryAssistedColumn
(
final
InsertStatement
insertStatement
,
final
EncryptRule
encryptRule
)
{
Collection
<
String
>
result
=
new
LinkedList
<>();
for
(
String
each
:
insertStatement
.
getColumnNames
())
{
Optional
<
String
>
assistedColumnName
=
encryptRule
.
getEncryptorEngine
().
getAssistedQueryColumn
(
insertStatement
.
getTables
().
getSingleTableName
(),
each
);
if
(
assistedColumnName
.
isPresent
())
{
result
.
add
(
assistedColumnName
.
get
());
}
}
return
result
;
}
}
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertSetAddGeneratedKeyTokenGenerator.java
0 → 100644
浏览文件 @
ce7e1f18
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertSetAddGeneratedKeyToken
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Insert set add items token generator.
*
* @author panjuan
*/
public
final
class
InsertSetAddGeneratedKeyTokenGenerator
implements
OptionalSQLTokenGenerator
<
ShardingRule
>
{
@Override
public
Optional
<
InsertSetAddGeneratedKeyToken
>
generateSQLToken
(
final
SQLStatement
sqlStatement
,
final
ShardingRule
shardingRule
)
{
Optional
<
SetAssignmentsSegment
>
setAssignmentsSegment
=
sqlStatement
.
findSQLSegment
(
SetAssignmentsSegment
.
class
);
if
(!(
sqlStatement
instanceof
InsertStatement
&&
setAssignmentsSegment
.
isPresent
()))
{
return
Optional
.
absent
();
}
return
createInsertSetAddGeneratedKeyToken
((
InsertStatement
)
sqlStatement
,
shardingRule
,
setAssignmentsSegment
.
get
());
}
private
Optional
<
InsertSetAddGeneratedKeyToken
>
createInsertSetAddGeneratedKeyToken
(
final
InsertStatement
insertStatement
,
final
ShardingRule
shardingRule
,
final
SetAssignmentsSegment
segment
)
{
Optional
<
String
>
generatedKeyColumn
=
getGeneratedKeyColumn
(
insertStatement
,
shardingRule
);
if
(
generatedKeyColumn
.
isPresent
())
{
List
<
AssignmentSegment
>
assignments
=
new
ArrayList
<>(
segment
.
getAssignments
());
return
Optional
.
of
(
new
InsertSetAddGeneratedKeyToken
(
assignments
.
get
(
assignments
.
size
()
-
1
).
getStopIndex
()
+
1
,
generatedKeyColumn
.
get
()));
}
return
Optional
.
absent
();
}
private
Optional
<
String
>
getGeneratedKeyColumn
(
final
InsertStatement
insertStatement
,
final
ShardingRule
shardingRule
)
{
String
tableName
=
insertStatement
.
getTables
().
getSingleTableName
();
Optional
<
String
>
generateKeyColumn
=
shardingRule
.
findGenerateKeyColumnName
(
tableName
);
return
generateKeyColumn
.
isPresent
()
&&
!
insertStatement
.
getColumnNames
().
contains
(
generateKeyColumn
.
get
())
?
generateKeyColumn
:
Optional
.<
String
>
absent
();
}
}
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertSetEncryptValueTokenGenerator.java
0 → 100644
浏览文件 @
ce7e1f18
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertSetEncryptValueToken
;
import
org.apache.shardingsphere.core.rule.EncryptRule
;
import
org.apache.shardingsphere.spi.encrypt.ShardingEncryptor
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.LinkedList
;
/**
* Insert set encrypt value token generator.
*
* @author panjuan
*/
public
final
class
InsertSetEncryptValueTokenGenerator
implements
CollectionSQLTokenGenerator
<
EncryptRule
>
{
@Override
public
Collection
<
InsertSetEncryptValueToken
>
generateSQLTokens
(
final
SQLStatement
sqlStatement
,
final
EncryptRule
encryptRule
)
{
Optional
<
SetAssignmentsSegment
>
setAssignmentsSegment
=
sqlStatement
.
findSQLSegment
(
SetAssignmentsSegment
.
class
);
if
(!(
sqlStatement
instanceof
InsertStatement
&&
setAssignmentsSegment
.
isPresent
()))
{
return
Collections
.
emptyList
();
}
return
createInsertSetEncryptValueTokens
((
InsertStatement
)
sqlStatement
,
encryptRule
,
setAssignmentsSegment
.
get
());
}
private
Collection
<
InsertSetEncryptValueToken
>
createInsertSetEncryptValueTokens
(
final
InsertStatement
insertStatement
,
final
EncryptRule
encryptRule
,
final
SetAssignmentsSegment
segment
)
{
Collection
<
InsertSetEncryptValueToken
>
result
=
new
LinkedList
<>();
for
(
AssignmentSegment
each
:
segment
.
getAssignments
())
{
Optional
<
InsertSetEncryptValueToken
>
insertSetEncryptValueToken
=
getInsertSetEncryptValueToken
(
insertStatement
,
encryptRule
,
each
);
if
(
insertSetEncryptValueToken
.
isPresent
())
{
result
.
add
(
insertSetEncryptValueToken
.
get
());
}
}
return
result
;
}
private
Optional
<
InsertSetEncryptValueToken
>
getInsertSetEncryptValueToken
(
final
InsertStatement
insertStatement
,
final
EncryptRule
encryptRule
,
final
AssignmentSegment
segment
)
{
Optional
<
ShardingEncryptor
>
shardingEncryptor
=
encryptRule
.
getEncryptorEngine
().
getShardingEncryptor
(
insertStatement
.
getTables
().
getSingleTableName
(),
segment
.
getColumn
().
getName
());
if
(
shardingEncryptor
.
isPresent
()
&&
!(
segment
.
getValue
()
instanceof
ParameterMarkerExpressionSegment
))
{
return
Optional
.
of
(
new
InsertSetEncryptValueToken
(
segment
.
getValue
().
getStartIndex
(),
segment
.
getValue
().
getStopIndex
(),
segment
.
getColumn
().
getName
()));
}
return
Optional
.
absent
();
}
}
sharding-core/sharding-core-
parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/token/TokenAssert
.java
→
sharding-core/sharding-core-
rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/InsertValuesTokenGenerator
.java
浏览文件 @
ce7e1f18
...
@@ -15,36 +15,40 @@
...
@@ -15,36 +15,40 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.shardingsphere.core.
parse.integrate.asserts.token
;
package
org.apache.shardingsphere.core.
rewrite.token.generator
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage
;
import
com.google.common.base.Optional
;
import
org.apache.shardingsphere.core.parse.integrate.jaxb.token.ExpectedTokens
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.InsertValuesSegment
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.test.sql.SQLCaseType
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.InsertValuesToken
;
import
org.apache.shardingsphere.core.rule.BaseRule
;
import
java.util.Collection
;
import
java.util.Collection
;
/**
/**
*
Token assert
.
*
Insert values token generator
.
*
*
* @author
zhangliang
* @author
panjuan
*/
*/
public
final
class
TokenAssert
{
public
final
class
InsertValuesTokenGenerator
implements
OptionalSQLTokenGenerator
<
BaseRule
>
{
private
final
InsertValuesTokenAssert
insertValuesTokenAssert
;
@Override
public
Optional
<
InsertValuesToken
>
generateSQLToken
(
final
SQLStatement
sqlStatement
,
final
BaseRule
baseRule
)
{
public
TokenAssert
(
final
SQLCaseType
sqlCaseType
,
final
SQLStatementAssertMessage
assertMessage
)
{
Collection
<
InsertValuesSegment
>
insertValuesSegments
=
sqlStatement
.
findSQLSegments
(
InsertValuesSegment
.
class
);
insertValuesTokenAssert
=
new
InsertValuesTokenAssert
(
assertMessage
);
if
(!(
sqlStatement
instanceof
InsertStatement
)
||
insertValuesSegments
.
isEmpty
())
{
return
Optional
.
absent
();
}
return
createInsertValuesToken
(
insertValuesSegments
);
}
}
/**
private
Optional
<
InsertValuesToken
>
createInsertValuesToken
(
final
Collection
<
InsertValuesSegment
>
insertValuesSegments
)
{
* Assert tokens.
int
startIndex
=
insertValuesSegments
.
iterator
().
next
().
getStartIndex
();
*
int
stopIndex
=
insertValuesSegments
.
iterator
().
next
().
getStopIndex
();
* @param actual actual tokens
for
(
InsertValuesSegment
each
:
insertValuesSegments
)
{
* @param expected expected tokens
startIndex
=
startIndex
>
each
.
getStartIndex
()
?
each
.
getStartIndex
()
:
startIndex
;
*/
stopIndex
=
stopIndex
<
each
.
getStopIndex
()
?
each
.
getStopIndex
()
:
stopIndex
;
public
void
assertTokens
(
final
Collection
<
SQLToken
>
actual
,
final
ExpectedTokens
expected
)
{
}
// TODO do not assert table token and index, will assert table segment in future
return
Optional
.
of
(
new
InsertValuesToken
(
startIndex
,
stopIndex
));
insertValuesTokenAssert
.
assertInsertValuesToken
(
actual
,
expected
);
}
}
}
}
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/AggregationDistinctToken.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
com.google.common.base.Optional
;
import
com.google.common.base.Optional
;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Aggregation distinct token.
* Aggregation distinct token.
...
...
sharding-core/sharding-core-
parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/token
/Attachable.java
→
sharding-core/sharding-core-
rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo
/Attachable.java
浏览文件 @
ce7e1f18
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.shardingsphere.core.
parse.sql.token
;
package
org.apache.shardingsphere.core.
rewrite.token.pojo
;
/**
/**
* Attach available.
* Attach available.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/EncryptColumnToken.java
浏览文件 @
ce7e1f18
...
@@ -21,7 +21,6 @@ import lombok.Getter;
...
@@ -21,7 +21,6 @@ import lombok.Getter;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.context.condition.Column
;
import
org.apache.shardingsphere.core.parse.sql.context.condition.Column
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Encrypt column token.
* Encrypt column token.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/IndexToken.java
浏览文件 @
ce7e1f18
...
@@ -21,7 +21,6 @@ import lombok.Getter;
...
@@ -21,7 +21,6 @@ import lombok.Getter;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.constant.QuoteCharacter
;
import
org.apache.shardingsphere.core.parse.constant.QuoteCharacter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Index token.
* Index token.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertAssistedColumnsToken.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.EqualsAndHashCode
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
java.util.Collection
;
import
java.util.Collection
;
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertColumnsToken.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.EqualsAndHashCode
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
java.util.Collection
;
import
java.util.Collection
;
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertGeneratedKeyToken.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.EqualsAndHashCode
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
/**
/**
...
...
sharding-core/sharding-core-
parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/token/impl/InsertSetAddItem
sToken.java
→
sharding-core/sharding-core-
rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertSetAddAssistedColumn
sToken.java
浏览文件 @
ce7e1f18
...
@@ -15,10 +15,9 @@
...
@@ -15,10 +15,9 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.shardingsphere.core.
parse.sql.token.impl
;
package
org.apache.shardingsphere.core.
rewrite.token.pojo
;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -29,11 +28,11 @@ import java.util.Collection;
...
@@ -29,11 +28,11 @@ import java.util.Collection;
* @author panjuan
* @author panjuan
*/
*/
@Getter
@Getter
public
final
class
InsertSetAdd
Item
sToken
extends
SQLToken
implements
Attachable
{
public
final
class
InsertSetAdd
AssistedColumn
sToken
extends
SQLToken
implements
Attachable
{
private
final
Collection
<
String
>
columnNames
;
private
final
Collection
<
String
>
columnNames
;
public
InsertSetAdd
Item
sToken
(
final
int
startIndex
,
final
Collection
<
String
>
columnNames
)
{
public
InsertSetAdd
AssistedColumn
sToken
(
final
int
startIndex
,
final
Collection
<
String
>
columnNames
)
{
super
(
startIndex
);
super
(
startIndex
);
this
.
columnNames
=
columnNames
;
this
.
columnNames
=
columnNames
;
}
}
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/InsertSetAddGeneratedKeyToken.java
0 → 100644
浏览文件 @
ce7e1f18
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.core.rewrite.token.pojo
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
/**
* Insert set add generated key token.
*
* @author panjuan
*/
@Getter
public
final
class
InsertSetAddGeneratedKeyToken
extends
SQLToken
implements
Attachable
{
private
final
String
columnName
;
public
InsertSetAddGeneratedKeyToken
(
final
int
startIndex
,
final
String
columnName
)
{
super
(
startIndex
);
this
.
columnName
=
columnName
;
}
}
sharding-core/sharding-core-
parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/token/impl
/InsertSetEncryptValueToken.java
→
sharding-core/sharding-core-
rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo
/InsertSetEncryptValueToken.java
浏览文件 @
ce7e1f18
...
@@ -15,11 +15,10 @@
...
@@ -15,11 +15,10 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.shardingsphere.core.
parse.sql.token.impl
;
package
org.apache.shardingsphere.core.
rewrite.token.pojo
;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Insert set encrypt value token.
* Insert set encrypt value token.
...
...
sharding-core/sharding-core-
parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/token/impl
/InsertValuesToken.java
→
sharding-core/sharding-core-
rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo
/InsertValuesToken.java
浏览文件 @
ce7e1f18
...
@@ -15,11 +15,10 @@
...
@@ -15,11 +15,10 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.shardingsphere.core.
parse.sql.token.impl
;
package
org.apache.shardingsphere.core.
rewrite.token.pojo
;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Insert values token.
* Insert values token.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java
浏览文件 @
ce7e1f18
...
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Offset token for limit.
* Offset token for limit.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OrderByToken.java
浏览文件 @
ce7e1f18
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
org.apache.shardingsphere.core.rewrite.token.pojo
;
package
org.apache.shardingsphere.core.rewrite.token.pojo
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
/**
/**
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RemoveToken.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Remove token.
* Remove token.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java
浏览文件 @
ce7e1f18
...
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
/**
/**
* Row count token for limit.
* Row count token for limit.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectItemPrefixToken.java
浏览文件 @
ce7e1f18
...
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
/**
/**
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/SelectItemsToken.java
浏览文件 @
ce7e1f18
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
...
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.EqualsAndHashCode
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.token.Attachable
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
java.util.Collection
;
import
java.util.Collection
;
...
...
sharding-core/sharding-core-
parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/token
/Substitutable.java
→
sharding-core/sharding-core-
rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo
/Substitutable.java
浏览文件 @
ce7e1f18
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org.apache.shardingsphere.core.
parse.sql.token
;
package
org.apache.shardingsphere.core.
rewrite.token.pojo
;
/**
/**
* Substitute available.
* Substitute available.
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/TableToken.java
浏览文件 @
ce7e1f18
...
@@ -21,7 +21,6 @@ import lombok.Getter;
...
@@ -21,7 +21,6 @@ import lombok.Getter;
import
lombok.ToString
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.constant.QuoteCharacter
;
import
org.apache.shardingsphere.core.parse.constant.QuoteCharacter
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.SQLToken
;
import
org.apache.shardingsphere.core.parse.sql.token.Substitutable
;
import
org.apache.shardingsphere.core.parse.util.SQLUtil
;
import
org.apache.shardingsphere.core.parse.util.SQLUtil
;
/**
/**
...
...
sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java
浏览文件 @
ce7e1f18
...
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.context.condition.Column;
...
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.context.condition.Column;
import
org.apache.shardingsphere.core.parse.sql.context.condition.Condition
;
import
org.apache.shardingsphere.core.parse.sql.context.condition.Condition
;
import
org.apache.shardingsphere.core.parse.sql.context.table.Table
;
import
org.apache.shardingsphere.core.parse.sql.context.table.Table
;
import
org.apache.shardingsphere.core.parse.sql.segment.common.TableSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.common.TableSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.InsertValuesSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.SelectItemsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.SelectItemsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.AssignmentSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.assignment.SetAssignmentsSegment
;
...
@@ -49,7 +50,6 @@ import org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement;
...
@@ -49,7 +50,6 @@ import org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.core.parse.sql.token.impl.InsertValuesToken
;
import
org.apache.shardingsphere.core.rewrite.SQLRewriteEngine
;
import
org.apache.shardingsphere.core.rewrite.SQLRewriteEngine
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.ParameterBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
import
org.apache.shardingsphere.core.rewrite.builder.SQLBuilder
;
...
@@ -179,9 +179,9 @@ public final class ShardingSQLRewriterTest {
...
@@ -179,9 +179,9 @@ public final class ShardingSQLRewriterTest {
insertStatement
.
getColumnNames
().
add
(
"age"
);
insertStatement
.
getColumnNames
().
add
(
"age"
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
30
,
30
,
Collections
.
singleton
(
mock
(
ColumnSegment
.
class
))));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
30
,
30
,
Collections
.
singleton
(
mock
(
ColumnSegment
.
class
))));
insertStatement
.
getSqlSegments
().
add
(
new
InsertValuesSegment
(
39
,
44
,
Collections
.<
ExpressionSegment
>
emptyList
()));
insertStatement
.
setParametersIndex
(
2
);
insertStatement
.
setParametersIndex
(
2
);
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
18
,
"table_x"
,
QuoteCharacter
.
NONE
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
18
,
"table_x"
,
QuoteCharacter
.
NONE
));
insertStatement
.
addSQLToken
(
new
InsertValuesToken
(
39
,
44
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"age"
,
"id"
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"age"
,
"id"
));
Object
[]
parameters
=
{
"x"
,
1
,
1
};
Object
[]
parameters
=
{
"x"
,
1
,
1
};
ExpressionSegment
[]
expressionSegments
=
{
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
2
)};
ExpressionSegment
[]
expressionSegments
=
{
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
2
)};
...
@@ -202,10 +202,10 @@ public final class ShardingSQLRewriterTest {
...
@@ -202,10 +202,10 @@ public final class ShardingSQLRewriterTest {
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertValuesSegment
(
29
,
31
,
Collections
.<
ExpressionSegment
>
emptyList
()));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
setParametersIndex
(
1
);
insertStatement
.
setParametersIndex
(
1
);
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
InsertValuesToken
(
29
,
31
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
Object
[]
parameters
=
{
"Bill"
,
1
};
Object
[]
parameters
=
{
"Bill"
,
1
};
ExpressionSegment
[]
expressionSegments
=
{
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
)};
ExpressionSegment
[]
expressionSegments
=
{
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
)};
...
@@ -226,9 +226,9 @@ public final class ShardingSQLRewriterTest {
...
@@ -226,9 +226,9 @@ public final class ShardingSQLRewriterTest {
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertValuesSegment
(
29
,
32
,
Collections
.<
ExpressionSegment
>
emptyList
()));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
InsertValuesToken
(
29
,
32
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
)};
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
)};
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
...
@@ -248,9 +248,9 @@ public final class ShardingSQLRewriterTest {
...
@@ -248,9 +248,9 @@ public final class ShardingSQLRewriterTest {
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertValuesSegment
(
29
,
32
,
Collections
.<
ExpressionSegment
>
emptyList
()));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
InsertValuesToken
(
29
,
32
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
)};
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
)};
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
...
@@ -294,8 +294,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -294,8 +294,8 @@ public final class ShardingSQLRewriterTest {
parameters
.
add
(
"x"
);
parameters
.
add
(
"x"
);
parameters
.
add
(
1
);
parameters
.
add
(
1
);
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
InsertValuesToken
(
29
,
35
));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertValuesSegment
(
29
,
35
,
Collections
.<
ExpressionSegment
>
emptyList
()));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
)};
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
)};
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
...
@@ -315,9 +315,9 @@ public final class ShardingSQLRewriterTest {
...
@@ -315,9 +315,9 @@ public final class ShardingSQLRewriterTest {
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
getColumnNames
().
add
(
"name"
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
setNeededToAppendGeneratedKey
(
true
);
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertColumnsSegment
(
21
,
21
,
Collections
.<
ColumnSegment
>
emptyList
()));
insertStatement
.
getSqlSegments
().
add
(
new
InsertValuesSegment
(
29
,
34
,
Collections
.<
ExpressionSegment
>
emptyList
()));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
null
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_x`"
,
QuoteCharacter
.
BACK_QUOTE
));
insertStatement
.
addSQLToken
(
new
InsertValuesToken
(
29
,
34
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
));
ExpressionSegment
[]
expressionSegments
=
{
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
)};
ExpressionSegment
[]
expressionSegments
=
{
new
ParameterMarkerExpressionSegment
(
0
,
0
,
0
),
new
ParameterMarkerExpressionSegment
(
0
,
0
,
1
)};
Object
[]
parameters
=
{
"x"
,
1
};
Object
[]
parameters
=
{
"x"
,
1
};
...
@@ -533,9 +533,6 @@ public final class ShardingSQLRewriterTest {
...
@@ -533,9 +533,6 @@ public final class ShardingSQLRewriterTest {
List
<
Object
>
parameters
=
new
ArrayList
<>(
2
);
List
<
Object
>
parameters
=
new
ArrayList
<>(
2
);
parameters
.
add
(
1
);
parameters
.
add
(
1
);
parameters
.
add
(
"x"
);
parameters
.
add
(
"x"
);
selectStatement
.
addSQLToken
(
new
TableToken
(
7
,
13
,
"table_x"
,
QuoteCharacter
.
NONE
));
selectStatement
.
addSQLToken
(
new
TableToken
(
31
,
37
,
"table_x"
,
QuoteCharacter
.
NONE
));
selectStatement
.
addSQLToken
(
new
TableToken
(
58
,
64
,
"table_x"
,
QuoteCharacter
.
NONE
));
selectStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
"x"
));
selectStatement
.
getTables
().
add
(
new
Table
(
"table_x"
,
"x"
));
selectStatement
.
getTables
().
add
(
new
Table
(
"table_y"
,
"y"
));
selectStatement
.
getTables
().
add
(
new
Table
(
"table_y"
,
"y"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
...
@@ -543,7 +540,7 @@ public final class ShardingSQLRewriterTest {
...
@@ -543,7 +540,7 @@ public final class ShardingSQLRewriterTest {
selectStatement
.
setLogicSQL
(
"SELECT table_x.id, x.name FROM table_x x, table_y y WHERE table_x.id=? AND x.name=?"
);
selectStatement
.
setLogicSQL
(
"SELECT table_x.id, x.name FROM table_x x, table_y y WHERE table_x.id=? AND x.name=?"
);
SQLRewriteEngine
rewriteEngine
=
new
SQLRewriteEngine
(
shardingRule
,
routeResult
.
getSqlStatement
(),
parameters
);
SQLRewriteEngine
rewriteEngine
=
new
SQLRewriteEngine
(
shardingRule
,
routeResult
.
getSqlStatement
(),
parameters
);
rewriteEngine
.
init
(
rewriteEngine
.
init
(
new
ShardingSQLRewriter
(
shardingRule
,
DatabaseType
.
MySQL
,
routeResult
),
new
ShardingSQLRewriter
(
shardingRule
,
DatabaseType
.
MySQL
,
routeResult
,
null
),
new
EncryptSQLRewriter
(
shardingRule
.
getEncryptRule
().
getEncryptorEngine
(),
routeResult
.
getSqlStatement
(),
routeResult
.
getOptimizeResult
()));
new
EncryptSQLRewriter
(
shardingRule
.
getEncryptRule
().
getEncryptorEngine
(),
routeResult
.
getSqlStatement
(),
routeResult
.
getOptimizeResult
()));
RoutingUnit
routingUnit
=
new
RoutingUnit
(
"db0"
);
RoutingUnit
routingUnit
=
new
RoutingUnit
(
"db0"
);
routingUnit
.
getTableUnits
().
add
(
new
TableUnit
(
"table_x"
,
"table_x"
));
routingUnit
.
getTableUnits
().
add
(
new
TableUnit
(
"table_x"
,
"table_x"
));
...
@@ -863,6 +860,29 @@ public final class ShardingSQLRewriterTest {
...
@@ -863,6 +860,29 @@ public final class ShardingSQLRewriterTest {
assertThat
(
getSQLBuilder
(
rewriteEngine
).
toSQL
(
null
,
tableTokens
),
is
(
"UPDATE table_z SET id = 'encryptValue' WHERE id = 'encryptValue'"
));
assertThat
(
getSQLBuilder
(
rewriteEngine
).
toSQL
(
null
,
tableTokens
),
is
(
"UPDATE table_z SET id = 'encryptValue' WHERE id = 'encryptValue'"
));
}
}
@Test
public
void
assertInsertWithQueryAssistedShardingEncryptor
()
{
insertStatement
.
getColumnNames
().
add
(
"name"
);
ColumnSegment
columnSegment
=
new
ColumnSegment
(
26
,
29
,
"name"
);
LiteralExpressionSegment
expressionSegment
=
new
LiteralExpressionSegment
(
33
,
34
,
10
);
insertStatement
.
getSqlSegments
().
add
(
new
SetAssignmentsSegment
(
22
,
34
,
Collections
.
singleton
(
new
AssignmentSegment
(
22
,
34
,
columnSegment
,
expressionSegment
))));
insertStatement
.
getTables
().
add
(
new
Table
(
"table_w"
,
null
));
insertStatement
.
addSQLToken
(
new
TableToken
(
12
,
20
,
"`table_w`"
,
QuoteCharacter
.
BACK_QUOTE
));
InsertOptimizeResult
insertOptimizeResult
=
new
InsertOptimizeResult
(
Arrays
.
asList
(
"name"
,
"id"
,
"query_name"
));
ExpressionSegment
[]
expressionSegments
=
{
new
LiteralExpressionSegment
(
0
,
0
,
10
),
new
LiteralExpressionSegment
(
0
,
0
,
1
),
new
LiteralExpressionSegment
(
0
,
0
,
10
)};
insertOptimizeResult
.
addUnit
(
expressionSegments
,
new
Object
[
0
],
0
);
insertOptimizeResult
.
getUnits
().
get
(
0
).
getDataNodes
().
add
(
new
DataNode
(
"db0.table_1"
));
RoutingUnit
routingUnit
=
new
RoutingUnit
(
"db0"
);
routingUnit
.
getTableUnits
().
add
(
new
TableUnit
(
"table_w"
,
"table_1"
));
routeResult
=
new
SQLRouteResult
(
insertStatement
);
routeResult
.
setOptimizeResult
(
new
OptimizeResult
(
insertOptimizeResult
));
routeResult
.
setRoutingResult
(
new
RoutingResult
());
insertStatement
.
setLogicSQL
(
"INSERT INTO `table_w` set name = 10 ON DUPLICATE KEY UPDATE name = VALUES(name)"
);
SQLRewriteEngine
rewriteEngine
=
createSQLRewriteEngine
(
DatabaseType
.
MySQL
,
Collections
.
emptyList
());
assertThat
(
getSQLBuilder
(
rewriteEngine
).
toSQL
(
routingUnit
,
tableTokens
),
is
(
"INSERT INTO `table_w` set name = 'encryptValue', id = 1, query_name = 'assistedEncryptValue' ON DUPLICATE KEY UPDATE name = VALUES(name)"
));
}
@Test
@Test
public
void
assertSelectInWithAggregationDistinct
()
{
public
void
assertSelectInWithAggregationDistinct
()
{
selectStatement
.
addSQLToken
(
new
TableToken
(
49
,
55
,
"table_z"
,
QuoteCharacter
.
NONE
));
selectStatement
.
addSQLToken
(
new
TableToken
(
49
,
55
,
"table_z"
,
QuoteCharacter
.
NONE
));
...
@@ -883,7 +903,7 @@ public final class ShardingSQLRewriterTest {
...
@@ -883,7 +903,7 @@ public final class ShardingSQLRewriterTest {
private
SQLRewriteEngine
createSQLRewriteEngine
(
final
DatabaseType
databaseType
,
final
List
<
Object
>
parameters
)
{
private
SQLRewriteEngine
createSQLRewriteEngine
(
final
DatabaseType
databaseType
,
final
List
<
Object
>
parameters
)
{
SQLRewriteEngine
result
=
new
SQLRewriteEngine
(
shardingRule
,
routeResult
.
getSqlStatement
(),
parameters
);
SQLRewriteEngine
result
=
new
SQLRewriteEngine
(
shardingRule
,
routeResult
.
getSqlStatement
(),
parameters
);
result
.
init
(
result
.
init
(
new
ShardingSQLRewriter
(
shardingRule
,
databaseType
,
routeResult
),
new
ShardingSQLRewriter
(
shardingRule
,
databaseType
,
routeResult
,
routeResult
.
getOptimizeResult
()
),
new
EncryptSQLRewriter
(
shardingRule
.
getEncryptRule
().
getEncryptorEngine
(),
routeResult
.
getSqlStatement
(),
routeResult
.
getOptimizeResult
()));
new
EncryptSQLRewriter
(
shardingRule
.
getEncryptRule
().
getEncryptorEngine
(),
routeResult
.
getSqlStatement
(),
routeResult
.
getOptimizeResult
()));
return
result
;
return
result
;
}
}
...
...
sharding-core/sharding-core-rewrite/src/test/resources/yaml/rewrite-rule.yaml
浏览文件 @
ce7e1f18
...
@@ -42,6 +42,11 @@ shardingRule:
...
@@ -42,6 +42,11 @@ shardingRule:
actualDataNodes
:
db${0..1}.table_z
actualDataNodes
:
db${0..1}.table_z
table_k
:
table_k
:
actualDataNodes
:
db${0..1}.table_k
actualDataNodes
:
db${0..1}.table_k
table_w
:
actualDataNodes
:
db${0..1}.table_w
keyGenerator
:
type
:
SNOWFLAKE
column
:
id
bindingTables
:
bindingTables
:
-
table_x, table_y
-
table_x, table_y
encryptRule
:
encryptRule
:
...
@@ -51,5 +56,5 @@ shardingRule:
...
@@ -51,5 +56,5 @@ shardingRule:
qualifiedColumns
:
table_z.id
qualifiedColumns
:
table_z.id
k_encryptor
:
k_encryptor
:
type
:
ASSISTEDTEST
type
:
ASSISTEDTEST
qualifiedColumns
:
table_k.id, table_k.id1
qualifiedColumns
:
table_k.id, table_k.id1
, table_w.name
assistedQueryColumns
:
table_k.query_id, table_k.query_id1
assistedQueryColumns
:
table_k.query_id, table_k.query_id1
, table_w.query_name
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录