use of org.mongodb.morphia.internal.PathTarget in project morphia by mongodb.
the class UpdateOpsImpl method push.
@Override
public UpdateOperations<T> push(final String field, final List<?> values, final PushOptions options) {
if (values == null || values.isEmpty()) {
throw new QueryException("Values cannot be null or empty.");
}
PathTarget pathTarget = new PathTarget(mapper, mapper.getMappedClass(clazz), field);
if (!validateNames) {
pathTarget.disableValidation();
}
BasicDBObject dbObject = new BasicDBObject(UpdateOperator.EACH.val(), mapper.toMongoObject(pathTarget.getTarget(), null, values));
options.update(dbObject);
addOperation(UpdateOperator.PUSH, pathTarget.translatedPath(), dbObject);
return this;
}
use of org.mongodb.morphia.internal.PathTarget in project morphia by mongodb.
the class UpdateOpsImpl method add.
//TODO Clean this up a little.
protected void add(final UpdateOperator op, final String f, final Object value, final boolean convert) {
if (value == null) {
throw new QueryException("Val cannot be null");
}
Object val = value;
PathTarget pathTarget = new PathTarget(mapper, mapper.getMappedClass(clazz), f);
if (!validateNames) {
pathTarget.disableValidation();
}
MappedField mf = pathTarget.getTarget();
if (convert) {
if (UpdateOperator.PULL_ALL.equals(op) && value instanceof List) {
val = toDBObjList(mf, (List<?>) value);
} else {
val = mapper.toMongoObject(mf, null, value);
}
}
if (UpdateOperator.ADD_TO_SET_EACH.equals(op)) {
val = new BasicDBObject(UpdateOperator.EACH.val(), val);
}
addOperation(op, pathTarget.translatedPath(), val);
}
Aggregations