Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
remit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gechengyang
remit
Commits
1eab7759
Commit
1eab7759
authored
Dec 17, 2018
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
事务管理
parent
e7e39cee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
6 deletions
+42
-6
DbUtil.java
src/main/java/com/brilliance/remit/common/util/DbUtil.java
+15
-0
RemitServiceImp.java
...ava/com/brilliance/remit/service/imp/RemitServiceImp.java
+22
-5
init.sql
src/main/resources/init.sql
+0
-0
spring-applicationContext.xml
src/main/resources/spring-applicationContext.xml
+5
-1
No files found.
src/main/java/com/brilliance/remit/common/util/DbUtil.java
0 → 100644
View file @
1eab7759
package
com
.
brilliance
.
remit
.
common
.
util
;
import
org.springframework.transaction.TransactionDefinition
;
import
org.springframework.transaction.support.DefaultTransactionDefinition
;
public
class
DbUtil
{
public
static
DefaultTransactionDefinition
getDbDefinition
()
{
DefaultTransactionDefinition
def
=
new
DefaultTransactionDefinition
();
// 设置事务隔离级别,开启新事务
def
.
setPropagationBehavior
(
TransactionDefinition
.
PROPAGATION_REQUIRES_NEW
);
return
def
;
}
}
src/main/java/com/brilliance/remit/service/imp/RemitServiceImp.java
View file @
1eab7759
package
com
.
brilliance
.
remit
.
service
.
imp
;
package
com
.
brilliance
.
remit
.
service
.
imp
;
import
javax.annotation.Resource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.TransactionStatus
;
import
com.brilliance.remit.common.util.DbUtil
;
import
com.brilliance.remit.db.dao.CpdMapper
;
import
com.brilliance.remit.db.dao.CpdMapper
;
import
com.brilliance.remit.db.dao.TrnMapper
;
import
com.brilliance.remit.db.dao.TrnMapper
;
import
com.brilliance.remit.db.model.Cpd
;
import
com.brilliance.remit.db.model.Cpd
;
...
@@ -15,15 +20,27 @@ public class RemitServiceImp implements RemitService {
...
@@ -15,15 +20,27 @@ public class RemitServiceImp implements RemitService {
@Autowired
@Autowired
private
TrnMapper
trnMapper
;
private
TrnMapper
trnMapper
;
private
static
int
i
=
10
;
private
static
int
i
=
10
;
@Resource
(
name
=
"txManager"
)
private
DataSourceTransactionManager
transactionManager
;
@Override
@Override
public
void
test
()
{
public
void
test
()
{
// 事务操作
TransactionStatus
status
=
transactionManager
.
getTransaction
(
DbUtil
.
getDbDefinition
());
try
{
Cpd
cpd
=
new
Cpd
();
cpd
.
setINR
(
String
.
valueOf
(
i
));
i
++;
cpdMapper
.
insert
(
cpd
);
transactionManager
.
commit
(
status
);
cpdMapper
.
insert
(
cpd
);
System
.
out
.
println
(
"insert cpd success !!!"
);
transactionManager
.
commit
(
status
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
transactionManager
.
rollback
(
status
);
}
Cpd
cpd
=
new
Cpd
();
cpd
.
setINR
(
String
.
valueOf
(
i
));
i
++;
cpdMapper
.
insert
(
cpd
);
System
.
out
.
println
(
"insert cpd success !!!"
);
}
}
}
}
src/main/resources/init.sql
View file @
1eab7759
This diff is collapsed.
Click to expand it.
src/main/resources/spring-applicationContext.xml
View file @
1eab7759
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<!-- 自动扫描注解的bean -->
<!-- 自动扫描注解的bean -->
<context:component-scan
base-package=
"com.brilliance.remit.service"
/>
<context:component-scan
base-package=
"com.brilliance.remit.service"
/>
<!-- 配置数据源 -->
<!-- 配置数据源 -->
<bean
id=
"dataSource"
class=
"org.apache.commons.dbcp.BasicDataSource"
>
<bean
id=
"dataSource"
class=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method=
"close"
>
<property
name=
"driverClassName"
value=
"oracle.jdbc.driver.OracleDriver"
/>
<property
name=
"driverClassName"
value=
"oracle.jdbc.driver.OracleDriver"
/>
<property
name=
"url"
value=
"jdbc:oracle:thin:@172.17.2.4:1521:orcl"
/>
<property
name=
"url"
value=
"jdbc:oracle:thin:@172.17.2.4:1521:orcl"
/>
<property
name=
"username"
value=
"xxremit"
/>
<property
name=
"username"
value=
"xxremit"
/>
...
@@ -30,6 +30,10 @@
...
@@ -30,6 +30,10 @@
<property
name=
"mapperLocations"
value=
"classpath*:com/brilliance/remit/db/mapper/**/*.xml"
/>
<property
name=
"mapperLocations"
value=
"classpath*:com/brilliance/remit/db/mapper/**/*.xml"
/>
</bean>
</bean>
<!-- 事务管理器 -->
<bean
id=
"txManager"
class=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
<property
name=
"dataSource"
ref=
"dataSource"
/>
</bean>
<!-- 配置mapper对应的dao和mybatis工厂 -->
<!-- 配置mapper对应的dao和mybatis工厂 -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment