use of dev.morphia.EntityInterceptor in project morphia by mongodb.
the class EntityModel method callGlobalInterceptors.
private void callGlobalInterceptors(Class<? extends Annotation> event, Object entity, Document document, Datastore datastore) {
for (EntityInterceptor ei : datastore.getMapper().getInterceptors()) {
Sofia.logCallingInterceptorMethod(event.getSimpleName(), ei);
if (event.equals(PreLoad.class)) {
ei.preLoad(entity, document, mapper);
ei.preLoad(entity, document, datastore);
} else if (event.equals(PostLoad.class)) {
ei.postLoad(entity, document, mapper);
ei.postLoad(entity, document, datastore);
} else if (event.equals(PrePersist.class)) {
ei.prePersist(entity, document, mapper);
ei.prePersist(entity, document, datastore);
} else if (event.equals(PostPersist.class)) {
ei.postPersist(entity, document, mapper);
ei.postPersist(entity, document, datastore);
}
}
}
use of dev.morphia.EntityInterceptor in project morphia by MorphiaOrg.
the class EntityModel method callGlobalInterceptors.
private void callGlobalInterceptors(Class<? extends Annotation> event, Object entity, Document document, Datastore datastore) {
for (EntityInterceptor ei : datastore.getMapper().getInterceptors()) {
Sofia.logCallingInterceptorMethod(event.getSimpleName(), ei);
if (event.equals(PreLoad.class)) {
ei.preLoad(entity, document, mapper);
ei.preLoad(entity, document, datastore);
} else if (event.equals(PostLoad.class)) {
ei.postLoad(entity, document, mapper);
ei.postLoad(entity, document, datastore);
} else if (event.equals(PrePersist.class)) {
ei.prePersist(entity, document, mapper);
ei.prePersist(entity, document, datastore);
} else if (event.equals(PostPersist.class)) {
ei.postPersist(entity, document, mapper);
ei.postPersist(entity, document, datastore);
}
}
}
use of dev.morphia.EntityInterceptor in project morphia by MorphiaOrg.
the class DocumentReaderTest method testNestedByteArrayWithInterceptor.
@Test
public void testNestedByteArrayWithInterceptor() {
HasByteArray hasByteArray = new HasByteArray();
hasByteArray.data = new byte[] { 1, 2, 3 };
HasNestedByteArray hasNestedByteArray = new HasNestedByteArray();
hasNestedByteArray.nested = hasByteArray;
getDs().save(hasNestedByteArray);
EntityInterceptor interceptor = new EntityInterceptor() {
};
try {
getDs().getMapper().addInterceptor(interceptor);
Document first = getDs().getCollection(HasNestedByteArray.class).withDocumentClass(Document.class).find().first();
fromDocument(HasNestedByteArray.class, first);
} finally {
getDs().getMapper().getInterceptors().remove(interceptor);
}
}
use of dev.morphia.EntityInterceptor in project morphia by mongodb.
the class DocumentReaderTest method testNestedByteArrayWithInterceptor.
@Test
public void testNestedByteArrayWithInterceptor() {
HasByteArray hasByteArray = new HasByteArray();
hasByteArray.data = new byte[] { 1, 2, 3 };
HasNestedByteArray hasNestedByteArray = new HasNestedByteArray();
hasNestedByteArray.nested = hasByteArray;
getDs().save(hasNestedByteArray);
EntityInterceptor interceptor = new EntityInterceptor() {
};
try {
getDs().getMapper().addInterceptor(interceptor);
Document first = getDs().getCollection(HasNestedByteArray.class).withDocumentClass(Document.class).find().first();
fromDocument(HasNestedByteArray.class, first);
} finally {
getDs().getMapper().getInterceptors().remove(interceptor);
}
}
Aggregations