Example usage for org.springframework.data.mongodb.core.query Update pushAll

List of usage examples for org.springframework.data.mongodb.core.query Update pushAll

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Update pushAll.

Prototype

@Deprecated
public Update pushAll(String key, Object[] values) 

Source Link

Document

Update using the $pushAll update modifier.

Usage

From source file:org.slc.sli.dal.repository.MongoRepository.java

public WriteResult updateFirst(NeutralQuery query, Map<String, Object> update, String collectionName) {
    // Enforcing the tenantId query. The rationale for this is all CRUD
    // Operations should be restricted based on tenant.
    this.addDefaultQueryParams(query, collectionName);

    Query convertedQuery = this.queryConverter.convert(collectionName, query);
    Update convertedUpdate = new Update();

    for (Map.Entry<String, Object> entry : update.entrySet()) {
        String operation = entry.getKey();
        @SuppressWarnings("unchecked")
        Map<String, Object> operands = (Map<String, Object>) entry.getValue();

        if (operation.equals("push")) {
            for (Map.Entry<String, Object> fieldValues : operands.entrySet()) {
                convertedUpdate.push(fieldValues.getKey(), fieldValues.getValue());
            }//from w  w w.  j av a2  s. com
        } else if (operation.equals("pushAll")) {
            for (Map.Entry<String, Object> fieldValues : operands.entrySet()) {
                convertedUpdate.pushAll(fieldValues.getKey(), (Object[]) fieldValues.getValue());
            }
        } else if (operation.equals("addToSet")) {
            for (Map.Entry<String, Object> fieldValues : operands.entrySet()) {
                convertedUpdate.addToSet(fieldValues.getKey(), fieldValues.getValue());
            }
        }
    }

    return updateFirst(convertedQuery, convertedUpdate, collectionName);
}

From source file:org.slc.sli.dal.repository.MongoRepository.java

@Override
public WriteResult updateMulti(NeutralQuery query, Map<String, Object> update, String collectionName) {
    // Enforcing the tenantId query. The rationale for this is all CRUD
    // Operations should be restricted based on tenant.
    this.addDefaultQueryParams(query, collectionName);

    Query convertedQuery = this.queryConverter.convert(collectionName, query);
    Update convertedUpdate = new Update();

    for (Map.Entry<String, Object> entry : update.entrySet()) {
        String operation = entry.getKey();
        @SuppressWarnings("unchecked")
        Map<String, Object> operands = (Map<String, Object>) entry.getValue();

        if (operation.equals("push")) {
            for (Map.Entry<String, Object> fieldValues : operands.entrySet()) {
                convertedUpdate.push(fieldValues.getKey(), fieldValues.getValue());
            }//from   w  w  w  .  j  a  va  2  s.c  o m
        } else if (operation.equals("pushAll")) {
            for (Map.Entry<String, Object> fieldValues : operands.entrySet()) {
                convertedUpdate.pushAll(fieldValues.getKey(), (Object[]) fieldValues.getValue());
            }
        } else if (operation.equals("addToSet")) {
            for (Map.Entry<String, Object> fieldValues : operands.entrySet()) {
                convertedUpdate.addToSet(fieldValues.getKey(), fieldValues.getValue());
            }
        }
    }
    guideIfTenantAgnostic(collectionName);
    return template.updateMulti(convertedQuery, convertedUpdate, collectionName);
}

From source file:piecework.repository.concrete.ProcessInstanceRepositoryCustomImpl.java

private static void include(Update update, List<Attachment> attachments) {
    if (attachments != null && !attachments.isEmpty()) {
        Object[] attachmentIds = new Object[attachments.size()];
        int count = 0;
        for (Attachment attachment : attachments) {
            attachmentIds[count++] = attachment.getAttachmentId();
        }/*from  w w w  .  j a v  a 2s .  c  o  m*/
        update.pushAll("attachmentIds", attachmentIds);
    }
}