private void readProperties(MongoPersistentEntity<?> entity, PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor, MongoDbPropertyValueProvider valueProvider, ObjectPath currentPath, SpELExpressionEvaluator evaluator) { DbRefResolverCallback callback = null; for (MongoPersistentProperty prop : entity) { if (prop.isAssociation() && !entity.isConstructorArgument(prop)) { if (callback == null) { callback = getDbRefResolverCallback(documentAccessor, currentPath, evaluator); } readAssociation(prop.getRequiredAssociation(), accessor, documentAccessor, dbRefProxyHandler, callback); continue; } // We skip the id property since it was already set if (entity.isIdProperty(prop)) { continue; } if (entity.isConstructorArgument(prop) || !documentAccessor.hasValue(prop)) { continue; } if (prop.isAssociation()) { if (callback == null) { callback = getDbRefResolverCallback(documentAccessor, currentPath, evaluator); } readAssociation(prop.getRequiredAssociation(), accessor, documentAccessor, dbRefProxyHandler, callback); continue; } accessor.setProperty(prop, valueProvider.getPropertyValue(prop)); } }
public boolean isIdProperty(PersistentProperty<?> property) { return delegate.isIdProperty(property); }
private void readProperties(MongoPersistentEntity<?> entity, PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor, MongoDbPropertyValueProvider valueProvider, ObjectPath currentPath, SpELExpressionEvaluator evaluator) { DbRefResolverCallback callback = null; for (MongoPersistentProperty prop : entity) { if (prop.isAssociation() && !entity.isConstructorArgument(prop)) { if (callback == null) { callback = getDbRefResolverCallback(documentAccessor, currentPath, evaluator); } readAssociation(prop.getRequiredAssociation(), accessor, documentAccessor, dbRefProxyHandler, callback); continue; } // We skip the id property since it was already set if (entity.isIdProperty(prop)) { continue; } if (entity.isConstructorArgument(prop) || !documentAccessor.hasValue(prop)) { continue; } if (prop.isAssociation()) { if (callback == null) { callback = getDbRefResolverCallback(documentAccessor, currentPath, evaluator); } readAssociation(prop.getRequiredAssociation(), accessor, documentAccessor, dbRefProxyHandler, callback); continue; } accessor.setProperty(prop, valueProvider.getPropertyValue(prop)); } }
@Override public void partialUpdate(T t) { ID id = getEntityInformation().getId(t); if (null == id) { throw new IllegalArgumentException("ID property should not be null"); } Update update = new Update(); final MongoPersistentEntity<?> persistentEntity = mongoOperations .getConverter().getMappingContext().getPersistentEntity(getEntityInformation().getJavaType()); persistentEntity.doWithProperties((PropertyHandler<MongoPersistentProperty>) persistentProperty -> { if (!persistentEntity.isIdProperty(persistentProperty)) { Object value = Accessible.on(t).field(persistentProperty.getField()).getValue(); if (null != value) { update.set(persistentProperty.getFieldName(), value); } } }); WriteResult writeResult = mongoOperations .updateFirst(query(where(persistentEntity.getIdProperty().getFieldName()).is(id)), update, getEntityInformation().getCollectionName()); if (1 != writeResult.getN()) { throw new IncorrectResultSizeDataAccessException(1, writeResult.getN()); } }