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:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.SensorRepositoryImpl.java

@Override
public boolean decrementUsageCountAndDeleteIfUnused(String id) {
    Update update = new Update().inc("usageCount", -1);
    mongoOperation.updateFirst(idQuery(id), update, Sensor.class, COLLECTION_NAME);
    Sensor s = getSensor(id);/*from  ww  w .j a v  a  2s .com*/
    if (s.getUsageCount() <= 0) {
        deleteSensor(s.getId());
    }
    return true;
}

From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java

@Override
public int updateExperience(Experience experience, String consultantId) {
    Query query = new Query(
            where(ID).is(consultantId).and(EXPERIENCES + "." + Fields.UNDERSCORE_ID).is(experience.getId()));
    Update update = new Update().set(EXPERIENCES + ".$", experience);
    return updateConsultant(query, update).getN();
}

From source file:com.trenako.repositories.mongo.WishListsRepositoryImpl.java

@Override
public void removeItem(WishList wishList, WishListItem item) {
    Update upd = new Update().set("lastModified", now()).inc("numberOfItems", -1).pull("items", item);
    mongoTemplate.updateFirst(query(where("slug").is(wishList.getSlug())), upd, WishList.class);
}

From source file:com.trenako.repositories.mongo.CollectionsRepositoryImpl.java

@Override
public void removeItem(Account owner, CollectionItem item) {
    Collection collection = new Collection(owner);

    Update upd = new Update().pull("items", Maps.map("itemId", item.getItemId()))
            .inc("categories." + CategoriesCount.getKey(item.getCategory()), -1).set("lastModified", now());
    mongo.updateFirst(query(where("owner").is(collection.getOwner())), upd, Collection.class);
}

From source file:com.enitalk.opentok.OpenTokListener.java

@Override
@RabbitListener(queues = "tokbox")
public void onMessage(Message msg) {
    try {/*from   w  w  w. jav a 2s. c o m*/
        ObjectNode tree = (ObjectNode) jackson.readTree(msg.getBody());
        logger.info("Tokbox status came {}", tree);

        Query q = Query.query(Criteria.where("sessionId").is(tree.path("sessionId").asText()));
        HashMap event = mongo.findOne(q, HashMap.class, "events");
        if (event != null) {
            String status = tree.path("status").asText();
            ObjectNode evJson = jackson.convertValue(event, ObjectNode.class);

            HashMap item = jackson.convertValue(tree, HashMap.class);
            item.put("came", new Date());
            Update update = new Update().push("opentok", item);

            switch (status) {
            case "uploaded":
                logger.info("Video uploaded for event {} ", evJson.path("ii").asText());
                break;
            case "paused":
                logger.info("Paused event {}", evJson.path("ii").asText());

                break;
            default:
            }
            mongo.updateFirst(q, update, "events");
        }
    } catch (Exception e) {
        logger.info(ExceptionUtils.getFullStackTrace(e));
    } finally {
    }
}

From source file:org.objectrepository.instruction.dao.InstructionMongoDBImpl.java

@Override
public void removetasks(InstructionType instruction) {
    final DBObject query = new BasicDBObject("fileSet", Normalizers.normalize(instruction.getFileSet()));
    final Update update = new Update().set("workflow", new ArrayList(0));
    mongoTemplate.getCollection(stagingfile).updateMulti(query, update.getUpdateObject());
}

From source file:com.epam.ta.reportportal.database.search.UpdateStatisticsQueryBuilder.java

/**
 * Remove specified custom sub-type for issue statistic of applied element
 * /*  www.  j av  a 2s  . c  o  m*/
 * @param subType
 * @return MongoDB
 */
public static Update dropIssueTypeAware(final StatisticSubType subType) {
    return new Update().unset(ISSUE_COUNTER + "." + valueOf(subType.getTypeRef()).awareStatisticsField() + "."
            + subType.getLocator());
}

From source file:com.trenako.repositories.mongo.WishListsRepositoryImpl.java

@Override
public void changeName(WishList wishList, String newName) {
    Update upd = new Update().set("lastModified", now()).set("name", newName).set("slug",
            wishList.slug(newName));/*from   w  w w .  ja  va 2 s . co m*/
    mongoTemplate.updateFirst(query(where("slug").is(wishList.getSlug())), upd, WishList.class);
}

From source file:it.f2informatica.mongodb.repositories.impl.ConsultantRepositoryImpl.java

@Override
public int removeExperience(String consultantId, String experienceId) {
    Query query = new Query(
            where(ID).is(consultantId).and(EXPERIENCES + "." + Fields.UNDERSCORE_ID).is(experienceId));
    Update update = new Update().pull(EXPERIENCES, findExperience(consultantId, experienceId));
    return updateConsultant(query, update).getN();
}

From source file:org.maodian.flyingcat.im.repository.AccountRepositoryImpl.java

@Override
public void updateContact(String uid, SimpleUser su) {
    Query query = Query.query(Criteria.where(Account.USERNAME).is(uid).and("cont.uid").is(su.getUsername()));
    Update update = new Update().set("cont.$.nick", su.getNickname()).set("cont.$.pin", su.isPendingIn())
            .set("cont.$.pout", su.isPendingOut()).set("cont.$.stat", su.getSubState().name());
    getMongoTemplate().updateFirst(query, update, Account.class);
}