Search in sources :

Example 1 with OperationTarget

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;
}
Also used : PathTarget(dev.morphia.internal.PathTarget) PropertyHandler(dev.morphia.mapping.codec.pojo.PropertyHandler) OperationTarget(dev.morphia.query.OperationTarget) PropertyModel(dev.morphia.mapping.codec.pojo.PropertyModel) Nullable(com.mongodb.lang.Nullable)

Example 2 with OperationTarget

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());
        }
    };
}
Also used : Datastore(dev.morphia.Datastore) Filter(dev.morphia.query.experimental.filters.Filter) DocumentWriter(dev.morphia.mapping.codec.writer.DocumentWriter) OperationTarget(dev.morphia.query.OperationTarget) Document(org.bson.Document)

Example 3 with OperationTarget

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;
        }
    };
}
Also used : Datastore(dev.morphia.Datastore) DocumentWriter(dev.morphia.mapping.codec.writer.DocumentWriter) OperationTarget(dev.morphia.query.OperationTarget) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) PropertyModel(dev.morphia.mapping.codec.pojo.PropertyModel) Document(org.bson.Document)

Aggregations

OperationTarget (dev.morphia.query.OperationTarget)3 Datastore (dev.morphia.Datastore)2 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)2 DocumentWriter (dev.morphia.mapping.codec.writer.DocumentWriter)2 Document (org.bson.Document)2 Nullable (com.mongodb.lang.Nullable)1 PathTarget (dev.morphia.internal.PathTarget)1 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)1 PropertyHandler (dev.morphia.mapping.codec.pojo.PropertyHandler)1 Filter (dev.morphia.query.experimental.filters.Filter)1