/** * 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); }
private void writeSimpleInternal(Object value, Bson bson, MongoPersistentProperty property) { DocumentAccessor accessor = new DocumentAccessor(bson); accessor.put(property, getPotentiallyConvertedSimpleWrite(value)); }
protected void writeInternal(@Nullable Object obj, Bson bson, @Nullable MongoPersistentEntity<?> entity) { if (obj == null) { return; } if (null == entity) { throw new MappingException("No mapping metadata found for entity of type " + obj.getClass().getName()); } PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(obj); DocumentAccessor dbObjectAccessor = new DocumentAccessor(bson); MongoPersistentProperty idProperty = entity.getIdProperty(); if (idProperty != null && !dbObjectAccessor.hasValue(idProperty)) { Object value = idMapper.convertId(accessor.getProperty(idProperty), idProperty.getFieldType()); if (value != null) { dbObjectAccessor.put(idProperty, value); } } writeProperties(bson, entity, accessor, dbObjectAccessor, idProperty); }
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final Document bson, final ObjectPath path) { SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(bson, spELContext); DocumentAccessor documentAccessor = new DocumentAccessor(bson); PreferredConstructor<S, MongoPersistentProperty> persistenceConstructor = entity.getPersistenceConstructor(); ParameterValueProvider<MongoPersistentProperty> provider = persistenceConstructor != null && persistenceConstructor.hasParameters() ? getParameterProvider(entity, documentAccessor, evaluator, path) : NoOpParameterValueProvider.INSTANCE; EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, provider); if (entity.requiresPropertyPopulation()) { return populateProperties(entity, documentAccessor, path, evaluator, instance); } return instance; }
/** * 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); }
private void writeSimpleInternal(Object value, Bson bson, MongoPersistentProperty property) { DocumentAccessor accessor = new DocumentAccessor(bson); accessor.put(property, getPotentiallyConvertedSimpleWrite(value)); }
protected void writeInternal(@Nullable Object obj, Bson bson, @Nullable MongoPersistentEntity<?> entity) { if (obj == null) { return; } if (null == entity) { throw new MappingException("No mapping metadata found for entity of type " + obj.getClass().getName()); } PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(obj); DocumentAccessor dbObjectAccessor = new DocumentAccessor(bson); MongoPersistentProperty idProperty = entity.getIdProperty(); if (idProperty != null && !dbObjectAccessor.hasValue(idProperty)) { Object value = idMapper.convertId(accessor.getProperty(idProperty)); if (value != null) { dbObjectAccessor.put(idProperty, value); } } writeProperties(bson, entity, accessor, dbObjectAccessor, idProperty); }
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final Document bson, final ObjectPath path) { SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(bson, spELContext); DocumentAccessor documentAccessor = new DocumentAccessor(bson); PreferredConstructor<S, MongoPersistentProperty> persistenceConstructor = entity.getPersistenceConstructor(); ParameterValueProvider<MongoPersistentProperty> provider = persistenceConstructor != null && persistenceConstructor.hasParameters() ? getParameterProvider(entity, documentAccessor, evaluator, path) : NoOpParameterValueProvider.INSTANCE; EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, provider); if (entity.requiresPropertyPopulation()) { return populateProperties(entity, documentAccessor, path, evaluator, instance); } return instance; }