@Override protected Field createPropertyField(MongoPersistentEntity<?> entity, String key, MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext) { return entity == null ? super.createPropertyField(entity, key, mappingContext) : new MetadataBackedUpdateField(entity, key, mappingContext); }
@Override public String convert(MongoPersistentProperty source) { return super.convert(source) == null ? null : mapper.mapPropertyName(source); } }
private DbRefResolverCallback getDbRefResolverCallback(DocumentAccessor documentAccessor, ObjectPath currentPath, SpELExpressionEvaluator evaluator) { return new DefaultDbRefResolverCallback(documentAccessor.getDocument(), currentPath, evaluator, MappingMongoConverter.this); }
private static MongoConverter getDefaultMongoConverter(MongoDbFactory factory) { DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory); MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList()); MongoMappingContext mappingContext = new MongoMappingContext(); mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); mappingContext.afterPropertiesSet(); MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext); converter.setCustomConversions(conversions); converter.afterPropertiesSet(); return converter; }
public StringConverter( MongoDbFactory mongoDbFactory, MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext) { super(new DefaultDbRefResolver(mongoDbFactory), mappingContext); }
/** * Creates a new {@link QueryMapper} with the given {@link MongoConverter}. * * @param converter must not be {@literal null}. */ public QueryMapper(MongoConverter converter) { Assert.notNull(converter, "MongoConverter must not be null!"); this.conversionService = converter.getConversionService(); this.converter = converter; this.mappingContext = converter.getMappingContext(); this.exampleMapper = new MongoExampleMapper(converter); this.schemaMapper = new MongoJsonSchemaMapper(converter); }
/** * Create a new {@link MongoTypeMapper} given {@link MongoConverter}. * * @param converter must not be {@literal null}. */ public MongoExampleMapper(MongoConverter converter) { this.converter = converter; this.mappingContext = converter.getMappingContext(); }
/** * Returns whether the given {@link String} is the type key. * * @param key * @return * @see MongoTypeMapper#isTypeKey(String) * @since 2.2 */ protected boolean isTypeKey(String key) { return converter.getTypeMapper().isTypeKey(key); }
private void writeSimpleInternal(Object value, Bson bson, MongoPersistentProperty property) { DocumentAccessor accessor = new DocumentAccessor(bson); accessor.put(property, getPotentiallyConvertedSimpleWrite(value)); }
private ParameterValueProvider<MongoPersistentProperty> getParameterProvider(MongoPersistentEntity<?> entity, DocumentAccessor source, SpELExpressionEvaluator evaluator, ObjectPath path) { AssociationAwareMongoDbPropertyValueProvider provider = new AssociationAwareMongoDbPropertyValueProvider(source, evaluator, path); PersistentEntityParameterValueProvider<MongoPersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<>( entity, provider, path.getCurrentObject()); return new ConverterAwareSpELExpressionParameterValueProvider(evaluator, conversionService, parameterProvider, path); }
/** * Return the {@link Converter} to use for creating the mapped key of an association. Default implementation is * {@link AssociationConverter}. * * @return * @since 1.7 */ protected Converter<MongoPersistentProperty, String> getAssociationConverter() { return new AssociationConverter(getAssociation()); }
@Override public String getMappedKey() { return this.getPath() == null ? key : super.getMappedKey(); }
@Override protected Converter<MongoPersistentProperty, String> getAssociationConverter() { return new UpdateAssociationConverter(getAssociation(), key); }
protected Object convertAssociation(Object source, Field field) { return convertAssociation(source, field.getProperty()); }
@Override public Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator, ObjectPath path) { return new MongoDbPropertyValueProvider(bson, evaluator, path).getPropertyValue(prop); }
/** * Creates a new {@link MongoDbPropertyValueProvider} for the given source, {@link SpELExpressionEvaluator} and * {@link ObjectPath}. * * @param source must not be {@literal null}. * @param evaluator must not be {@literal null}. * @param path must not be {@literal null}. */ MongoDbPropertyValueProvider(Bson source, SpELExpressionEvaluator evaluator, ObjectPath path) { this(new DocumentAccessor(source), evaluator, path); }
/** * 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); }
private DBRef createDbRefFor(Object source, MongoPersistentProperty property) { if (source instanceof DBRef) { return (DBRef) source; } return converter.toDBRef(source, property); }
@Override public String convert(MongoPersistentProperty source) { return keyMapper.mapPropertyName(source); } }
@Override public Object resolve(MongoPersistentProperty property) { return resolver.getValueInternal(property, surroundingObject, evaluator, path); } }