/** * Returns whether the given {@link Field} represents an association reference that together with the given value * requires conversion to a {@link org.springframework.data.mongodb.core.mapping.DBRef} object. We check whether the * type of the given value is compatible with the type of the given document field in order to deal with potential * query field exclusions, since MongoDB uses the {@code int} {@literal 0} as an indicator for an excluded field. * * @param documentField must not be {@literal null}. * @param value * @return */ protected boolean isAssociationConversionNecessary(Field documentField, @Nullable Object value) { Assert.notNull(documentField, "Document field must not be null!"); if (value == null) { return false; } if (!documentField.isAssociation()) { return false; } Class<? extends Object> type = value.getClass(); MongoPersistentProperty property = documentField.getProperty(); if (property.getActualType().isAssignableFrom(type)) { return true; } MongoPersistentEntity<?> entity = documentField.getPropertyEntity(); return entity.hasIdProperty() && (type.equals(DBRef.class) || entity.getRequiredIdProperty().getActualType().isAssignableFrom(type)); }
private Object getMappedModifier(@Nullable Field field, Modifier modifier) { Object value = modifier.getValue(); if (value instanceof Sort) { Document sortObject = getSortObject((Sort) value); return field == null || field.getPropertyEntity() == null ? sortObject : getMappedSort(sortObject, field.getPropertyEntity()); } TypeInformation<?> typeHint = field == null ? ClassTypeInformation.OBJECT : field.getTypeHint(); return converter.convertToMongoType(value, typeHint); }
return getMappedKeyword(new Keyword((Bson) value), documentField.getPropertyEntity()); return convertSimpleOrDocument(value, documentField.getPropertyEntity());
return getMappedKeyword(new Keyword((Bson) value), documentField.getPropertyEntity()); return convertSimpleOrDocument(value, documentField.getPropertyEntity());
/** * Returns whether the given {@link Field} represents an association reference that together with the given value * requires conversion to a {@link org.springframework.data.mongodb.core.mapping.DBRef} object. We check whether the * type of the given value is compatible with the type of the given document field in order to deal with potential * query field exclusions, since MongoDB uses the {@code int} {@literal 0} as an indicator for an excluded field. * * @param documentField must not be {@literal null}. * @param value * @return */ protected boolean isAssociationConversionNecessary(Field documentField, @Nullable Object value) { Assert.notNull(documentField, "Document field must not be null!"); if (value == null) { return false; } if (!documentField.isAssociation()) { return false; } Class<? extends Object> type = value.getClass(); MongoPersistentProperty property = documentField.getProperty(); if (property.getActualType().isAssignableFrom(type)) { return true; } MongoPersistentEntity<?> entity = documentField.getPropertyEntity(); return entity.hasIdProperty() && (type.equals(DBRef.class) || entity.getRequiredIdProperty().getActualType().isAssignableFrom(type)); }
@Override protected Entry<String, Object> getMappedObjectForField(Field field, Object rawValue) { if (isDocument(rawValue)) { Object val = field.isMap() ? new LinkedHashMap<>((Document) rawValue) : rawValue; // unwrap to preserve field type return createMapEntry(field, convertSimpleOrDocument(val, field.getPropertyEntity())); } if (isQuery(rawValue)) { return createMapEntry(field, super.getMappedObject(((Query) rawValue).getQueryObject(), field.getPropertyEntity())); } if (isUpdateModifier(rawValue)) { return getMappedUpdateModifier(field, rawValue); } return super.getMappedObjectForField(field, rawValue); }
private Object getMappedModifier(@Nullable Field field, Modifier modifier) { Object value = modifier.getValue(); if (value instanceof Sort) { Document sortObject = getSortObject((Sort) value); return field == null || field.getPropertyEntity() == null ? sortObject : getMappedSort(sortObject, field.getPropertyEntity()); } TypeInformation<?> typeHint = field == null ? ClassTypeInformation.OBJECT : field.getTypeHint(); return converter.convertToMongoType(value, typeHint); }
@Override protected Entry<String, Object> getMappedObjectForField(Field field, Object rawValue) { if (isDocument(rawValue)) { Object val = field.isMap() ? new LinkedHashMap<>((Document) rawValue) : rawValue; // unwrap to preserve field type return createMapEntry(field, convertSimpleOrDocument(val, field.getPropertyEntity())); } if (isQuery(rawValue)) { return createMapEntry(field, super.getMappedObject(((Query) rawValue).getQueryObject(), field.getPropertyEntity())); } if (isUpdateModifier(rawValue)) { return getMappedUpdateModifier(field, rawValue); } return super.getMappedObjectForField(field, rawValue); }