DATAREST-723 - PropertyMappings now get eagerly initialized.

Switched to eager initialization of PropertyMappings to avoid potential ConcurrentModificationException.
This commit is contained in:
Oliver Gierke
2015-12-16 16:02:14 +01:00
parent 5c1b731bfa
commit 8c5bf9802f
3 changed files with 7 additions and 14 deletions

View File

@@ -49,19 +49,14 @@ class MappingResourceMetadata extends TypeBasedCollectionResourceMapping impleme
super(entity.getType());
this.entity = entity;
this.propertyMappings = new PropertyMappings(resourceMappings);
RestResource annotation = entity.findAnnotation(RestResource.class);
this.explicitlyExported = annotation != null && annotation.exported();
}
public MappingResourceMetadata init() {
this.entity = entity;
this.entity.doWithAssociations(propertyMappings);
this.entity.doWithProperties(propertyMappings);
return this;
RestResource annotation = entity.findAnnotation(RestResource.class);
this.explicitlyExported = annotation != null && annotation.exported();
}
/*

View File

@@ -99,8 +99,6 @@ public class PersistentEntitiesResourceMappings implements ResourceMappings {
mappingMetadata = new MappingResourceMetadata(entity, this);
mappingCache.put(type, mappingMetadata);
mappingMetadata.init();
return mappingMetadata;
}

View File

@@ -41,9 +41,9 @@ public class MappingResourceMetadataUnitTests {
MongoMappingContext context = new MongoMappingContext();
MongoPersistentEntity<?> entity = context.getPersistentEntity(Entity.class);
ResourceMappings resourceMappings = new PersistentEntitiesResourceMappings(new PersistentEntities(
Arrays.asList(context)));
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings).init();
ResourceMappings resourceMappings = new PersistentEntitiesResourceMappings(
new PersistentEntities(Arrays.asList(context)));
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings);
/**
* @see DATAREST-514
@@ -76,7 +76,7 @@ public class MappingResourceMetadataUnitTests {
public void isExportedIfExplicitlyAnnotated() {
MappingResourceMetadata metadata = new MappingResourceMetadata(context.getPersistentEntity(Related.class),
resourceMappings).init();
resourceMappings);
assertThat(metadata.isExported(), is(true));
}