Keep transaction simplication

This commit is contained in:
Paulo Gustavo Veiga 2023-11-19 00:31:41 -08:00
parent 61c691fc82
commit 480fd49fd0
8 changed files with 38 additions and 112 deletions

View File

@ -1,7 +1,12 @@
package com.wisemapping.config; package com.wisemapping.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.interceptor.TransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionInterceptor;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@ -11,8 +16,12 @@ import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc @EnableWebMvc
@Configuration @Configuration
@EnableTransactionManagement
public class AppConfig { public class AppConfig {
@Autowired
TransactionManager txManager;
@Bean @Bean
HandlerExceptionResolver errorHandler() { HandlerExceptionResolver errorHandler() {
final SimpleMappingExceptionResolver result = new SimpleMappingExceptionResolver(); final SimpleMappingExceptionResolver result = new SimpleMappingExceptionResolver();

View File

@ -1,38 +0,0 @@
/*
* Copyright [2022] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* 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 com.wisemapping.service;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
public class HibernateAppListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent ce) {
try {
Class.forName("tomcatJndi.HibernateUtil").newInstance();
} catch (Exception e) {}
}
/* Application Shutdown Event */
public void contextDestroyed(ServletContextEvent ce)
{ }
}

View File

@ -23,17 +23,20 @@ import com.wisemapping.model.Label;
import com.wisemapping.model.User; import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@Service("labelService")
@Transactional(propagation = Propagation.REQUIRED)
public class LabelServiceImpl implements LabelService { public class LabelServiceImpl implements LabelService {
@Autowired
private LabelManager labelManager; private LabelManager labelManager;
public void setLabelManager(LabelManager labelManager) {
this.labelManager = labelManager;
}
@Override @Override
public void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException { public void addLabel(@NotNull final Label label, @NotNull final User user) throws WiseMappingException {

View File

@ -27,7 +27,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Calendar; import java.util.Calendar;
@ -35,8 +39,10 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@Service("mindmapService")
@Transactional(propagation = Propagation.REQUIRED)
public class MindmapServiceImpl public class MindmapServiceImpl
implements MindmapService { implements MindmapService {
@Autowired @Autowired
@ -49,6 +55,8 @@ public class MindmapServiceImpl
@Autowired @Autowired
private NotificationService notificationService; private NotificationService notificationService;
@Value("${admin.user}")
private String adminUser; private String adminUser;
final private LockManager lockManager; final private LockManager lockManager;

View File

@ -33,18 +33,31 @@ import com.wisemapping.util.VelocityEngineUtils;
import com.wisemapping.util.VelocityEngineWrapper; import com.wisemapping.util.VelocityEngineWrapper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
@Service("userService")
@Transactional(propagation = Propagation.REQUIRED)
public class UserServiceImpl public class UserServiceImpl
implements UserService { implements UserService {
@Autowired
private UserManager userManager; private UserManager userManager;
@Autowired
private MindmapService mindmapService; private MindmapService mindmapService;
@Autowired
private NotificationService notificationService; private NotificationService notificationService;
@Autowired
private MessageSource messageSource; private MessageSource messageSource;
@Autowired
private VelocityEngineWrapper velocityEngineWrapper; private VelocityEngineWrapper velocityEngineWrapper;
@Autowired
private GoogleService googleService; private GoogleService googleService;
@Override @Override

View File

@ -44,9 +44,6 @@
- WebApplicationContextUtils.getWebApplicationContext(servletContext). - WebApplicationContextUtils.getWebApplicationContext(servletContext).
--> -->
<listener>
<listener-class>com.wisemapping.service.HibernateAppListener</listener-class>
</listener>
<listener> <listener>
<listener-class>com.wisemapping.listener.UnlockOnExpireListener</listener-class> <listener-class>com.wisemapping.listener.UnlockOnExpireListener</listener-class>
</listener> </listener>

View File

@ -35,19 +35,4 @@
<property name="nestedTransactionAllowed" value="true"/> <property name="nestedTransactionAllowed" value="true"/>
</bean> </bean>
<!-- Hibernate Template Definition -->
<bean id="txAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource" ref="txAttributes"/>
</bean>
</beans> </beans>

View File

@ -30,61 +30,10 @@
<property name="callbackUrl" value="${security.oauth2.google.callbackUrl}"/> <property name="callbackUrl" value="${security.oauth2.google.callbackUrl}"/>
</bean> </bean>
<bean id="userServiceTarget" class="com.wisemapping.service.UserServiceImpl">
<property name="userManager" ref="userManager"/>
<property name="mindmapService" ref="mindMapServiceTarget"/>
<property name="notificationService" ref="notificationService"/>
<property name="messageSource" ref="messageSource"/>
<property name="velocityEngineWrapper" ref="velocityEngineWrapper"/>
<property name="googleService" ref="googleService"/>
</bean>
<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="userServiceTarget"/>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="mindMapServiceTarget" class="com.wisemapping.service.MindmapServiceImpl">
<property name="mindmapManager" ref="mindmapManager"/>
<property name="userService" ref="userService"/>
<property name="notificationService" ref="notificationService"/>
<property name="adminUser" value="${admin.user}"/>
</bean>
<bean id="recaptchaService" class="com.wisemapping.service.RecaptchaService"> <bean id="recaptchaService" class="com.wisemapping.service.RecaptchaService">
<property name="recaptchaSecret" value="${google.recaptcha2.secretKey}"/> <property name="recaptchaSecret" value="${google.recaptcha2.secretKey}"/>
</bean> </bean>
<bean id="mindmapService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="com.wisemapping.service.MindmapService"/>
<property name="interceptorNames">
<list>
<value>txInterceptor</value>
</list>
</property>
<property name="target" ref="mindMapServiceTarget"/>
</bean>
<bean id="labelServiceTarget" class="com.wisemapping.service.LabelServiceImpl">
<property name="labelManager" ref="labelManager"/>
</bean>
<bean id="labelService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="labelServiceTarget"/>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.smtp.host}"/> <property name="host" value="${mail.smtp.host}"/>
<property name="port" value="${mail.smtp.port}"/> <property name="port" value="${mail.smtp.port}"/>