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

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

Introduction

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

Prototype

Update

Source Link

Usage

From source file:net.cit.tetrad.resource.ManagementResource.java

/**
 *    update//from w  w w . j a v  a2s  . c  o m
 * @param dto
 * @return
 * @throws Exception
 */
public boolean update(Device dto) throws Exception {
    log.debug("start - update(Device dto)");
    boolean isUpdated = false;
    String name;
    String tablenm = TABLENAME[1];
    Class<?> classname = managementDao.getDtoClassNm(tablenm);

    Query query = new Query();
    Update update = new Update();
    Object obj = new Object();
    try {

        query = setIpPort(dto.getIp(), dto.getPort(), dto.getIdx());
        obj = monadService.getFind(query, classname);//??ip,port  ?
        query = notIdxsetUid(dto.getIdx(), dto.getUid());

        update.set("isFinishedInitailRrd", dto.isFinishedInitailRrd());
        query = setIdx(dto.getIdx());
        monadService.update(query, update, classname);

        isUpdated = true;

    } catch (Exception e) {
        log.error(e, e);
    }
    log.debug("end - update(Device dto)");
    return isUpdated;
}

From source file:net.cit.tetrad.resource.ManagementResource.java

/**
 * ? ?./*from w  w w. j a  va2  s.co  m*/
 * @param dto
 */
public void updateCritical(CommonDto dto) {
    Update update = new Update();
    Query query = new Query();
    update.set("groupCode", dto.getGroupCode());
    query = setDeviceCode(dto.getIdx());
    Object obj = monadService.getFind(query, Critical.class);//?? name  ?
    if (obj != null)
        monadService.updateMulti(query, update, MAV_CRITICAL);
}

From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java

/**
 * ??/*from   w w  w  .  j  a v  a2 s .  c o  m*/
 *
 * @param userId Id
 * @return ?Token
 * @throws ApiException
 */
private String refreshUserToken(String userId) throws ApiException {
    UserToken userToken = cacheManager.getUserToken(userId);
    String token = CodeGenerator.generatorId();
    if (null == userToken) {
        LOG.warn("Fail to get token and expire info from userToken, new a token");
        userToken = new UserToken();
        userToken.setUserId(userId);
        userToken.setToken(token);
        userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE,
                PropertiesUtil.getProperty("carplay.token.over.date", 7)));
        userTokenDao.save(userToken);
    } else {
        userToken.setToken(token);
        userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE,
                PropertiesUtil.getProperty("carplay.token.over.date", 7)));

        Update update = new Update();
        update.set("token", userToken.getToken());
        update.set("expire", userToken.getExpire());
        UserToken toFind = userTokenDao.findById(userToken.getId());
        //TODO
        if (null == toFind) {
            userToken = new UserToken();
            userToken.setId(null);
            userToken.setUserId(userId);
            userToken.setToken(token);
            userToken.setExpire(DateUtil.addTime(DateUtil.getDate(), Calendar.DATE,
                    PropertiesUtil.getProperty("carplay.token.over.date", 7)));
            userTokenDao.save(userToken);
        } else {
            userTokenDao.update(userToken.getId(), update);
        }
    }
    cacheManager.setUserToken(userToken);

    return token;
}

From source file:net.cit.tetrad.resource.ManagementResource.java

private void unGroupBind(String groupBind) {
    Query q = new Query();
    q = setgroupBind(q, groupBind);//from  w w  w . java  2 s .com
    Update update = new Update();
    update.unset("groupBind");
    monadService.updateMulti(q, update, MAV_CRITICAL, false);
}

From source file:net.cit.tetrad.resource.ManagementResource.java

@RequestMapping(value = "/popup_event.do")
public ModelAndView popup_event_update(HttpServletRequest request, HttpServletResponse response,
        CommonDto dto) {//from w ww .  ja va  2s. c  o m
    log.debug("start - popup_event");

    ModelAndView mav = new ModelAndView();

    String groupText = dto.getGroupText();
    String[] strLst = request.getParameter("Lst").split("&");
    int[] idxLst = new int[strLst.length];

    for (int i = 0; i < strLst.length; i++) {
        String[] temp = strLst[i].split("=");
        idxLst[i] = Integer.valueOf(temp[1]);
    }

    Query query = new Query();
    Update update = new Update();

    int idx = 0;

    for (int i = 0; i < idxLst.length; i++) {
        idx = idxLst[i];
        query = setIdx(idx);
        update.set("idx", idx).set("groupBind", groupText).set("groupCnt", idxLst.length);
        monadService.update(query, update, Critical.class);
    }

    mav.addObject("groupName", groupText);
    mav.setViewName(PATH_MANAGEMEMT + "popup_event");
    log.debug("end - popup_event param : groupBind");
    return mav;
}

From source file:org.sipfoundry.commons.userdb.profile.UserProfileServiceImpl.java

@Override
public void updateBranchAddress(String branchName, Address address) {
    m_template.updateMulti(new Query(Criteria.where(BRANCH_NAME).is(branchName)),
            new Update().set(BRANCH_ADDRESS, address), USER_PROFILE_COLLECTION);
}

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

@Override
public boolean patch(String type, String collectionName, String id, Map<String, Object> newValues) {
    boolean result = false;
    Entity entity = new MongoEntity(type, id, newValues, null);
    validator.validatePresent(entity);/*from  w w  w  . j a va 2s  .c  o m*/
    validator.validateNaturalKeys(entity, false);
    keyEncoder.encodeEntityKey(entity);
    if (subDocs.isSubDoc(collectionName)) {

        // prepare to find desired record to be patched
        Query query = new Query();
        query.addCriteria(Criteria.where("_id").is(idConverter.toDatabaseId(id)));
        query.addCriteria(createTenantCriteria(collectionName));

        // prepare update operation for record to be patched
        Update update = new Update();
        for (Entry<String, Object> patch : newValues.entrySet()) {
            update.set("body." + patch.getKey(), patch.getValue());
        }
        result = subDocs.subDoc(collectionName).doUpdate(query, update);
    } else if (containerDocumentAccessor.isContainerDocument(type)) {
        result = containerDocumentAccessor.update(type, id, newValues, collectionName);
    } else {
        result = super.patch(type, collectionName, id, newValues);
        if (result && EntityNames.EDUCATION_ORGANIZATION.equals(collectionName)
                && newValues.containsKey(ParameterConstants.PARENT_EDUCATION_AGENCY_REFERENCE)) {
            // TODO can be optimized to take an edOrg Id
            updateAllSchoolLineage();
        }
    }

    if (result && denormalizer.isDenormalizedDoc(collectionName)) {
        Entity updateEntity;
        if (subDocs.isSubDoc(collectionName)) {
            updateEntity = subDocs.subDoc(collectionName).findById(id);
        } else {
            updateEntity = super.findById(collectionName, id);
        }

        Update update = new Update();
        for (Map.Entry<String, Object> patch : newValues.entrySet()) {
            update.set(patch.getKey(), patch.getValue());
        }

        denormalizer.denormalization(collectionName).doUpdate(updateEntity, update);
    }

    if (journal != null) {
        journal.journal(id, collectionName, false);
    }

    return result;
}

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

@Override
protected Update getUpdateCommand(Entity entity, boolean isSuperdoc) {
    // set up update query
    Update update = new Update();

    // It is possible for the body and metaData keys to be absent in the case
    // of "orphaned" subDoc data when a document has been "hollowed out"
    Map<String, Object> entityBody = entity.getBody();
    if (entityBody != null && entityBody.size() == 0) {
        update.unset("body");
    } else {/*  w w w  .j a  v  a  2s .co m*/
        update.set("body", entityBody);
    }
    Map<String, Object> entityMetaData = entity.getMetaData();
    if (entityMetaData != null && entityMetaData.size() == 0) {
        update.unset("metaData");
    } else {
        update.set("metaData", entityMetaData);
    }

    // update should also set type in case of upsert
    String entityType = entity.getType();
    if (entityType != null && !entityType.isEmpty()) {
        update.set("type", entityType);
    }
    // superdoc need to update subdoc fields outside body
    if (isSuperdoc && entity.getEmbeddedData() != null) {
        Set<String> subdocFields = FullSuperDoc.FULL_ENTITIES.get(entity.getType());
        if (subdocFields != null) {
            for (String subdocField : subdocFields) {
                List<Entity> subdocEntities = entity.getEmbeddedData().get(subdocField);
                if (subdocEntities != null && subdocEntities.size() > 0) {
                    List<Map<String, Object>> updateEntities = new ArrayList<Map<String, Object>>();
                    for (Entity subdocEntity : subdocEntities) {
                        Map<String, Object> updateEntity = new HashMap<String, Object>();
                        updateEntity.put("_id", subdocEntity.getEntityId());
                        updateEntity.put("body", subdocEntity.getBody());
                        updateEntity.put("type", subdocEntity.getType());
                        updateEntity.put("metaData", subdocEntity.getMetaData());
                        updateEntities.add(updateEntity);
                    }
                    update.set(subdocField, updateEntities);
                } else {
                    update.unset(subdocField);
                }
            }
        }
    }
    return update;
}

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

/**
 * Updates the cached education organization hierarchy for the specified school
 *
 * @param schoolId/*from w  w w  .  j ava2 s  .  com*/
 * @return whether the update succeeded
 */
private boolean updateSchoolLineage(String schoolId) {
    try {
        NeutralQuery query = new NeutralQuery(
                new NeutralCriteria("_id", NeutralCriteria.OPERATOR_EQUAL, schoolId));

        Update update = new Update();
        update.set("metaData.edOrgs", new ArrayList<String>(fetchLineage(schoolId, new HashSet<String>())));
        super.doUpdate(EntityNames.EDUCATION_ORGANIZATION, query, update);
    } catch (RuntimeException e) {
        LOG.error("Failed to update educational organization lineage for school with Id " + schoolId + ". "
                + e.getMessage() + ".  Related data will not be visible.  Re-ingestion required.");
        throw e;
    }
    return true;
}

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 .  ja  v  a2 s .co 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());
            }
        }
    }

    return updateFirst(convertedQuery, convertedUpdate, collectionName);
}