From 9e4b329791f42a32b9596bf35fcff06005d6380e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Thu, 26 May 2011 19:55:43 +0200 Subject: [PATCH] [Bug #954] Fix bug Allow to do flush before doing validations, so the optimist locking exceptions don't happen at validation phase. When validating, the exceptions are wraped, so the optimist locking failure can't be easily seen. FEA: ItEr74S04BugFixing --- .../common/daos/GenericDAOHibernate.java | 9 ++++++++- .../business/common/daos/IGenericDAO.java | 19 ++++++++++++++++++- .../web/common/ConfigurationModel.java | 13 +++---------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/GenericDAOHibernate.java b/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/GenericDAOHibernate.java index a6840f5a5..bba34374d 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/GenericDAOHibernate.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/GenericDAOHibernate.java @@ -84,14 +84,21 @@ public class GenericDAOHibernate{ public Class getEntityClass(); + public enum Mode { + FLUSH_BEFORE_VALIDATION, AUTOMATIC_FLUSH; + } + /** + * It saves with automatic flush + * + * @see #save(Object, Mode) + */ + public void save(E entity) throws ValidationException; + + /** + *

* It inserts the object passed as a parameter in the ORM session, planning * it for updating (even though it is not modified before or after the call * to this method) or insertion, depending if it is was detached or @@ -51,10 +63,15 @@ public interface IGenericDAO { * executed (if the entity has version control enabled) with the possible * org.springframework.dao.OptimisticLockingFailureException * being thrown. + *

+ *

+ * + *

+ * * @throws ValidationException * if the entity has some invalid values */ - public void save(E entity) throws ValidationException; + public void save(E entity, Mode mode) throws ValidationException; /** * Unlike save, it does not execute validations. diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java index 771226ed3..4145fb666 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ConfigurationModel.java @@ -25,7 +25,6 @@ import static org.navalplanner.web.I18nHelper._; import java.util.ArrayList; import java.util.Collection; -import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -36,6 +35,7 @@ import org.navalplanner.business.calendars.daos.IBaseCalendarDAO; import org.navalplanner.business.calendars.entities.BaseCalendar; import org.navalplanner.business.common.daos.IConfigurationDAO; import org.navalplanner.business.common.daos.IEntitySequenceDAO; +import org.navalplanner.business.common.daos.IGenericDAO.Mode; import org.navalplanner.business.common.entities.Configuration; import org.navalplanner.business.common.entities.EntityNameEnum; import org.navalplanner.business.common.entities.EntitySequence; @@ -48,7 +48,6 @@ import org.navalplanner.web.common.concurrentdetection.OnConcurrentModification; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; -import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -140,15 +139,9 @@ public class ConfigurationModel implements IConfigurationModel { @Override @Transactional public void confirm() { - checkEntitySequences(); - try { - configurationDAO.save(configuration); - storeAndRemoveEntitySequences(); - } catch (HibernateOptimisticLockingFailureException e) { - throw new ConcurrentModificationException( - _("Some entity sequence was created during the configuration process, it is impossible to update entity sequence table. Please, try again later")); - } + configurationDAO.save(configuration, Mode.FLUSH_BEFORE_VALIDATION); + storeAndRemoveEntitySequences(); } private void checkEntitySequences() {