Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
620e6237
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,发现更多精彩内容 >>
提交
620e6237
编写于
2月 19, 2019
作者:
C
cherrylzhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor spring-namespace-orche-mybatis.
上级
4a205b09
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
80 deletion
+8
-80
sharding-jdbc-example/spring-namespace-orche-example/spring-namespace-orche-mybatis-example/src/main/java/io/shardingsphere/example/spring/namespace/mybatis/orche/SpringNamespaceExample.java
...pring/namespace/mybatis/orche/SpringNamespaceExample.java
+4
-31
sharding-jdbc-example/spring-namespace-orche-example/spring-namespace-orche-mybatis-example/src/main/java/io/shardingsphere/example/spring/namespace/mybatis/orche/SpringNamespaceTransactionExample.java
...pace/mybatis/orche/SpringNamespaceTransactionExample.java
+4
-49
未找到文件。
sharding-jdbc-example/spring-namespace-orche-example/spring-namespace-orche-mybatis-example/src/main/java/io/shardingsphere/example/spring/namespace/mybatis/orche/SpringNamespaceExample.java
浏览文件 @
620e6237
...
...
@@ -17,6 +17,7 @@
package
io.shardingsphere.example.spring.namespace.mybatis.orche
;
import
io.shardingsphere.example.repository.api.senario.AnnotationCommonServiceScenario
;
import
io.shardingsphere.example.repository.api.service.CommonService
;
import
io.shardingsphere.example.repository.mybatis.service.SpringPojoService
;
import
io.shardingsphere.example.type.RegistryCenterType
;
...
...
@@ -32,9 +33,6 @@ public class SpringNamespaceExample {
// private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
// private static ShardingType shardingType = ShardingType.SHARDING_MASTER_SLAVE;
// private static boolean isRangeSharding = true;
private
static
boolean
isRangeSharding
=
false
;
private
static
RegistryCenterType
registryCenterType
=
RegistryCenterType
.
ZOOKEEPER
;
// private static RegistryCenterType registryCenterType = RegistryCenterType.ETCD;
...
...
@@ -42,7 +40,7 @@ public class SpringNamespaceExample {
// private static boolean loadConfigFromRegCenter = true;
public
static
void
main
(
final
String
[]
args
)
{
try
(
ConfigurableApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
isRangeSharding
?
getApplicationFileRange
()
:
getApplicationFilePrecise
()))
{
try
(
ConfigurableApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
getApplicationFilePrecise
()))
{
process
(
applicationContext
);
}
}
...
...
@@ -64,35 +62,10 @@ public class SpringNamespaceExample {
}
}
private
static
String
getApplicationFileRange
()
{
switch
(
shardingType
)
{
case
SHARDING_DATABASES:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-databases-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
SHARDING_TABLES:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-tables-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
SHARDING_DATABASES_AND_TABLES:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-databases-tables-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
MASTER_SLAVE:
return
String
.
format
(
"META-INF/%s/%s/application-master-slave.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
SHARDING_MASTER_SLAVE:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-master-slave-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
default
:
throw
new
UnsupportedOperationException
(
shardingType
.
name
());
}
}
private
static
void
process
(
final
ConfigurableApplicationContext
applicationContext
)
{
CommonService
commonService
=
getCommonService
(
applicationContext
);
commonService
.
initEnvironment
();
commonService
.
processSuccess
();
try
{
commonService
.
processFailure
();
}
catch
(
final
Exception
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
commonService
.
printData
();
}
finally
{
commonService
.
cleanEnvironment
();
}
AnnotationCommonServiceScenario
scenario
=
new
AnnotationCommonServiceScenario
(
commonService
);
scenario
.
process
();
}
private
static
CommonService
getCommonService
(
final
ConfigurableApplicationContext
applicationContext
)
{
...
...
sharding-jdbc-example/spring-namespace-orche-example/spring-namespace-orche-mybatis-example/src/main/java/io/shardingsphere/example/spring/namespace/mybatis/orche/SpringNamespaceTransactionExample.java
浏览文件 @
620e6237
...
...
@@ -17,11 +17,11 @@
package
io.shardingsphere.example.spring.namespace.mybatis.orche
;
import
io.shardingsphere.example.repository.api.senario.AnnotationTractionServiceScenario
;
import
io.shardingsphere.example.repository.api.service.TransactionService
;
import
io.shardingsphere.example.repository.mybatis.service.SpringPojoTransactionService
;
import
io.shardingsphere.example.type.RegistryCenterType
;
import
io.shardingsphere.example.type.ShardingType
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
...
...
@@ -33,9 +33,6 @@ public class SpringNamespaceTransactionExample {
// private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
// private static ShardingType shardingType = ShardingType.SHARDING_MASTER_SLAVE;
// private static boolean isRangeSharding = true;
private
static
boolean
isRangeSharding
=
false
;
private
static
RegistryCenterType
registryCenterType
=
RegistryCenterType
.
ZOOKEEPER
;
// private static RegistryCenterType registryCenterType = RegistryCenterType.ETCD;
...
...
@@ -43,7 +40,7 @@ public class SpringNamespaceTransactionExample {
// private static boolean loadConfigFromRegCenter = true;
public
static
void
main
(
final
String
[]
args
)
{
try
(
ConfigurableApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
isRangeSharding
?
getApplicationFileRange
()
:
getApplicationFilePrecise
()))
{
try
(
ConfigurableApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
getApplicationFilePrecise
()))
{
process
(
applicationContext
);
}
}
...
...
@@ -65,52 +62,10 @@ public class SpringNamespaceTransactionExample {
}
}
private
static
String
getApplicationFileRange
()
{
switch
(
shardingType
)
{
case
SHARDING_DATABASES:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-databases-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
SHARDING_TABLES:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-tables-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
SHARDING_DATABASES_AND_TABLES:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-databases-tables-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
MASTER_SLAVE:
return
String
.
format
(
"META-INF/%s/%s/application-master-slave.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
case
SHARDING_MASTER_SLAVE:
return
String
.
format
(
"META-INF/%s/%s/application-sharding-master-slave-range.xml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
default
:
throw
new
UnsupportedOperationException
(
shardingType
.
name
());
}
}
private
static
void
process
(
final
ConfigurableApplicationContext
applicationContext
)
{
TransactionService
transactionService
=
getTransactionService
(
applicationContext
);
transactionService
.
initEnvironment
();
transactionService
.
processSuccess
();
processFailureSingleTransaction
(
transactionService
,
TransactionType
.
LOCAL
);
processFailureSingleTransaction
(
transactionService
,
TransactionType
.
XA
);
processFailureSingleTransaction
(
transactionService
,
TransactionType
.
BASE
);
processFailureSingleTransaction
(
transactionService
,
TransactionType
.
LOCAL
);
transactionService
.
cleanEnvironment
();
}
private
static
void
processFailureSingleTransaction
(
final
TransactionService
transactionService
,
final
TransactionType
type
)
{
try
{
switch
(
type
)
{
case
LOCAL:
transactionService
.
processFailureWithLocal
();
break
;
case
XA:
transactionService
.
processFailureWithXA
();
break
;
case
BASE:
transactionService
.
processFailureWithBase
();
break
;
default
:
}
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
transactionService
.
printData
();
}
AnnotationTractionServiceScenario
scenario
=
new
AnnotationTractionServiceScenario
(
transactionService
);
scenario
.
process
();
}
private
static
TransactionService
getTransactionService
(
final
ConfigurableApplicationContext
applicationContext
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录