Пример #1
0
  @Override
  public long nextVal(String key) throws SequenceException {
    Query query = new Query(Criteria.where("_id").is(key));

    Update update = new Update();
    update.inc("seq", 1);

    FindAndModifyOptions options = new FindAndModifyOptions();
    options.returnNew(true);

    Sequence sequence = mongoOperation.findAndModify(query, update, options, Sequence.class);

    if (sequence == null) throw new SequenceException("Unable to get sequence id for key : " + key);

    return sequence.getSeq();
  }
Пример #2
0
  /**
   * Updating sequence details
   *
   * @param key
   * @return
   */
  public Long updateSequence(String key) {

    // Building query
    Query query = new Query();
    query.addCriteria(Criteria.where("_id").is(key));

    // Increase Sequence Id by 1
    Update update = new Update();
    update.inc("sequence", 1);

    FindAndModifyOptions options = new FindAndModifyOptions();
    options.returnNew(true);

    Sequence sequence = hamesDataStore.findAndModify(query, update, options, Sequence.class);

    return sequence.getSequence();
  }
  @Override
  public Comment setComment(Comment c) {
    Query q = new Query();
    q.addCriteria(
        Criteria.where("idPath")
            .is(c.getIdPath())
            .andOperator(Criteria.where("deviceId").is(c.getDeviceId())));

    Update u = new Update();
    u.set("idPath", c.getIdPath());
    u.set("idTicket", c.getIdTicket());
    u.set("content", c.getContent());
    u.set("author", c.getAuthor());
    u.set("deviceId", c.getDeviceId());
    u.set("title", c.getTitle());
    u.set("rating", c.getRating());
    u.set("realdate", c.getRealdate());
    FindAndModifyOptions options = new FindAndModifyOptions();
    options.upsert(true);
    options.returnNew(true);
    return mongoOp.findAndModify(q, u, options, Comment.class);
  }
Пример #4
-1
 @Override
 public Character updateCharacter(String id, Update update) {
   Query q = new Query();
   q.addCriteria(Criteria.where("id").is(id));
   FindAndModifyOptions options = new FindAndModifyOptions();
   options.returnNew(true);
   return mongoOp.findAndModify(q, update, options, Character.class);
 }