From 78d57f97c00d39ac7d62702ca8fec61669625234 Mon Sep 17 00:00:00 2001 From: guorui Date: Wed, 5 Mar 2025 11:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E6=B3=A8=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/aspectj/TransactionAspect.java | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/openhis-server/core-framework/src/main/java/com/core/framework/aspectj/TransactionAspect.java b/openhis-server/core-framework/src/main/java/com/core/framework/aspectj/TransactionAspect.java index a3b17784..f2756927 100644 --- a/openhis-server/core-framework/src/main/java/com/core/framework/aspectj/TransactionAspect.java +++ b/openhis-server/core-framework/src/main/java/com/core/framework/aspectj/TransactionAspect.java @@ -1,54 +1,54 @@ -package com.core.framework.aspectj; - -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.AfterThrowing; -import org.springframework.stereotype.Component; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.DefaultTransactionDefinition; - -/** - * 事务处理 - */ -@Aspect -@Component -public class TransactionAspect { - - private final PlatformTransactionManager transactionManager; - private TransactionStatus transactionStatus; - - public TransactionAspect(PlatformTransactionManager transactionManager) { - this.transactionManager = transactionManager; - } - - @Before("@annotation(org.springframework.web.bind.annotation.PostMapping) || " + - "@annotation(org.springframework.web.bind.annotation.GetMapping) || " + - "@annotation(org.springframework.web.bind.annotation.PutMapping) || " + - "@annotation(org.springframework.web.bind.annotation.DeleteMapping)") - public void beginTransaction() { - transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); - } - - @AfterReturning("@annotation(org.springframework.web.bind.annotation.PostMapping) || " + - "@annotation(org.springframework.web.bind.annotation.GetMapping) || " + - "@annotation(org.springframework.web.bind.annotation.PutMapping) || " + - "@annotation(org.springframework.web.bind.annotation.DeleteMapping)") - public void commitTransaction() { - if (transactionStatus != null && !transactionStatus.isCompleted()) { - transactionManager.commit(transactionStatus); - } - } - - @AfterThrowing(pointcut = "@annotation(org.springframework.web.bind.annotation.PostMapping) || " + - "@annotation(org.springframework.web.bind.annotation.GetMapping) || " + - "@annotation(org.springframework.web.bind.annotation.PutMapping) || " + - "@annotation(org.springframework.web.bind.annotation.DeleteMapping)", - throwing = "ex") - public void rollbackTransaction(Exception ex) { - if (transactionStatus != null && !transactionStatus.isCompleted()) { - transactionManager.rollback(transactionStatus); - } - } -} +// package com.core.framework.aspectj; +// +// import org.aspectj.lang.annotation.Aspect; +// import org.aspectj.lang.annotation.Before; +// import org.aspectj.lang.annotation.AfterReturning; +// import org.aspectj.lang.annotation.AfterThrowing; +// import org.springframework.stereotype.Component; +// import org.springframework.transaction.PlatformTransactionManager; +// import org.springframework.transaction.TransactionStatus; +// import org.springframework.transaction.support.DefaultTransactionDefinition; +// +/// ** +// * 事务处理 +// */ +// @Aspect +// @Component +// public class TransactionAspect { +// +// private final PlatformTransactionManager transactionManager; +// private TransactionStatus transactionStatus; +// +// public TransactionAspect(PlatformTransactionManager transactionManager) { +// this.transactionManager = transactionManager; +// } +// +// @Before("@annotation(org.springframework.web.bind.annotation.PostMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.GetMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.PutMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.DeleteMapping)") +// public void beginTransaction() { +// transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); +// } +// +// @AfterReturning("@annotation(org.springframework.web.bind.annotation.PostMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.GetMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.PutMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.DeleteMapping)") +// public void commitTransaction() { +// if (transactionStatus != null && !transactionStatus.isCompleted()) { +// transactionManager.commit(transactionStatus); +// } +// } +// +// @AfterThrowing(pointcut = "@annotation(org.springframework.web.bind.annotation.PostMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.GetMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.PutMapping) || " + +// "@annotation(org.springframework.web.bind.annotation.DeleteMapping)", +// throwing = "ex") +// public void rollbackTransaction(Exception ex) { +// if (transactionStatus != null && !transactionStatus.isCompleted()) { +// transactionManager.rollback(transactionStatus); +// } +// } +// }