Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
e1f241cb
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,发现更多精彩内容 >>
提交
e1f241cb
编写于
8月 13, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove TransactionContext
上级
0fb35825
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
31 addition
and
82 deletion
+31
-82
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
...ngsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+3
-8
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
...ngsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
+0
-6
sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
...e/proxy/backend/jdbc/transaction/XaTransactionEngine.java
+2
-3
sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
...ain/java/io/shardingsphere/proxy/config/RuleRegistry.java
+2
-3
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
...shardingsphere/transaction/common/TransactionContext.java
+0
-42
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionTypeHolder.java
...rdingsphere/transaction/common/TransactionTypeHolder.java
+16
-13
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
...ere/transaction/common/event/TransactionEventFactory.java
+2
-2
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
...here/transaction/common/listener/TransactionListener.java
+6
-5
未找到文件。
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
浏览文件 @
e1f241cb
...
@@ -24,10 +24,7 @@ import io.shardingsphere.core.hint.HintManagerHolder;
...
@@ -24,10 +24,7 @@ import io.shardingsphere.core.hint.HintManagerHolder;
import
io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection
;
import
io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection
;
import
io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager
;
import
io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager
;
import
io.shardingsphere.core.util.EventBusInstance
;
import
io.shardingsphere.core.util.EventBusInstance
;
import
io.shardingsphere.transaction.api.ShardingTransactionManagerRegistry
;
import
io.shardingsphere.transaction.common.TransactionTypeHolder
;
import
io.shardingsphere.transaction.api.local.LocalTransactionManager
;
import
io.shardingsphere.transaction.common.TransactionContext
;
import
io.shardingsphere.transaction.common.TransactionContextHolder
;
import
io.shardingsphere.transaction.common.event.LocalTransactionEvent
;
import
io.shardingsphere.transaction.common.event.LocalTransactionEvent
;
import
io.shardingsphere.transaction.common.event.TransactionEvent
;
import
io.shardingsphere.transaction.common.event.TransactionEvent
;
import
io.shardingsphere.transaction.common.event.TransactionEventFactory
;
import
io.shardingsphere.transaction.common.event.TransactionEventFactory
;
...
@@ -67,8 +64,6 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
...
@@ -67,8 +64,6 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
* @throws SQLException SQL exception
* @throws SQLException SQL exception
*/
*/
public
final
Connection
getConnection
(
final
String
dataSourceName
)
throws
SQLException
{
public
final
Connection
getConnection
(
final
String
dataSourceName
)
throws
SQLException
{
TransactionType
transactionType
=
TransactionContextHolder
.
get
().
getTransactionType
();
TransactionContextHolder
.
set
(
new
TransactionContext
(
ShardingTransactionManagerRegistry
.
getInstance
().
getShardingTransactionManager
(
transactionType
),
transactionType
));
if
(
cachedConnections
.
containsKey
(
dataSourceName
))
{
if
(
cachedConnections
.
containsKey
(
dataSourceName
))
{
return
cachedConnections
.
get
(
dataSourceName
);
return
cachedConnections
.
get
(
dataSourceName
);
}
}
...
@@ -94,7 +89,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
...
@@ -94,7 +89,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
@Override
@Override
public
final
void
setAutoCommit
(
final
boolean
autoCommit
)
{
public
final
void
setAutoCommit
(
final
boolean
autoCommit
)
{
this
.
autoCommit
=
autoCommit
;
this
.
autoCommit
=
autoCommit
;
Transaction
ContextHolder
.
set
(
new
TransactionContext
(
new
LocalTransactionManager
(),
TransactionType
.
LOCAL
)
);
Transaction
TypeHolder
.
set
(
TransactionType
.
LOCAL
);
recordMethodInvocation
(
Connection
.
class
,
"setAutoCommit"
,
new
Class
[]
{
boolean
.
class
},
new
Object
[]
{
autoCommit
});
recordMethodInvocation
(
Connection
.
class
,
"setAutoCommit"
,
new
Class
[]
{
boolean
.
class
},
new
Object
[]
{
autoCommit
});
EventBusInstance
.
getInstance
().
post
(
buildTransactionEvent
(
TCLType
.
BEGIN
));
EventBusInstance
.
getInstance
().
post
(
buildTransactionEvent
(
TCLType
.
BEGIN
));
}
}
...
@@ -114,7 +109,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
...
@@ -114,7 +109,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
closed
=
true
;
closed
=
true
;
HintManagerHolder
.
clear
();
HintManagerHolder
.
clear
();
MasterVisitedManager
.
clear
();
MasterVisitedManager
.
clear
();
Transaction
Context
Holder
.
clear
();
Transaction
Type
Holder
.
clear
();
Collection
<
SQLException
>
exceptions
=
new
LinkedList
<>();
Collection
<
SQLException
>
exceptions
=
new
LinkedList
<>();
for
(
Connection
each
:
cachedConnections
.
values
())
{
for
(
Connection
each
:
cachedConnections
.
values
())
{
try
{
try
{
...
...
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java
浏览文件 @
e1f241cb
...
@@ -19,12 +19,8 @@ package io.shardingsphere.core.jdbc.adapter;
...
@@ -19,12 +19,8 @@ package io.shardingsphere.core.jdbc.adapter;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Preconditions
;
import
io.shardingsphere.core.constant.DatabaseType
;
import
io.shardingsphere.core.constant.DatabaseType
;
import
io.shardingsphere.core.constant.TransactionType
;
import
io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource
;
import
io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource
;
import
io.shardingsphere.core.listener.JDBCListenerRegister
;
import
io.shardingsphere.core.listener.JDBCListenerRegister
;
import
io.shardingsphere.transaction.api.ShardingTransactionManagerRegistry
;
import
io.shardingsphere.transaction.common.TransactionContext
;
import
io.shardingsphere.transaction.common.TransactionContextHolder
;
import
lombok.Getter
;
import
lombok.Getter
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
@@ -42,8 +38,6 @@ import java.util.logging.Logger;
...
@@ -42,8 +38,6 @@ import java.util.logging.Logger;
public
abstract
class
AbstractDataSourceAdapter
extends
AbstractUnsupportedOperationDataSource
{
public
abstract
class
AbstractDataSourceAdapter
extends
AbstractUnsupportedOperationDataSource
{
static
{
static
{
TransactionType
transactionType
=
TransactionContextHolder
.
get
().
getTransactionType
();
TransactionContextHolder
.
set
(
new
TransactionContext
(
ShardingTransactionManagerRegistry
.
getInstance
().
getShardingTransactionManager
(
transactionType
),
transactionType
));
JDBCListenerRegister
.
register
();
JDBCListenerRegister
.
register
();
}
}
...
...
sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java
浏览文件 @
e1f241cb
...
@@ -22,8 +22,7 @@ import io.shardingsphere.core.constant.TCLType;
...
@@ -22,8 +22,7 @@ import io.shardingsphere.core.constant.TCLType;
import
io.shardingsphere.core.constant.TransactionType
;
import
io.shardingsphere.core.constant.TransactionType
;
import
io.shardingsphere.core.util.EventBusInstance
;
import
io.shardingsphere.core.util.EventBusInstance
;
import
io.shardingsphere.proxy.config.RuleRegistry
;
import
io.shardingsphere.proxy.config.RuleRegistry
;
import
io.shardingsphere.transaction.common.TransactionContext
;
import
io.shardingsphere.transaction.common.TransactionTypeHolder
;
import
io.shardingsphere.transaction.common.TransactionContextHolder
;
import
io.shardingsphere.transaction.common.event.XaTransactionEvent
;
import
io.shardingsphere.transaction.common.event.XaTransactionEvent
;
import
javax.transaction.Status
;
import
javax.transaction.Status
;
...
@@ -46,7 +45,7 @@ public final class XaTransactionEngine extends TransactionEngine {
...
@@ -46,7 +45,7 @@ public final class XaTransactionEngine extends TransactionEngine {
public
boolean
execute
()
throws
SQLException
{
public
boolean
execute
()
throws
SQLException
{
Optional
<
TCLType
>
tclType
=
parseSQL
();
Optional
<
TCLType
>
tclType
=
parseSQL
();
if
(
tclType
.
isPresent
()
&&
isInTransaction
(
tclType
.
get
()))
{
if
(
tclType
.
isPresent
()
&&
isInTransaction
(
tclType
.
get
()))
{
Transaction
ContextHolder
.
set
(
new
TransactionContext
(
RULE_REGISTRY
.
getTransactionManager
(),
TransactionType
.
XA
)
);
Transaction
TypeHolder
.
set
(
TransactionType
.
XA
);
EventBusInstance
.
getInstance
().
post
(
new
XaTransactionEvent
(
tclType
.
get
(),
getSql
()));
EventBusInstance
.
getInstance
().
post
(
new
XaTransactionEvent
(
tclType
.
get
(),
getSql
()));
return
true
;
return
true
;
}
}
...
...
sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java
浏览文件 @
e1f241cb
...
@@ -35,8 +35,7 @@ import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent
...
@@ -35,8 +35,7 @@ import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent
import
io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource
;
import
io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource
;
import
io.shardingsphere.transaction.api.ShardingTransactionManager
;
import
io.shardingsphere.transaction.api.ShardingTransactionManager
;
import
io.shardingsphere.transaction.api.ShardingTransactionManagerRegistry
;
import
io.shardingsphere.transaction.api.ShardingTransactionManagerRegistry
;
import
io.shardingsphere.transaction.common.TransactionContext
;
import
io.shardingsphere.transaction.common.TransactionTypeHolder
;
import
io.shardingsphere.transaction.common.TransactionContextHolder
;
import
lombok.AccessLevel
;
import
lombok.AccessLevel
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -109,7 +108,7 @@ public final class RuleRegistry {
...
@@ -109,7 +108,7 @@ public final class RuleRegistry {
connectionMode
=
ConnectionMode
.
valueOf
(
shardingProperties
.<
String
>
getValue
(
ShardingPropertiesConstant
.
CONNECTION_MODE
));
connectionMode
=
ConnectionMode
.
valueOf
(
shardingProperties
.<
String
>
getValue
(
ShardingPropertiesConstant
.
CONNECTION_MODE
));
transactionType
=
TransactionType
.
valueOf
(
shardingProperties
.<
String
>
getValue
(
ShardingPropertiesConstant
.
PROXY_TRANSACTION_MODE
));
transactionType
=
TransactionType
.
valueOf
(
shardingProperties
.<
String
>
getValue
(
ShardingPropertiesConstant
.
PROXY_TRANSACTION_MODE
));
transactionManager
=
ShardingTransactionManagerRegistry
.
getInstance
().
getShardingTransactionManager
(
transactionType
);
transactionManager
=
ShardingTransactionManagerRegistry
.
getInstance
().
getShardingTransactionManager
(
transactionType
);
Transaction
ContextHolder
.
set
(
new
TransactionContext
(
transactionManager
,
transactionType
)
);
Transaction
TypeHolder
.
set
(
transactionType
);
acceptorSize
=
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
ACCEPTOR_SIZE
);
acceptorSize
=
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
ACCEPTOR_SIZE
);
executorSize
=
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_SIZE
);
executorSize
=
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_SIZE
);
// TODO :jiaqi force off use NIO for backend, this feature is not complete yet
// TODO :jiaqi force off use NIO for backend, this feature is not complete yet
...
...
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java
已删除
100644 → 0
浏览文件 @
0fb35825
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package
io.shardingsphere.transaction.common
;
import
io.shardingsphere.core.constant.TransactionType
;
import
io.shardingsphere.transaction.api.ShardingTransactionManager
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
/**
* Hold Transaction Context.
*
* @author zhaojun
*/
@NoArgsConstructor
@Getter
public
final
class
TransactionContext
{
private
ShardingTransactionManager
transactionManager
;
private
TransactionType
transactionType
=
TransactionType
.
LOCAL
;
public
TransactionContext
(
final
ShardingTransactionManager
transactionManager
,
final
TransactionType
transactionType
)
{
this
.
transactionManager
=
transactionManager
;
this
.
transactionType
=
transactionType
;
}
}
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/Transaction
Context
Holder.java
→
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/Transaction
Type
Holder.java
浏览文件 @
e1f241cb
...
@@ -17,41 +17,44 @@
...
@@ -17,41 +17,44 @@
package
io.shardingsphere.transaction.common
;
package
io.shardingsphere.transaction.common
;
import
io.shardingsphere.core.constant.TransactionType
;
/**
/**
* Hold transaction
context
for current thread.
* Hold transaction
type
for current thread.
*
*
* @author zhaojun
* @author zhaojun
* @author zhangliang
*/
*/
public
final
class
Transaction
Context
Holder
{
public
final
class
Transaction
Type
Holder
{
private
static
final
ThreadLocal
<
Transaction
Context
>
CONTEXT
=
new
ThreadLocal
<
TransactionContext
>()
{
private
static
final
ThreadLocal
<
Transaction
Type
>
CONTEXT
=
new
ThreadLocal
<
TransactionType
>()
{
@Override
@Override
protected
Transaction
Context
initialValue
()
{
protected
Transaction
Type
initialValue
()
{
return
new
TransactionContext
()
;
return
TransactionType
.
LOCAL
;
}
}
};
};
/**
/**
* Get transaction
context
for current thread.
* Get transaction
type
for current thread.
*
*
* @return
TransactionContext
* @return
transaction type
*/
*/
public
static
Transaction
Context
get
()
{
public
static
Transaction
Type
get
()
{
return
CONTEXT
.
get
();
return
CONTEXT
.
get
();
}
}
/**
/**
* Set transaction
context
for current thread.
* Set transaction
type
for current thread.
*
*
* @param
context Transaction context
* @param
transactionType transaction type
*/
*/
public
static
void
set
(
final
Transaction
Context
context
)
{
public
static
void
set
(
final
Transaction
Type
transactionType
)
{
CONTEXT
.
set
(
context
);
CONTEXT
.
set
(
transactionType
);
}
}
/**
/**
* Clear transaction
context
for current thread.
* Clear transaction
type
for current thread.
*/
*/
public
static
void
clear
()
{
public
static
void
clear
()
{
CONTEXT
.
remove
();
CONTEXT
.
remove
();
...
...
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java
浏览文件 @
e1f241cb
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
package
io.shardingsphere.transaction.common.event
;
package
io.shardingsphere.transaction.common.event
;
import
io.shardingsphere.core.constant.TCLType
;
import
io.shardingsphere.core.constant.TCLType
;
import
io.shardingsphere.transaction.common.Transaction
Context
Holder
;
import
io.shardingsphere.transaction.common.Transaction
Type
Holder
;
import
lombok.AccessLevel
;
import
lombok.AccessLevel
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -37,7 +37,7 @@ public final class TransactionEventFactory {
...
@@ -37,7 +37,7 @@ public final class TransactionEventFactory {
* @return transaction event
* @return transaction event
*/
*/
public
static
TransactionEvent
create
(
final
TCLType
tclType
)
{
public
static
TransactionEvent
create
(
final
TCLType
tclType
)
{
switch
(
Transaction
ContextHolder
.
get
().
getTransactionType
())
{
switch
(
Transaction
TypeHolder
.
get
())
{
case
LOCAL:
case
LOCAL:
return
new
LocalTransactionEvent
(
tclType
);
return
new
LocalTransactionEvent
(
tclType
);
case
XA:
case
XA:
...
...
sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java
浏览文件 @
e1f241cb
...
@@ -21,7 +21,8 @@ import com.google.common.eventbus.AllowConcurrentEvents;
...
@@ -21,7 +21,8 @@ import com.google.common.eventbus.AllowConcurrentEvents;
import
com.google.common.eventbus.Subscribe
;
import
com.google.common.eventbus.Subscribe
;
import
io.shardingsphere.core.util.EventBusInstance
;
import
io.shardingsphere.core.util.EventBusInstance
;
import
io.shardingsphere.transaction.api.ShardingTransactionManager
;
import
io.shardingsphere.transaction.api.ShardingTransactionManager
;
import
io.shardingsphere.transaction.common.TransactionContextHolder
;
import
io.shardingsphere.transaction.api.ShardingTransactionManagerRegistry
;
import
io.shardingsphere.transaction.common.TransactionTypeHolder
;
import
io.shardingsphere.transaction.common.event.TransactionEvent
;
import
io.shardingsphere.transaction.common.event.TransactionEvent
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
...
@@ -49,16 +50,16 @@ public final class TransactionListener {
...
@@ -49,16 +50,16 @@ public final class TransactionListener {
@Subscribe
@Subscribe
@AllowConcurrentEvents
@AllowConcurrentEvents
public
void
listen
(
final
TransactionEvent
transactionEvent
)
throws
SQLException
{
public
void
listen
(
final
TransactionEvent
transactionEvent
)
throws
SQLException
{
ShardingTransactionManager
transactionManager
=
TransactionContextHolder
.
get
().
getTransactionManager
(
);
ShardingTransactionManager
shardingTransactionManager
=
ShardingTransactionManagerRegistry
.
getInstance
().
getShardingTransactionManager
(
TransactionTypeHolder
.
get
()
);
switch
(
transactionEvent
.
getTclType
())
{
switch
(
transactionEvent
.
getTclType
())
{
case
BEGIN:
case
BEGIN:
t
ransactionManager
.
begin
(
transactionEvent
);
shardingT
ransactionManager
.
begin
(
transactionEvent
);
break
;
break
;
case
COMMIT:
case
COMMIT:
t
ransactionManager
.
commit
(
transactionEvent
);
shardingT
ransactionManager
.
commit
(
transactionEvent
);
break
;
break
;
case
ROLLBACK:
case
ROLLBACK:
t
ransactionManager
.
rollback
(
transactionEvent
);
shardingT
ransactionManager
.
rollback
(
transactionEvent
);
break
;
break
;
default
:
default
:
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录