/** * Performs a bulk fetch operation for the given {@link DBRef}s. * * @param references must not be {@literal null}. * @return never {@literal null}. * @since 1.10 */ List<Document> bulkReadRefs(List<DBRef> references) { return dbRefResolver.bulkFetch(references); }
/** * Performs the fetch operation for the given {@link DBRef}. * * @param ref * @return */ Document readRef(DBRef ref) { return dbRefResolver.fetch(ref); }
private void readAssociation(Association<MongoPersistentProperty> association, PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor, DbRefProxyHandler handler, DbRefResolverCallback callback) { MongoPersistentProperty property = association.getInverse(); Object value = documentAccessor.get(property); if (value == null) { return; } DBRef dbref = value instanceof DBRef ? (DBRef) value : null; accessor.setProperty(property, dbRefResolver.resolveDbRef(property, dbref, callback, handler)); }
protected DBRef createDBRef(Object target, MongoPersistentProperty property) { Assert.notNull(target, "Target object must not be null!"); if (target instanceof DBRef) { return (DBRef) target; } MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass()); targetEntity = targetEntity != null ? targetEntity : mappingContext.getPersistentEntity(property); if (null == targetEntity) { throw new MappingException("No mapping metadata found for " + target.getClass()); } MongoPersistentEntity<?> entity = targetEntity; MongoPersistentProperty idProperty = entity.getIdProperty(); if (idProperty != null) { Object id = target.getClass().equals(idProperty.getType()) ? target : entity.getPropertyAccessor(target).getProperty(idProperty); if (null == id) { throw new MappingException("Cannot create a reference to an object with a NULL id."); } return dbRefResolver.createDbRef(property == null ? null : property.getDBRef(), entity, idMapper.convertId(id, idProperty != null ? idProperty.getFieldType() : ObjectId.class)); } throw new MappingException("No id property found on class " + entity.getType()); }
protected DBRef createDBRef(Object target, MongoPersistentProperty property) { Assert.notNull(target, "Target object must not be null!"); if (target instanceof DBRef) { return (DBRef) target; } MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass()); targetEntity = targetEntity != null ? targetEntity : mappingContext.getPersistentEntity(property); if (null == targetEntity) { throw new MappingException("No mapping metadata found for " + target.getClass()); } MongoPersistentEntity<?> entity = targetEntity; MongoPersistentProperty idProperty = entity.getIdProperty(); if (idProperty != null) { Object id = target.getClass().equals(idProperty.getType()) ? target : entity.getPropertyAccessor(target).getProperty(idProperty); if (null == id) { throw new MappingException("Cannot create a reference to an object with a NULL id."); } return dbRefResolver.createDbRef(property == null ? null : property.getDBRef(), entity, idMapper.convertId(id)); } throw new MappingException("No id property found on class " + entity.getType()); }
/** * Performs the fetch operation for the given {@link DBRef}. * * @param ref * @return */ Document readRef(DBRef ref) { return dbRefResolver.fetch(ref); }
@Nullable @SuppressWarnings("unchecked") public <T> T getPropertyValue(MongoPersistentProperty property) { if (property.isDbReference() && property.getDBRef().lazy()) { Object rawRefValue = accessor.get(property); if (rawRefValue == null) { return null; } DbRefResolverCallback callback = new DefaultDbRefResolverCallback(accessor.getDocument(), path, evaluator, MappingMongoConverter.this); DBRef dbref = rawRefValue instanceof DBRef ? (DBRef) rawRefValue : null; return (T) dbRefResolver.resolveDbRef(property, dbref, callback, dbRefProxyHandler); } return super.getPropertyValue(property); } }
/** * Performs a bulk fetch operation for the given {@link DBRef}s. * * @param references must not be {@literal null}. * @return never {@literal null}. * @since 1.10 */ List<Document> bulkReadRefs(List<DBRef> references) { return dbRefResolver.bulkFetch(references); }
: new DBRef(collection, id); sourceDocument = dbRefResolver.fetch(ref); if (sourceDocument == null) { return null;
private void readAssociation(Association<MongoPersistentProperty> association, PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor, DbRefProxyHandler handler, DbRefResolverCallback callback) { MongoPersistentProperty property = association.getInverse(); Object value = documentAccessor.get(property); if (value == null) { return; } DBRef dbref = value instanceof DBRef ? (DBRef) value : null; accessor.setProperty(property, dbRefResolver.resolveDbRef(property, dbref, callback, handler)); }
sourceDocument = dbRefResolver.fetch(new DBRef(sourceDocument.getString("$ref"), sourceDocument.get("$id"))); if (sourceDocument == null) { return null;
@Nullable @SuppressWarnings("unchecked") public <T> T getPropertyValue(MongoPersistentProperty property) { if (property.isDbReference() && property.getDBRef().lazy()) { Object rawRefValue = accessor.get(property); if (rawRefValue == null) { return null; } DbRefResolverCallback callback = new DefaultDbRefResolverCallback(accessor.getDocument(), path, evaluator, MappingMongoConverter.this); DBRef dbref = rawRefValue instanceof DBRef ? (DBRef) rawRefValue : null; return (T) dbRefResolver.resolveDbRef(property, dbref, callback, dbRefProxyHandler); } return super.getPropertyValue(property); } }