use of dev.morphia.mapping.codec.pojo.PropertyHandler 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.mapping.codec.pojo.PropertyHandler in project morphia by mongodb.
the class OperationTarget method encode.
/**
* Encodes this target
*
* @param datastore the datastore
* @return the encoded form
* @morphia.internal
*/
public Object encode(Datastore datastore) {
if (target == null) {
if (value == null) {
throw new NullPointerException();
}
return value;
}
PropertyModel mappedField = this.target.getTarget();
Object mappedValue = value;
PropertyModel model = mappedField != null ? mappedField.getEntityModel().getProperty(mappedField.getName()) : null;
Codec cachedCodec = null;
if (model != null && !(mappedValue instanceof LegacyQuery)) {
cachedCodec = model.specializeCodec(datastore);
}
if (cachedCodec instanceof PropertyHandler) {
mappedValue = ((PropertyHandler) cachedCodec).encode(mappedValue);
} else {
DocumentWriter writer = new DocumentWriter(datastore.getMapper());
Object finalMappedValue = mappedValue;
document(writer, () -> value(datastore, writer, "mapped", finalMappedValue, EncoderContext.builder().build()));
mappedValue = writer.getDocument().get("mapped");
}
return new Document(target.translatedPath(), mappedValue);
}
Aggregations