Skip to content

Commit

Permalink
refact: add Transactional annotation in demo services to get a better…
Browse files Browse the repository at this point in the history
… code style
  • Loading branch information
skyesx committed Sep 16, 2018
1 parent 60684ab commit f36b59d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -17,7 +18,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -31,7 +32,7 @@ public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
return walletPayTccMethodResult;
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -41,6 +42,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -16,7 +17,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public void doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -26,7 +27,7 @@ public void doTryPay(WalletPayRequestVO param) {
}
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -36,6 +37,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -17,7 +18,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -31,7 +32,7 @@ public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
return walletPayTccMethodResult;
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -41,6 +42,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.yiqiniu.easytrans.core.EasyTransFacade;
import com.yiqiniu.easytrans.demos.wallet.api.vo.WalletPayVO.WalletPayRequestVO;
Expand All @@ -17,7 +18,7 @@ public class WalletService {
@Resource
private JdbcTemplate jdbcTemplate;


@Transactional
public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount + ? where user_id = ? and (total_amount - freeze_amount) >= ?;",
param.getPayAmount(),param.getUserId(),param.getPayAmount());
Expand All @@ -31,7 +32,7 @@ public WalletPayResponseVO doTryPay(WalletPayRequestVO param) {
return walletPayTccMethodResult;
}


@Transactional
public void doConfirmPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ?, total_amount = total_amount - ? where user_id = ?;",
param.getPayAmount(),param.getPayAmount(),param.getUserId());
Expand All @@ -41,6 +42,7 @@ public void doConfirmPay(WalletPayRequestVO param) {
}
}

@Transactional
public void doCancelPay(WalletPayRequestVO param) {
int update = jdbcTemplate.update("update `wallet` set freeze_amount = freeze_amount - ? where user_id = ?;",
param.getPayAmount(),param.getUserId());
Expand Down

0 comments on commit f36b59d

Please sign in to comment.