Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
ba32bf80
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,发现更多精彩内容 >>
未验证
提交
ba32bf80
编写于
5月 09, 2019
作者:
L
Liang Zhang
提交者:
GitHub
5月 09, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2358 from cherrylzhao/dev-upstream
for #2356 support transaction for python mysql connector.
上级
667747a2
ad898b00
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
5 deletion
+20
-5
sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/text/TextProtocolBackendHandlerFactory.java
...proxy/backend/text/TextProtocolBackendHandlerFactory.java
+4
-2
sharding-proxy/sharding-proxy-backend/src/test/java/org/apache/shardingsphere/shardingproxy/backend/TextProtocolBackendHandlerFactoryTest.java
...gproxy/backend/TextProtocolBackendHandlerFactoryTest.java
+14
-2
sharding-transaction/sharding-transaction-core/src/main/java/org/apache/shardingsphere/transaction/core/TransactionOperationType.java
...dingsphere/transaction/core/TransactionOperationType.java
+2
-1
未找到文件。
sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/text/TextProtocolBackendHandlerFactory.java
浏览文件 @
ba32bf80
...
...
@@ -37,7 +37,9 @@ import org.apache.shardingsphere.shardingproxy.backend.text.transaction.Transact
import
org.apache.shardingsphere.transaction.core.TransactionOperationType
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* Text protocol backend handler factory.
...
...
@@ -47,7 +49,7 @@ import java.util.List;
@NoArgsConstructor
(
access
=
AccessLevel
.
PRIVATE
)
public
final
class
TextProtocolBackendHandlerFactory
{
private
static
final
S
tring
SET_AUTOCOMMIT_1
=
"SET AUTOCOMMIT=1"
;
private
static
final
S
et
<
String
>
AUTO_COMMIT
=
new
HashSet
<>(
Arrays
.
asList
(
"SET AUTOCOMMIT=1"
,
"SET @@SESSION.AUTOCOMMIT = ON"
))
;
private
static
final
List
<
String
>
GUI_SQL
=
Arrays
.
asList
(
"SET"
,
"SHOW VARIABLES LIKE"
,
"SHOW CHARACTER SET"
,
"SHOW COLLATION"
);
...
...
@@ -67,7 +69,7 @@ public final class TextProtocolBackendHandlerFactory {
if
(
transactionOperationType
.
isPresent
())
{
return
new
TransactionBackendHandler
(
transactionOperationType
.
get
(),
backendConnection
);
}
if
(
sql
.
toUpperCase
().
contains
(
SET_AUTOCOMMIT_1
))
{
if
(
AUTO_COMMIT
.
contains
(
sql
.
toUpperCase
()
))
{
return
backendConnection
.
getStateHandler
().
isInTransaction
()
?
new
TransactionBackendHandler
(
TransactionOperationType
.
COMMIT
,
backendConnection
)
:
new
SkipBackendHandler
();
}
SQLStatement
sqlStatement
=
new
SQLJudgeEngine
(
sql
).
judge
();
...
...
sharding-proxy/sharding-proxy-backend/src/test/java/org/apache/shardingsphere/shardingproxy/backend/TextProtocolBackendHandlerFactoryTest.java
浏览文件 @
ba32bf80
...
...
@@ -60,20 +60,32 @@ public final class TextProtocolBackendHandlerFactoryTest {
}
@Test
public
void
assertNewInstance
()
{
public
void
assertNew
Transaction
Instance
()
{
String
sql
=
"BEGIN"
;
TextProtocolBackendHandler
actual
=
TextProtocolBackendHandlerFactory
.
newInstance
(
sql
,
backendConnection
);
assertThat
(
actual
,
instanceOf
(
TransactionBackendHandler
.
class
));
sql
=
"START TRANSACTION"
;
actual
=
TextProtocolBackendHandlerFactory
.
newInstance
(
sql
,
backendConnection
);
assertThat
(
actual
,
instanceOf
(
TransactionBackendHandler
.
class
));
sql
=
"SET AUTOCOMMIT=0"
;
actual
=
TextProtocolBackendHandlerFactory
.
newInstance
(
sql
,
backendConnection
);
assertThat
(
actual
,
instanceOf
(
TransactionBackendHandler
.
class
));
sql
=
"SET @@SESSION.AUTOCOMMIT = OFF"
;
actual
=
TextProtocolBackendHandlerFactory
.
newInstance
(
sql
,
backendConnection
);
assertThat
(
actual
,
instanceOf
(
TransactionBackendHandler
.
class
));
}
@Test
public
void
assertNewTransactionBackendHandlerInstanceOfCommitOperate
()
{
String
sql
=
"SET AUTOCOMMIT=1"
;
ConnectionStateHandler
stateHandler
=
mock
(
ConnectionStateHandler
.
class
);
when
(
backendConnection
.
getStateHandler
()).
thenReturn
(
stateHandler
);
when
(
stateHandler
.
isInTransaction
()).
thenReturn
(
true
);
String
sql
=
"SET AUTOCOMMIT=1"
;
TextProtocolBackendHandler
actual
=
TextProtocolBackendHandlerFactory
.
newInstance
(
sql
,
backendConnection
);
assertThat
(
actual
,
instanceOf
(
TransactionBackendHandler
.
class
));
sql
=
"SET @@SESSION.AUTOCOMMIT = ON"
;
actual
=
TextProtocolBackendHandlerFactory
.
newInstance
(
sql
,
backendConnection
);
assertThat
(
actual
,
instanceOf
(
TransactionBackendHandler
.
class
));
}
@Test
...
...
sharding-transaction/sharding-transaction-core/src/main/java/org/apache/shardingsphere/transaction/core/TransactionOperationType.java
浏览文件 @
ba32bf80
...
...
@@ -31,7 +31,7 @@ public enum TransactionOperationType {
/**
* Get operation type.
*
*
* @param sql SQL
* @return transaction operation type
*/
...
...
@@ -41,6 +41,7 @@ public enum TransactionOperationType {
case
"BEGIN"
:
case
"START TRANSACTION"
:
case
"SET AUTOCOMMIT=0"
:
case
"SET @@SESSION.AUTOCOMMIT = OFF"
:
return
Optional
.
of
(
TransactionOperationType
.
BEGIN
);
case
"COMMIT"
:
return
Optional
.
of
(
TransactionOperationType
.
COMMIT
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录