use of dev.morphia.query.OperationTarget in project morphia by mongodb.
the class Filter method getValue.
@Nullable
protected Object getValue(Datastore datastore) {
if (!mapped) {
PathTarget target = pathTarget(datastore.getMapper());
OperationTarget operationTarget = new OperationTarget(pathTarget, value);
this.value = operationTarget.getValue();
PropertyModel property = target.getTarget();
if (property != null && property.specializeCodec(datastore) instanceof PropertyHandler) {
this.value = ((Document) operationTarget.encode(datastore)).get(field);
}
mapped = true;
}
return value;
}
use of dev.morphia.query.OperationTarget in project morphia by mongodb.
the class PullOperator method toTarget.
@Override
public OperationTarget toTarget(PathTarget pathTarget) {
return new OperationTarget(pathTarget, value()) {
@Override
public Object encode(Datastore datastore) {
DocumentWriter writer = new DocumentWriter(datastore.getMapper());
document(writer, () -> {
((Filter) getValue()).encode(datastore, writer, EncoderContext.builder().build());
});
return new Document(field(), writer.getDocument());
}
};
}
use of dev.morphia.query.OperationTarget in project morphia by mongodb.
the class SetEntityOperator method toTarget.
@Override
public OperationTarget toTarget(PathTarget pathTarget) {
return new OperationTarget(null, value()) {
@Override
@SuppressWarnings("unchecked")
public Object encode(Datastore datastore) {
Object value = value();
EntityModel entityModel = datastore.getMapper().getEntityModel(value.getClass());
PropertyModel versionProperty = entityModel.getVersionProperty();
if (versionProperty == null) {
return super.encode(datastore);
}
Codec<Object> codec = datastore.getCodecRegistry().get((Class<Object>) value.getClass());
DocumentWriter writer = new DocumentWriter(datastore.getMapper());
codec.encode(writer, value, EncoderContext.builder().build());
Document document = writer.getDocument();
document.remove(versionProperty.getMappedName());
return document;
}
};
}
Aggregations