galovics commented on code in PR #5143:
URL: https://github.com/apache/fineract/pull/5143#discussion_r2495683181


##########
fineract-core/src/main/java/org/apache/fineract/infrastructure/core/aop/FlushModeAspect.java:
##########
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.core.aop;
+
+import jakarta.persistence.FlushModeType;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.infrastructure.core.annotation.WithFlushMode;
+import org.apache.fineract.infrastructure.core.persistence.FlushModeHandler;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * Aspect that handles the @WithFlushMode annotation to manage JPA flush mode 
around method execution.
+ */
+@Aspect
+@Component
+@RequiredArgsConstructor
+public class FlushModeAspect {
+
+    private final FlushModeHandler flushModeHandler;
+
+    @Around("@within(withFlushMode) || @annotation(withFlushMode)")
+    public Object manageFlushMode(ProceedingJoinPoint joinPoint, WithFlushMode 
withFlushMode) {

Review Comment:
   I think there's one thing missing from this. Whether the annotation is 
applied to a class/method which is inside a running transaction (IIRC you can 
use the TransactionSynchronizationManager to check this).
   
   Also, one thing that comes to my mind when combining these kind of things 
(Transactional and this annotation) is the ordering.
   
   You need to make sure the ordering of this aspect is lower than the 
transactional annotation's, otherwise you might apply this first then the tx 
annotation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to