Bug #1397: Revert a previous commit to avoid the problem
Commit 9e4b329791 is reverted and exception
IllegalStateException is cached to launch an OptimisticLockingFailureException.
FEA: ItEr76S04BugFixing
This commit is contained in:
parent
3e1bb46e23
commit
c778b92d5d
3 changed files with 10 additions and 28 deletions
|
|
@ -85,21 +85,14 @@ public class GenericDAOHibernate<E extends BaseEntity,
|
|||
return entityClass;
|
||||
}
|
||||
|
||||
public void save(E entity) throws ValidationException {
|
||||
save(entity, Mode.AUTOMATIC_FLUSH);
|
||||
}
|
||||
|
||||
/**
|
||||
* It's necessary to save and validate later.
|
||||
*
|
||||
* Validate may retrieve the entity from DB and put it into the Session, which can eventually lead to
|
||||
* a NonUniqueObject exception. Save works here to reattach the object as well as saving.
|
||||
*/
|
||||
public void save(E entity, Mode mode) throws ValidationException {
|
||||
public void save(E entity) throws ValidationException {
|
||||
getSession().saveOrUpdate(entity);
|
||||
if (mode == Mode.FLUSH_BEFORE_VALIDATION) {
|
||||
getSession().flush();
|
||||
}
|
||||
entity.validate();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,19 +42,7 @@ public interface IGenericDAO <E, PK extends Serializable>{
|
|||
|
||||
public Class<E> 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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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
|
||||
|
|
@ -63,15 +51,11 @@ public interface IGenericDAO <E, PK extends Serializable>{
|
|||
* executed (if the entity has version control enabled) with the possible
|
||||
* <code>org.springframework.dao.OptimisticLockingFailureException</code>
|
||||
* being thrown.
|
||||
* </p>
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @throws ValidationException
|
||||
* if the entity has some invalid values
|
||||
*/
|
||||
public void save(E entity, Mode mode) throws ValidationException;
|
||||
public void save(E entity) throws ValidationException;
|
||||
|
||||
/**
|
||||
* Unlike <code>save</code>, it does not execute validations.
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import org.libreplan.business.calendars.daos.IBaseCalendarDAO;
|
|||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||
import org.libreplan.business.common.daos.IEntitySequenceDAO;
|
||||
import org.libreplan.business.common.daos.IGenericDAO.Mode;
|
||||
import org.libreplan.business.common.entities.Configuration;
|
||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
||||
import org.libreplan.business.common.entities.EntitySequence;
|
||||
|
|
@ -49,6 +48,7 @@ import org.libreplan.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.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -149,8 +149,13 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
@Transactional
|
||||
public void confirm() {
|
||||
checkEntitySequences();
|
||||
configurationDAO.save(configuration, Mode.FLUSH_BEFORE_VALIDATION);
|
||||
storeAndRemoveEntitySequences();
|
||||
configurationDAO.save(configuration);
|
||||
try {
|
||||
storeAndRemoveEntitySequences();
|
||||
} catch (IllegalStateException e) {
|
||||
throw new OptimisticLockingFailureException(
|
||||
"concurrency problem in entity sequences");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEntitySequences() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue