DATAREST-723 - PropertyMappings now get eagerly initialized.
Switched to eager initialization of PropertyMappings to avoid potential ConcurrentModificationException.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -99,8 +99,6 @@ public class PersistentEntitiesResourceMappings implements ResourceMappings {
|
||||
|
||||
mappingMetadata = new MappingResourceMetadata(entity, this);
|
||||
mappingCache.put(type, mappingMetadata);
|
||||
mappingMetadata.init();
|
||||
|
||||
return mappingMetadata;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user