<T> Key<T> manualRefToKey(final String collection, final Object id) { return id == null ? null : new Key<T>((Class<? extends T>) getClassFromCollection(collection), collection, id); }
/** * Converts a DBRef to a Key * * @param ref the DBRef to convert * @param <T> the type of the referenced entity * @return the Key */ public <T> Key<T> refToKey(final DBRef ref) { return ref == null ? null : new Key<T>((Class<? extends T>) getClassFromCollection(ref.getCollectionName()), ref.getCollectionName(), ref.getId()); }
@Override public Object decode(final Class targetClass, final Object o, final MappedField optionalExtraInfo) { if (o == null) { return null; } if (!(o instanceof DBRef)) { throw new ConverterException(String.format("cannot convert %s to Key because it isn't a DBRef", o.toString())); } DBRef ref = (DBRef) o; MappedField actualType = getActualType(optionalExtraInfo); final Class<?> keyType = actualType != null ? actualType.getConcreteType() : getMapper().getClassFromCollection(ref.getCollectionName()); final Key<?> key = new Key<Object>(keyType, ref.getCollectionName(), ref.getId()); return key; }
@Override @SuppressWarnings("unchecked") public <T> UpdateResults update(final Key<T> key, final UpdateOperations<T> operations) { Class<T> clazz = (Class<T>) key.getType(); if (clazz == null) { clazz = (Class<T>) mapper.getClassFromCollection(key.getCollection()); } return updateFirst(createQuery(clazz).disableValidation().filter(Mapper.ID_KEY, key.getId()), operations); }