@Override protected DBRef asReference(Object constant) { Key<?> key = morphia.getMapper().getKey(constant); return morphia.getMapper().keyToDBRef(key); }
@Override @Deprecated // use mapper instead. public <T> Key<T> getKey(final T entity) { return mapper.getKey(entity); }
private Object getDBRefs(final MappedField field, final Iterable value) { final List<Object> refs = new ArrayList<Object>(); Reference annotation = field.getAnnotation(Reference.class); boolean idOnly = annotation != null && annotation.idOnly(); for (final Object o : value) { Key<?> key = (o instanceof Key) ? (Key<?>) o : getKey(o); refs.add(idOnly ? key.getId() : keyToDBRef(key)); } return refs; }
@Override protected DBRef asReference(Object constant) { Key<?> key = morphia.getMapper().getKey(constant); return morphia.getMapper().keyToRef(key); }
private Query<?> buildExistsQuery(final Object entityOrKey) { final Object unwrapped = ProxyHelper.unwrap(entityOrKey); final Key<?> key = mapper.getKey(unwrapped); final Object id = key.getId(); if (id == null) { throw new MappingException("Could not get id for " + unwrapped.getClass().getName()); } return find(key.getCollection(), key.getType()).filter(Mapper.ID_KEY, key.getId()); }
final LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>(); final DBObject dbObj = mapper.toDBObject(unwrapped, involvedObjects); final Key<T> key = mapper.getKey(unwrapped); unwrapped = ProxyHelper.unwrap(unwrapped); final Object id = mapper.getId(unwrapped);
if (refAnn != null) { if (!valueIsIdType) { Key<?> key = value instanceof Key ? (Key<?>) value : getKey(value); if (key != null) { mappedValue = refAnn.idOnly() mappedValue = keyToDBRef(valueIsIdType ? createKey(mf.getSubClass(), value) : value instanceof Key ? (Key<?>) value : getKey(value)); if (mappedValue == value) { throw new ValidationException("cannot map to Key<T> field: " + value);