@Override public Object visit(Constant<?> expr, Void context) { Object value = super.visit(expr, context); return morphia.getMapper().toMongoObject(null, null, value); }
protected List<Object> toDBObjList(final MappedField mf, final List<?> values) { final List<Object> list = new ArrayList<Object>(values.size()); for (final Object obj : values) { list.add(mapper.toMongoObject(mf, null, obj)); } return list; }
final HashMap m = new HashMap(); for (final Map.Entry e : (Iterable<Map.Entry>) ((Map) newObj).entrySet()) { m.put(e.getKey(), toMongoObject(e.getValue(), includeClassName)); if (type.isArray()) { for (final Object obj : (Object[]) newObj) { values.add(toMongoObject(obj, includeClassName)); values.add(toMongoObject(obj, includeClassName));
final Object val; if (Collection.class.isAssignableFrom(o.getClass()) || Map.class.isAssignableFrom(o.getClass())) { val = mapper.toMongoObject(o, true); } else { val = mapper.toDBObject(o, involvedObjects);
@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; }
} else { if (Map.class.isAssignableFrom(entryVal.getClass()) || Collection.class.isAssignableFrom(entryVal.getClass())) { val = mapper.toMongoObject(entryVal, true); } else { val = mapper.toDBObject(entryVal, involvedObjects);
Object mappedValue = mapper.toMongoObject(mf, mc, value);
/** * Converts a Key to a DBRef * * @param key the Key to convert * @return the DBRef */ public DBRef keyToDBRef(final Key key) { if (key == null) { return null; } if (key.getType() == null && key.getCollection() == null) { throw new IllegalStateException("How can it be missing both?"); } if (key.getCollection() == null) { key.setCollection(getCollectionName(key.getType())); } Object id = key.getId(); if (isMapped(id.getClass())) { id = toMongoObject(id, true); } return new DBRef(key.getCollection(), id); }
private void writeSingle(final DBObject dbObject, final String name, final Object fieldValue, final Reference refAnn, final Mapper mapper) { if (fieldValue == null) { if (mapper.getOptions().isStoreNulls()) { dbObject.put(name, null); } } else { Key<?> key = getKey(fieldValue, mapper); if (refAnn.idOnly()) { Object id = mapper.keyToId(key); if (id != null && mapper.isMapped(id.getClass())) { id = mapper.toMongoObject(id, true); } dbObject.put(name, id); } else { dbObject.put(name, mapper.keyToDBRef(key)); } } }
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); }
mappedValue = getDBRefs(mf, (Iterable) value); } else { mappedValue = toMongoObject(value, false); mappedValue = toMongoObject(value, false); mappedValue = toMongoObject(value, false); mappedValue = value; } else { mappedValue = toMongoObject(value, EmbeddedMapper.shouldSaveClassName(value, mappedValue, mf)); if (mappedValue instanceof BasicDBList) { final BasicDBList list = (BasicDBList) mappedValue;