Java Code Examples for com.mongodb.WriteResult#getN()

The following examples show how to use com.mongodb.WriteResult#getN() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyResourceDaoImpl.java    From ProxyPool with Apache License 2.0 6 votes vote down vote up
@Override
public boolean saveResourcePlan(ResourcePlan resourcePlan) {
    boolean result = false;
    if(resourcePlan.getAddTime() == 0) { //insert
        resourcePlan.setAddTime(new Date().getTime());
        resourcePlan.setModTime(new Date().getTime());

        mongoTemplate.save(resourcePlan, Constant.COL_NAME_RESOURCE_PLAN);
        result = Preconditions.isNotBlank(resourcePlan.getId());

    } else {                            //update
        Query query = new Query().addCriteria(Criteria.where("_id").is(resourcePlan.getId()));
        Update update = new Update();
        update.set("startPageNum", resourcePlan.getStartPageNum());
        update.set("endPageNum", resourcePlan.getEndPageNum());
        update.set("modTime", new Date().getTime());

        WriteResult writeResult = mongoTemplate.updateFirst(query, update, Constant.COL_NAME_RESOURCE_PLAN);
        result = writeResult!=null && writeResult.getN() > 0;
    }

    return result;
}
 
Example 2
Source File: MongoRecoverTransactionServiceImpl.java    From Raincat with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Boolean updateRetry(final String id, final Integer retry, final String applicationName) {
    if (StringUtils.isBlank(id)
            || StringUtils.isBlank(applicationName)
            || Objects.isNull(retry)) {
        return Boolean.FALSE;
    }
    final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName);

    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(id));
    Update update = new Update();
    update.set("lastTime", DateUtils.getCurrentDateTime());
    update.set("retriedCount", retry);
    final WriteResult writeResult = mongoTemplate.updateFirst(query, update,
            MongoAdapter.class, mongoTableName);
    if (writeResult.getN() <= 0) {
        throw new TransactionRuntimeException("更新数据异常!");
    }
    return Boolean.TRUE;
}
 
Example 3
Source File: MongoLogServiceImpl.java    From myth with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean updateRetry(final String id, final Integer retry, final String appName) {
    if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) {
        return Boolean.FALSE;
    }
    final String mongoTableName = RepositoryPathUtils.buildMongoTableName(appName);
    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(id));
    Update update = new Update();
    update.set("lastTime", DateUtils.getCurrentDateTime());
    update.set("retriedCount", retry);
    final WriteResult writeResult = mongoTemplate.updateFirst(query, update,
            MongoAdapter.class, mongoTableName);
    if (writeResult.getN() <= 0) {
        throw new RuntimeException("更新数据异常!");
    }
    return Boolean.TRUE;
}
 
Example 4
Source File: UserService.java    From sanshanblog with Apache License 2.0 6 votes vote down vote up
/**
 * 更改密码
 * @param code
 * @param password
 * @param responseMsgVO
 */
public void changePwd(String code, String password, ResponseMsgVO responseMsgVO) {
    String username=  UserContextHandler.getUsername();


    UserDO userDO = userRepository.findByUsername(username);
    log.info("用户:{}更改密码",userDO.getUsername());
    String key = CODE_PREFIX + CodeTypeEnum.CHANGE_PWD.getValue() + userDO.getEmail();
    String value = redisTemplate.opsForValue().get(key);
    if (!StringUtils.equals(code, value)) {
        responseMsgVO.buildWithMsgAndStatus(PosCodeEnum.PARAM_ERROR, "验证码错误");
        return;
    }

    if (!checkPassWordLegal(password, responseMsgVO)){
        return;
    }

    // 更新到mongo数据库
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    WriteResult result = userRepository.changePassword(username, passwordEncoder.encode(password));
    if (result.getN() == 0) {
        responseMsgVO.buildWithMsgAndStatus(PosCodeEnum.PARAM_ERROR, "更新失败");
        return;
    }
    responseMsgVO.buildOK();
}
 
Example 5
Source File: MongoJobFeedbackQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(String jobClientNodeGroup, String id) {
    Query<JobFeedbackPo> query = createQuery(jobClientNodeGroup);
    query.field("id").equal(id);
    WriteResult wr = template.delete(query);
    return wr.getN() == 1;
}
 
Example 6
Source File: MongoRepeatJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(String jobId) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.field("jobId").equal(jobId);
    WriteResult wr = template.delete(query);
    return wr.getN() == 1;
}
 
Example 7
Source File: DeleteVo.java    From tangyuan2 with GNU General Public License v3.0 5 votes vote down vote up
public int delete(DBCollection collection, WriteConcern writeConcern) {
	DBObject query = new BasicDBObject();
	if (null != condition) {
		this.condition.setQuery(query, null);
	}

	log(query);

	// WriteResult result = collection.remove(query, WriteConcern.ACKNOWLEDGED);
	WriteResult result = collection.remove(query, writeConcern);
	// collection.remove(query)
	// System.out.println(query.toString());
	return result.getN();
}
 
Example 8
Source File: MongoCronJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(String jobId) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.field("jobId").equal(jobId);
    WriteResult wr = template.delete(query);
    return wr.getN() == 1;
}
 
Example 9
Source File: ProxyResourceDaoImpl.java    From ProxyPool with Apache License 2.0 5 votes vote down vote up
@Override
public boolean saveProxyResource(ProxyResource proxyResource) {
    boolean result = false;
    if(Preconditions.isBlank(proxyResource.getResId())) {            //insert
        proxyResource.setResId(commonDao.getNextSequence(Constant.COL_NAME_PROXY_RESOURCE).getSequence());
        proxyResource.setAddTime(new Date().getTime());
        proxyResource.setModTime(new Date().getTime());
        mongoTemplate.save(proxyResource, Constant.COL_NAME_PROXY_RESOURCE);

        result = Preconditions.isNotBlank(proxyResource.getId());
    } else {                                                        //update
        Query query = new Query().addCriteria(Criteria.where("resId").is(proxyResource.getResId()));
        Update update = new Update();
        update.set("webName", proxyResource.getWebName());
        update.set("webUrl", proxyResource.getWebUrl());
        update.set("pageCount", proxyResource.getPageCount());
        update.set("prefix", proxyResource.getPrefix());
        update.set("suffix", proxyResource.getSuffix());
        update.set("parser", proxyResource.getParser());
        update.set("modTime", new Date().getTime());

        WriteResult writeResult = mongoTemplate.updateFirst(query, update, Constant.COL_NAME_PROXY_RESOURCE);

        result = writeResult!=null && writeResult.getN() > 0;
    }
    return result;
}
 
Example 10
Source File: ProxyDaoImpl.java    From ProxyPool with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deleteProxyById(String id) {

    Query query = new Query(Criteria.where("id").is(id));
    WriteResult writeResult = mongoTemplate.remove(query, ProxyData.class, Constant.COL_NAME_PROXY);
    return writeResult!=null && writeResult.getN() > 0;
}
 
Example 11
Source File: ProxyDaoImpl.java    From ProxyPool with Apache License 2.0 5 votes vote down vote up
@Override
public boolean updateProxyById(String id) {

    Query query = new Query(Criteria.where("id").is(id));
    Update update = new Update();
    update.set("lastSuccessfulTime", new Date().getTime());        //最近一次验证成功的时间
    WriteResult writeResult = mongoTemplate.updateFirst(query, update, ProxyData.class,Constant.COL_NAME_PROXY);
    return writeResult!=null && writeResult.getN() > 0;
}
 
Example 12
Source File: AdminIndexService.java    From sanshanblog with Apache License 2.0 5 votes vote down vote up
private Boolean changeUserInfo(UserDO userDO){
    WriteResult result= userRepository.changeUserInfo(userDO);
    //转换DTO对象
    UserDTO userDTO = UserConvert.doToDto(userDO);
    Boolean eschange=  elasticSearchService.userAdd(userDTO);
    if (eschange!=null && result.getN()!=0){
        return true;
    }else {
        return false;
    }
}
 
Example 13
Source File: MongoDataHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method deletes the entity from the collection for a given key.
 *
 * @param tableName Name of the table
 * @param entity    Entity
 * @throws ODataServiceFault
 */
@Override
public boolean deleteEntityInTable(String tableName, ODataEntry entity) throws ODataServiceFault {
    String documentId = entity.getValue(DOCUMENT_ID);
    WriteResult delete = jongo.getCollection(tableName).remove(new ObjectId(documentId));
    int wasDeleted = delete.getN();
    if (wasDeleted == 1) {
        return delete.wasAcknowledged();
    } else {
        throw new ODataServiceFault("Document ID: " + documentId + " does not exist in "
                + "collection: " + tableName + ".");
    }
}
 
Example 14
Source File: MongoCoordinatorRepository.java    From myth with Apache License 2.0 5 votes vote down vote up
@Override
public int updateStatus(final String id, final Integer status) throws MythRuntimeException {
    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(id));
    Update update = new Update();
    update.set("status", status);
    final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
    if (writeResult.getN() <= 0) {
        throw new MythRuntimeException(ERROR);
    }
    return CommonConstant.SUCCESS;
}
 
Example 15
Source File: MongoSuspendJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(String jobId) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.field("jobId").equal(jobId);
    WriteResult wr = template.delete(query);
    return wr.getN() == 1;
}
 
Example 16
Source File: MongoCoordinatorRepository.java    From myth with Apache License 2.0 5 votes vote down vote up
@Override
public void updateFailTransaction(final MythTransaction mythTransaction) throws MythRuntimeException {
    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(mythTransaction.getTransId()));
    Update update = new Update();
    update.set("status", mythTransaction.getStatus());
    update.set("errorMsg", mythTransaction.getErrorMsg());
    update.set("lastTime", new Date());
    update.set("retriedCount", mythTransaction.getRetriedCount());
    final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
    if (writeResult.getN() <= 0) {
        throw new MythRuntimeException(ERROR);
    }
}
 
Example 17
Source File: MongoExecutableJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(String taskTrackerNodeGroup, String jobId) {
    String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup);
    Query<JobPo> query = template.createQuery(tableName, JobPo.class);
    query.field("jobId").equal(jobId);
    WriteResult wr = template.delete(query);
    return wr.getN() == 1;
}
 
Example 18
Source File: MongoExecutingJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(String jobId) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.field("jobId").equal(jobId);
    WriteResult wr = template.delete(query);
    return wr.getN() == 1;
}
 
Example 19
Source File: EntityAuthService.java    From restfiddle with Apache License 2.0 3 votes vote down vote up
public boolean logout(String llt){

DBCollection dbCollection = mongoTemplate.getCollection(ENTITY_AUTH);

BasicDBObject queryObject = new BasicDBObject();
queryObject.append("_id", new ObjectId(llt));
WriteResult result = dbCollection.remove(queryObject);

return result.getN() == 1;
   }
 
Example 20
Source File: MailDao.java    From game-server with MIT License 2 votes vote down vote up
/**
 * 删除邮件
 * @author JiangZhiYong
 * @QQ 359135103
 * 2017年9月21日 下午4:23:52
 * @param id
 * @return
 */
public static int deleteMail(long id) {
	WriteResult writeResult = mailDao.deleteById(id);
	return writeResult.getN();
}