Example usage for org.springframework.data.mongodb.core.mapping MongoPersistentEntity isIdProperty

List of usage examples for org.springframework.data.mongodb.core.mapping MongoPersistentEntity isIdProperty

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.mapping MongoPersistentEntity isIdProperty.

Prototype

boolean isIdProperty(PersistentProperty<?> property);

Source Link

Document

Returns whether the given PersistentProperty is the id property of the entity.

Usage

From source file:com.epam.ta.reportportal.database.dao.ReportPortalRepositoryImpl.java

@Override
public void partialUpdate(T t) {
    ID id = getEntityInformation().getId(t);
    if (null == id) {
        throw new IllegalArgumentException("ID property should not be null");
    }//www .  j  av a2 s .c  om

    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());
    }
}