This is an automated email from the git hooks/post-receive script. New commit to branch feature/7470_mise_en_place_de_la_date_de_derniere_mise_a_jour in repository tutti. See http://git.codelutin.com/tutti.git commit 46beb5bc612fcfc15db8ebff5e20a4ee04cf6e93 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Dec 27 10:58:00 2015 +0100 Amélioration de l'exception de concurrence --- .../service/ConcurrentModificationException.java | 31 +++++++++++----- .../ird/observe/services/ObserveServiceTopia.java | 41 +++++++++++----------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/ConcurrentModificationException.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/ConcurrentModificationException.java index 8d70181..f25fc4d 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/service/ConcurrentModificationException.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/ConcurrentModificationException.java @@ -7,20 +7,33 @@ import java.util.Date; */ public class ConcurrentModificationException extends RuntimeException { - protected final Date lastUpdate; + private static final long serialVersionUID = -4964630055605654415L; - protected final Date currentUpdate; + /** + * Entity id. + */ + protected final String id; + /** + * Last update date stored in database. + */ + protected final Date lastUpdateDate; - public ConcurrentModificationException(Date lastUpdate, Date currentUpdate) { - this.lastUpdate = lastUpdate; - this.currentUpdate = currentUpdate; + /** + * Last update date coming from entity to store. + */ + protected final Date currentUpdateDate; + + public ConcurrentModificationException(String id, Date lastUpdateDate, Date currentUpdateDate) { + this.id = id; + this.lastUpdateDate = lastUpdateDate; + this.currentUpdateDate = currentUpdateDate; } - public Date getLastUpdate() { - return lastUpdate; + public Date getLastUpdateDate() { + return lastUpdateDate; } - public Date getCurrentUpdate() { - return currentUpdate; + public Date getCurrentUpdateDate() { + return currentUpdateDate; } } diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceTopia.java index e81b0c6..c192c5c 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/ObserveServiceTopia.java @@ -59,7 +59,6 @@ import fr.ird.observe.services.service.DataSourceService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaDao; -import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.topia.replication.TopiaReplicationService; import org.nuiton.topia.replication.model.ReplicationModel; @@ -87,7 +86,7 @@ public abstract class ObserveServiceTopia implements ObserveService { protected ObserveServiceContextTopia serviceContext; - public static <D extends DataDto, E extends TopiaEntity> Class<E> getDataEntityType(Class<D> dtoType) { + public static <D extends DataDto, E extends ObserveEntity> Class<E> getDataEntityType(Class<D> dtoType) { Class<E> dataEntityType = BINDER_ENGINE.getDataEntityType(dtoType); return dataEntityType; } @@ -115,7 +114,7 @@ public abstract class ObserveServiceTopia implements ObserveService { return serviceContext.getApplicationLocale(); } - public <D extends IdDto, E extends TopiaEntity> E loadEntity(Class<D> dtoType, String id) { + public <D extends IdDto, E extends ObserveEntity> E loadEntity(Class<D> dtoType, String id) { if (log.isInfoEnabled()) { log.info("Load entity: " + id); } @@ -127,7 +126,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } } - public <E extends TopiaEntity> E newEntity(Class<E> entityType) { + public <E extends ObserveEntity> E newEntity(Class<E> entityType) { ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext(); TopiaDao<E> dao = persistenceContext.getDao(entityType); E entity = dao.newInstance(); @@ -138,7 +137,7 @@ public abstract class ObserveServiceTopia implements ObserveService { return serviceContext.getTopiaPersistenceContext(); } - protected <E extends TopiaEntity> List<E> loadEntities(Class<E> entityType) { + protected <E extends ObserveEntity> List<E> loadEntities(Class<E> entityType) { ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext(); TopiaDao<E> dao = persistenceContext.getDao(entityType); List<E> entities = dao.findAll(); @@ -192,7 +191,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } - protected <E extends TopiaEntity, D extends DataDto> Form<D> dataEntityToForm(Class<D> dtoType, + protected <E extends ObserveEntity, D extends DataDto> Form<D> dataEntityToForm(Class<D> dtoType, E entity, ReferenceSetRequestDefinitions referentialRequestDefinition) { @@ -216,7 +215,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } - protected <E extends TopiaEntity, D extends DataDto> void copyDataDtoToEntity(D dto, E entity) { + protected <E extends ObserveEntity, D extends DataDto> void copyDataDtoToEntity(D dto, E entity) { BINDER_ENGINE.copyDataDtoToEntity(serviceContext.getReferentialLocale(), dto, entity); @@ -228,7 +227,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } - protected <E extends TopiaEntity, D extends DataDto> E loadOrCreateEntityFromDataDto(D dto) { + protected <E extends ObserveEntity, D extends DataDto> E loadOrCreateEntityFromDataDto(D dto) { Class<D> dtoType = (Class<D>) dto.getClass(); @@ -264,17 +263,17 @@ public abstract class ObserveServiceTopia implements ObserveService { return entity; } - protected <E extends ObserveEntity, D extends IdDto & FollowedUpdateDto> void checkLastUpdateDate(E entity, D dto) { + protected <E extends ObserveEntity, D extends FollowedUpdateDto> void checkLastUpdateDate(E entity, D dto) { - if (dto.isPersisted()) { + if (entity.isPersisted()) { - Date lasUpdate = entity.getLastUpdateDate(); + Date lastUpdateDate = entity.getLastUpdateDate(); - Date currentUpdate = dto.getLastUpdate(); + Date currentUpdateDate = dto.getLastUpdate(); - if (lasUpdate.after(currentUpdate)) { + if (lastUpdateDate.after(currentUpdateDate)) { - throw new ConcurrentModificationException(lasUpdate, currentUpdate); + throw new ConcurrentModificationException(entity.getTopiaId(), lastUpdateDate, currentUpdateDate); } @@ -397,7 +396,7 @@ public abstract class ObserveServiceTopia implements ObserveService { try (ObserveTopiaPersistenceContext sourcePersistenceContext = sourceTopiaApplicationContext.newPersistenceContext()) { - TopiaEntity e = sourcePersistenceContext.findByTopiaId(id); + ObserveEntity e = sourcePersistenceContext.findByTopiaId(id); if (e instanceof TripLongline) { @@ -431,16 +430,16 @@ public abstract class ObserveServiceTopia implements ObserveService { } } - protected <D extends DataDto, E extends TopiaEntity> D loadEntityToDataDto(Class<D> dtoType, String id) { + protected <D extends DataDto, E extends ObserveEntity> D loadEntityToDataDto(Class<D> dtoType, String id) { E entity = loadEntity(dtoType, id); - DataBinderSupport<TopiaEntity, D> binder = getDataBinder(dtoType); + DataBinderSupport<ObserveEntity, D> binder = getDataBinder(dtoType); D dto = binder.toData(getReferentialLocale(), entity); return dto; } - protected <E extends TopiaEntity> boolean existsEntity(Class<E> entityType, String id) { + protected <E extends ObserveEntity> boolean existsEntity(Class<E> entityType, String id) { ObserveTopiaPersistenceContext persistenceContext = serviceContext.getTopiaPersistenceContext(); TopiaDao<E> dao = persistenceContext.getDao(entityType); return dao.forTopiaIdEquals(id).exists(); @@ -453,7 +452,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } - protected <D extends DataDto> DataReference<D> toReference(TopiaEntity entity) { + protected <D extends DataDto> DataReference<D> toReference(ObserveEntity entity) { DataReference<D> reference = BinderEngine.get().transformEntityToDataReferenceDto(getReferentialLocale(), entity); return reference; @@ -461,7 +460,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } - protected <D extends DataDto, E extends TopiaEntity> DataReferenceSet<D> toDataReferenceSet(Class<D> dtoType, List<E> allStubByTripId) { + protected <D extends DataDto, E extends ObserveEntity> DataReferenceSet<D> toDataReferenceSet(Class<D> dtoType, List<E> allStubByTripId) { DataBinderSupport<E, D> binder = getDataBinder(dtoType); @@ -497,7 +496,7 @@ public abstract class ObserveServiceTopia implements ObserveService { } - protected <D extends DataDto, E extends TopiaEntity> DataBinderSupport<E, D> getDataBinder(Class<D> dtoType) { + protected <D extends DataDto, E extends ObserveEntity> DataBinderSupport<E, D> getDataBinder(Class<D> dtoType) { DataBinderSupport<E, D> reference = BINDER_ENGINE.getDataBinder(dtoType); return reference; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.