Browse Source

DATACMNS-901 - AbstractMappingContext publishes entity added events outside the write lock.

Previously, the publication of the event that indicated a PersistentEntity having been added to it took place before the write lock over the entities had been released. We now keep the lock smaller and publish the addition event *after* the lock has been released.
pull/347/head
Oliver Gierke 8 years ago
parent
commit
efdfee50fe
  1. 17
      src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

17
src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

@ -301,12 +301,13 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
} }
Class<?> type = typeInformation.getType(); Class<?> type = typeInformation.getType();
E entity = null;
try { try {
write.lock(); write.lock();
final E entity = createPersistentEntity(typeInformation); entity = createPersistentEntity(typeInformation);
// Eagerly cache the entity as we might have to find it during recursive lookups. // Eagerly cache the entity as we might have to find it during recursive lookups.
persistentEntities.put(typeInformation, entity); persistentEntities.put(typeInformation, entity);
@ -331,18 +332,18 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
throw e; throw e;
} }
// Inform listeners
if (null != applicationEventPublisher) {
applicationEventPublisher.publishEvent(new MappingContextEvent<E, P>(this, entity));
}
return entity;
} catch (BeansException e) { } catch (BeansException e) {
throw new MappingException(e.getMessage(), e); throw new MappingException(e.getMessage(), e);
} finally { } finally {
write.unlock(); write.unlock();
} }
// Inform listeners
if (applicationEventPublisher != null && entity != null) {
applicationEventPublisher.publishEvent(new MappingContextEvent<E, P>(this, entity));
}
return entity;
} }
/* /*

Loading…
Cancel
Save