Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop morphia thread safety mapper issue #3036

Open
wants to merge 1 commit into
base: 2.4.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions core/src/main/java/dev/morphia/mapping/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class Mapper {
private final List<EntityListener<?>> listeners = new ArrayList<>();
private final MorphiaConfig config;
private final DiscriminatorLookup discriminatorLookup;
private final Object entityRegistrationMonitor = new Object();

/**
* Creates a Mapper with the given options.
Expand Down Expand Up @@ -567,22 +568,27 @@ private EntityModel register(EntityModel model, boolean validate) {
var existing = mappedEntities.get(model.getType().getName());
if (existing != null) {
return existing;
} else {
synchronized (entityRegistrationMonitor) {
existing = mappedEntities.get(model.getType().getName());
if (existing != null) {
return existing;
} else {
mappedEntities.put(model.getType().getName(), model);
if (validate && !model.isInterface()) {
new MappingValidator().validate(this, model);
}
discriminatorLookup.addModel(model);
mappedEntitiesByCollection.computeIfAbsent(model.getCollectionName(), s -> new CopyOnWriteArraySet<>()).add(model);

EntityModel superClass = model.getSuperClass();
if (superClass != null) {
superClass.addSubtype(model);
}
return model;
}
}
}
mappedEntities.put(model.getType().getName(), model);

if (validate && !model.isInterface()) {
new MappingValidator()
.validate(this, model);
}
discriminatorLookup.addModel(model);
mappedEntitiesByCollection.computeIfAbsent(model.getCollectionName(), s -> new CopyOnWriteArraySet<>())
.add(model);
EntityModel superClass = model.getSuperClass();
if (superClass != null) {
superClass.addSubtype(model);
}

return model;
}

private List<Class> getClasses(String packageName)
Expand Down