private List<Object> mapEnumValues(Iterable<?> values) { List<Object> converted = new ArrayList<>(); for (Object val : values) { converted.add(converter.convertToMongoType(val)); } return converted; }
/** * Converts the given source Object to a mongo type with the type information of the original source type omitted. * Subclasses may overwrite this method to retain the type information of the source type on the resulting mongo type. * * @param source * @param entity * @return the converted mongo type or null if source is null */ @Nullable protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) { return converter.convertToMongoType(source, entity == null ? null : entity.getTypeInformation()); }
private Object[] convertScriptArgs(boolean quote, Object... args) { if (ObjectUtils.isEmpty(args)) { return args; } List<Object> convertedValues = new ArrayList<Object>(args.length); for (Object arg : args) { convertedValues.add(arg instanceof String && quote ? String.format("'%s'", arg) : this.mongoOperations.getConverter().convertToMongoType(arg)); } return convertedValues.toArray(); }
@Override protected Document asDocument(@Nullable String key, @Nullable Object value) { value = value instanceof Optional ? ((Optional) value).orElse(null) : value; return super.asDocument(key, value instanceof Pattern ? value : converter.convertToMongoType(value)); }
/** * Converts the given source object to a mongo type retaining the original type information of the source type on the * mongo type. * * @see org.springframework.data.mongodb.core.convert.QueryMapper#delegateConvertToMongoType(java.lang.Object, * org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) */ @Override protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) { return converter.convertToMongoType(source, entity == null ? ClassTypeInformation.OBJECT : getTypeHintForEntity(source, entity)); }
return getConversionService().canConvert(id.getClass(), targetType) ? getConversionService().convert(id, targetType) : convertToMongoType(id, null); } catch (ConversionException o_O) { return convertToMongoType(id, null);
@Override public Object visit(Constant<?> expr, Void context) { if (!ClassUtils.isAssignable(Enum.class, expr.getType())) { return super.visit(expr, context); } return converter.convertToMongoType(expr.getConstant()); }
String key = ObjectUtils.nullSafeToString(converter.convertToMongoType(it.getKey()));
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); }
/** * Returns the given {@link Example} as {@link Document} holding matching values extracted from * {@link Example#getProbe()}. * * @param example must not be {@literal null}. * @param entity must not be {@literal null}. * @return */ public Document getMappedExample(Example<?> example, MongoPersistentEntity<?> entity) { Assert.notNull(example, "Example must not be null!"); Assert.notNull(entity, "MongoPersistentEntity must not be null!"); Document reference = (Document) converter.convertToMongoType(example.getProbe()); if (entity.getIdProperty() != null && ClassUtils.isAssignable(entity.getType(), example.getProbeType())) { Object identifier = entity.getIdentifierAccessor(example.getProbe()).getIdentifier(); if (identifier == null) { reference.remove(entity.getIdProperty().getFieldName()); } } ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher()); applyPropertySpecs("", reference, example.getProbeType(), matcherAccessor); Document flattened = ObjectUtils.nullSafeEquals(NullHandler.INCLUDE, matcherAccessor.getNullHandler()) ? reference : new Document(SerializationUtils.flattenMap(reference)); Document result = example.getMatcher().isAllMatching() ? flattened : orConcatenate(flattened); return updateTypeRestrictions(result, example); }
private List<Object> mapEnumValues(Iterable<?> values) { List<Object> converted = new ArrayList<>(); for (Object val : values) { converted.add(converter.convertToMongoType(val)); } return converted; }
private Object[] convertScriptArgs(boolean quote, Object... args) { if (ObjectUtils.isEmpty(args)) { return args; } List<Object> convertedValues = new ArrayList<Object>(args.length); for (Object arg : args) { convertedValues.add(arg instanceof String && quote ? String.format("'%s'", arg) : this.mongoOperations.getConverter().convertToMongoType(arg)); } return convertedValues.toArray(); }
/** * Converts the given source Object to a mongo type with the type information of the original source type omitted. * Subclasses may overwrite this method to retain the type information of the source type on the resulting mongo type. * * @param source * @param entity * @return the converted mongo type or null if source is null */ @Nullable protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) { return converter.convertToMongoType(source, entity == null ? null : entity.getTypeInformation()); }
/** * Converts the given source object to a mongo type retaining the original type information of the source type on the * mongo type. * * @see org.springframework.data.mongodb.core.convert.QueryMapper#delegateConvertToMongoType(java.lang.Object, * org.springframework.data.mongodb.core.mapping.MongoPersistentEntity) */ @Override protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) { return converter.convertToMongoType(source, entity == null ? ClassTypeInformation.OBJECT : getTypeHintForEntity(source, entity)); }
@Override protected Document asDocument(@Nullable String key, @Nullable Object value) { value = value instanceof Optional ? ((Optional) value).orElse(null) : value; if (ID_KEY.equals(key) || (key != null && key.endsWith("." + ID_KEY))) { return convertId(key, value); } return super.asDocument(key, value instanceof Pattern ? value : converter.convertToMongoType(value)); }
@Override public Object visit(Constant<?> expr, Void context) { if (!ClassUtils.isAssignable(Enum.class, expr.getType())) { return super.visit(expr, context); } return converter.convertToMongoType(expr.getConstant()); }
String key = ObjectUtils.nullSafeToString(converter.convertToMongoType(it.getKey()));
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); }
/** * Returns the given {@link Example} as {@link Document} holding matching values extracted from * {@link Example#getProbe()}. * * @param example must not be {@literal null}. * @param entity must not be {@literal null}. * @return */ public Document getMappedExample(Example<?> example, MongoPersistentEntity<?> entity) { Assert.notNull(example, "Example must not be null!"); Assert.notNull(entity, "MongoPersistentEntity must not be null!"); Document reference = (Document) converter.convertToMongoType(example.getProbe()); if (entity.getIdProperty() != null && ClassUtils.isAssignable(entity.getType(), example.getProbeType())) { Object identifier = entity.getIdentifierAccessor(example.getProbe()).getIdentifier(); if (identifier == null) { reference.remove(entity.getIdProperty().getFieldName()); } } ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher()); applyPropertySpecs("", reference, example.getProbeType(), matcherAccessor); Document flattened = ObjectUtils.nullSafeEquals(NullHandler.INCLUDE, matcherAccessor.getNullHandler()) ? reference : new Document(SerializationUtils.flattenMap(reference)); Document result = example.getMatcher().isAllMatching() ? flattened : orConcatenate(flattened); return updateTypeRestrictions(result, example); }
@Override public boolean patch(ID id, E data, String... fieldsToDelete) { DBObject dbObject = getDbObject(data); return doUpdate(mongoOperations.getConverter().convertToMongoType(id), dbObject, fieldsToDelete); }