当前位置:网站首页>Transaction rollback and record exception information at the same time
Transaction rollback and record exception information at the same time
2022-07-26 20:49:00 【root_ zhb】
Transaction rollback , Record abnormal information at the same time
demand
When an exception occurs , Rollback the operation on the database , At the same time, insert an exception message into the database .
Realization principle
Start a new business , Perform database operation of abnormal information
Realization
1、 rely on HTTP Resend request
Before throwing an exception , rely on http, Send an asynchronous request , An interface stores exception information , Then the main program throws an exception .
2、 Start a new business , Insert exception information
@Autowired
private DataSourceTransactionManager dstManager;
@Transactional
@Override
public void create(Payment payment) throws Exception {
try {
paymentDao.create(payment);
System.out.println(1 / 0);
} catch (Exception e) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// Here you can add exception thrown information , Does not affect the existing logic
} finally {
// Isolation level of things , Start a new business , It'll be safer .
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
// Get transaction state
TransactionStatus transaction = dstManager.getTransaction(def);
try {
payment.setSerial(" Report an error, Lala Lala ");
paymentDao.create(payment);
dstManager.commit(transaction);
} catch (Exception e) {
dstManager.rollback(transaction);
logger.error(" Temporary table insertion failed :" + e.getMessage(), e);
}
}
}
A way of implementation , The same idea as the above code
@Transactional
@Override
public void create(Payment payment) {
paymentDao.create(payment);
paymentService.newTransCreate(payment);
System.out.println(1 / 0);
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void newTransCreate(Payment payment) {
payment.setSerial(" This is a new error message ");
paymentDao.create(payment);
}
边栏推荐
- It is said that HP / Dell / Microsoft / Amazon are considering transferring some hardware production lines outside the mainland
- Task 2 kaggle diabetes detection
- Easy gene | introduction to macrovirus sequencing technology
- BGP的路由黑洞和防环
- [record of question brushing] 22. bracket generation
- 81.(cesium之家)cesium修改灰色背景(默认蓝色)
- Depthwiseseparableconvolution: depthwise convolution and pointwise convolution
- A super simple neural network code with 5 coordinates for one layer node training
- Bean注入和生命周期
- Chat software project development 2
猜你喜欢

营销与销售文件管理以及工作流程解决方案

Experiment 6 BGP federal comprehensive experiment

Buu brush inscription 4

Chat software project development 2

消息队列——引入的问题:重复消费&顺序消费&分布式事务

Group convolution
![Chapter 2: encounter obstacles! Bypass WAF filtering! [SQL injection attack]](/img/f8/e6991852547a370f4363a2b763e52e.png)
Chapter 2: encounter obstacles! Bypass WAF filtering! [SQL injection attack]

LeetCode链表问题——24.两两交换链表中的结点(一题一文学会链表)

Experiment 5 OSPF comprehensive experiment

QT driving school subject examination system -- from implementation to release
随机推荐
BGP的基本配置和聚合
[Delphi] different platform descriptions of borderstyles of FMX form
twenty million two hundred and twenty thousand seven hundred and twenty-six
单核A7玩转人脸识别,恩智浦“跨界处理器”又玩出新花样!
884. Uncommon words in two sentences - hash table
Software testing - development test content specification (project test template)
Pandonia spirit voxedit creation competition
Solve the horizontal segmentation of iBGP and BGP routing principles
「企业管理」精诚CRM+——一体化管理企业业务流程
员工辞职还得赔偿公司损失?34岁机长辞职被公司索赔1066万
nmap安装和使用
[interview brush 101] dynamic planning 1
Keepalived高可用介绍与配置详解
执行上下文与词法环境
Easycvr device management list page, paging data does not display problem repair
Bean注入和生命周期
BGP routing black hole and anti ring
营销与销售文件管理以及工作流程解决方案
Numpy中ndarray的常见操作
arpspoof 安装和使用