@Override
 public void commit(Change change) {
   if (change.getOperationType() != OperationType.DELETE) {
     try {
       Object targetObject = change.getNewObject();
       Query removeQuery = createFindQuery(targetObject);
       Update update = new Update().unset("tid");
       mongoOperations.findAndModify(removeQuery, update, targetObject.getClass());
     } catch (Exception exc) {
       throw new RuntimeException(exc);
     }
   }
 }
Ejemplo n.º 2
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();
  }
  @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);
  }
Ejemplo n.º 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);
 }