Skip to content

Commit

Permalink
use the Impl class
Browse files Browse the repository at this point in the history
don't access fields directly
  • Loading branch information
evanchooly committed Jan 23, 2025
1 parent 033da3c commit a5a6ef8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.mongodb.lang.Nullable;

import dev.morphia.Datastore;
import dev.morphia.DatastoreImpl;
import dev.morphia.EntityInterceptor;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
Expand Down Expand Up @@ -273,8 +274,9 @@ public boolean hasAnnotation(Class<? extends Annotation> type) {

@Override
public void prePersist(@NotNull Object ent, @NotNull Document document, @NotNull Datastore datastore) {
final List<PropertyModel> fieldsToTest = datastore.getMapper().getEntityModel(ent.getClass())
.getProperties(NonNull.class);
DatastoreImpl ds = (DatastoreImpl) datastore;
final List<PropertyModel> fieldsToTest = ds.getMapper().getEntityModel(ent.getClass())
.getProperties(NonNull.class);
for (PropertyModel mf : fieldsToTest) {
if (mf.getValue(ent) == null) {
throw new NonNullValidationException(mf);
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/dev/morphia/test/mapping/TestMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static void assertModelNotSame(EntityModel originalEntity, EntityModel c
} else {
assertNotSame(originalEntity.superClass, clonedEntity.superClass);
}
originalEntity.subtypes.forEach(subtype -> {
originalEntity.getSubtypes().forEach(subtype -> {
assertNotSame(subtype, findSubtype(clonedEntity, subtype));
});
originalEntity.getProperties().forEach(propertyModel -> {
Expand All @@ -49,7 +49,7 @@ private static void assertModelNotSame(EntityModel originalEntity, EntityModel c
}

private static EntityModel findSubtype(EntityModel clonedEntity, EntityModel subtype) {
return clonedEntity.subtypes.stream()
return clonedEntity.getSubtypes().stream()
.filter(clone -> clone.getType().equals(subtype.getType()))
.findFirst()
.orElseThrow(() -> new MappingException(
Expand Down

0 comments on commit a5a6ef8

Please sign in to comment.