use of dev.morphia.internal.PathTarget 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.internal.PathTarget in project morphia by mongodb.
the class PathTargetTest method maps.
@Test
public void maps() {
getMapper().map(Student.class);
Mapper mapper = getMapper();
EntityModel entityModel = mapper.getEntityModel(Student.class);
PathTarget pathTarget = new PathTarget(mapper, entityModel, "grades.$.data.name");
Assert.assertEquals(pathTarget.translatedPath(), "grades.$.d.name");
Assert.assertEquals(mapper.getEntityModel(Grade.class).getProperty("data"), pathTarget.getTarget());
pathTarget = new PathTarget(mapper, entityModel, "grades.$.d.name");
Assert.assertEquals(pathTarget.translatedPath(), "grades.$.d.name");
Assert.assertEquals(mapper.getEntityModel(Grade.class).getProperty("d"), pathTarget.getTarget());
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class Operations method versionUpdate.
protected void versionUpdate() {
PropertyModel versionField = entityModel.getVersionProperty();
if (versionField != null) {
List<OperationTarget> operationTargets = ops.get("$inc");
String version = versionField.getMappedName();
boolean already = operationTargets != null && operationTargets.stream().anyMatch(tv -> {
PathTarget target = tv.getTarget();
return target != null && target.translatedPath().equals(version);
});
if (!already) {
add("$inc", new OperationTarget(new PathTarget(datastore.getMapper(), entityModel, versionField.getName()), 1L));
}
}
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class Projection method knownFields.
private Document knownFields(Mapper mapper, Class<?> clazz) {
Document projection = new Document();
mapper.getEntityModel(clazz).getProperties().stream().map(mf -> new PathTarget(mapper, mapper.getEntityModel(clazz), mf.getMappedName()).translatedPath()).forEach(name -> projection.put(name, 1));
return projection;
}
use of dev.morphia.internal.PathTarget in project morphia by mongodb.
the class FindOptions method apply.
/**
* @param iterable the iterable to use
* @param mapper the mapper to use
* @param type the result type
* @param <T> the result type
* @return the iterable instance for the query results
* @morphia.internal
*/
public <T> FindIterable<T> apply(FindIterable<T> iterable, Mapper mapper, Class<?> type) {
if (isLogQuery()) {
// reset to a new ID
logQuery();
}
if (projection != null) {
iterable.projection(projection.map(mapper, type));
}
tryInvoke(v4_1_0, () -> {
return iterable.allowDiskUse(allowDiskUse);
});
iterable.batchSize(batchSize);
iterable.collation(collation);
iterable.comment(comment);
if (cursorType != null) {
iterable.cursorType(cursorType);
}
iterable.hint(hint);
iterable.hintString(hintString);
iterable.limit(limit);
iterable.max(max);
iterable.maxAwaitTime(maxAwaitTimeMS, TimeUnit.MILLISECONDS);
iterable.maxTime(maxTimeMS, TimeUnit.MILLISECONDS);
iterable.min(min);
iterable.noCursorTimeout(noCursorTimeout);
iterable.oplogReplay(oplogReplay);
iterable.partial(partial);
iterable.returnKey(returnKey);
iterable.showRecordId(showRecordId);
iterable.skip(skip);
if (sort != null) {
Document mapped = new Document();
EntityModel model = mapper.getEntityModel(type);
for (Entry<String, Object> entry : sort.entrySet()) {
Object value = entry.getValue();
boolean metaScore = value instanceof Document && ((Document) value).get("$meta") != null;
mapped.put(new PathTarget(mapper, model, entry.getKey(), !metaScore).translatedPath(), value);
}
iterable.sort(mapped);
}
return iterable;
}
Aggregations