@Override
  public boolean removeCharacter(String characterId) {
    Query q = new Query();
    q.addCriteria(Criteria.where("id").is(characterId));

    WriteResult w = mongoOp.remove(q, Character.class);
    if (w.isUpdateOfExisting()) return true;
    else return false;
  }
 @Override
 public boolean updateSysAccount(String userName, Long state) {
   MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo();
   Update update = new Update();
   update.set("acstate", state);
   WriteResult writeResult =
       mongoTemplate.updateFirst(
           Query.query(Criteria.where("userName").is(userName)), update, "sys_user");
   return writeResult.isUpdateOfExisting();
 }
 @Override
 public boolean updateBaiDuName(String name, Long baiduId) {
   MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo();
   Update update = new Update();
   update.set("bdAccounts.$.baiduRemarkName", name);
   WriteResult writeResult =
       mongoTemplate.updateFirst(
           Query.query(Criteria.where("bdAccounts._id").is(baiduId)), update, "sys_user");
   return writeResult.isUpdateOfExisting();
 }
 @Override
 public boolean updatePwd(String account, String pwd) {
   MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo();
   WriteResult writeResult =
       mongoTemplate.updateFirst(
           Query.query(Criteria.where("userName").is(account)),
           Update.update("password", pwd),
           "sys_user");
   return writeResult.isUpdateOfExisting();
 }
 @Override
 public boolean setCover(String characterId, String coverId) {
   Query q = new Query();
   q.addCriteria(Criteria.where("id").is(characterId));
   Update u = new Update();
   u.set("cover", coverId);
   WriteResult w = mongoOp.updateFirst(q, u, User.class);
   if (w.isUpdateOfExisting()) return true;
   else return false;
 }
  @Override
  public boolean addPostToCharacter(String id, PostReference postReference) {
    Query q = new Query();
    q.addCriteria(Criteria.where("id").is(id));
    Update u = new Update();
    u.push("posts", postReference);
    WriteResult w = mongoOp.updateFirst(q, u, Character.class);

    if (w.isUpdateOfExisting()) return true;
    else return false;
  }
 @Override
 public int updateAccountStruts(String userName) {
   MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo();
   WriteResult writeResult =
       mongoTemplate.updateFirst(
           Query.query(Criteria.where("userName").is(userName)),
           Update.update("state", 1),
           "sys_user");
   int i = 0;
   if (writeResult.isUpdateOfExisting()) i = 1;
   return i;
 }
  @Override
  public boolean removePostFromCharacter(String id, String postId) {
    Query q = new Query();
    q.addCriteria(Criteria.where("id").is(id));

    PostReference post = new PostReference();
    post.setId(postId);

    Update u = new Update();
    u.pull("posts", post);

    WriteResult w = mongoOp.updateFirst(q, u, Character.class);
    if (w.isUpdateOfExisting()) return true;
    else return false;
  }
示例#9
0
 /**
  * 下午2:18:26
  *
  * @author zhangyh2 TODO 更新该条数据
  */
 public static boolean update(final AddressModel model) {
   final DBCollection collection = DBMongo.getInstance().getDB().getCollection(tablename);
   try {
     // 增删查改必须放到线程中进行。否则报错。
     BasicDBObject des = new BasicDBObject();
     des.put("name", model.getName());
     des.put("tel", model.getTel());
     des.put("province", model.getProvince());
     des.put("city", model.getCity());
     des.put("district", model.getDistrict());
     des.put("zipcode", model.getZipcode());
     des.put("token", model.getToken());
     WriteResult dbObject = collection.update(getQuery(model.get_id()), des);
     return dbObject.isUpdateOfExisting();
   } catch (Exception e) {
     // TODO: handle exception
   }
   return false;
 }