当前位置: 首页>>代码示例>>Java>>正文


Java WriteResult类代码示例

本文整理汇总了Java中com.mongodb.WriteResult的典型用法代码示例。如果您正苦于以下问题:Java WriteResult类的具体用法?Java WriteResult怎么用?Java WriteResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WriteResult类属于com.mongodb包,在下文中一共展示了WriteResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateRetry

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * 更改恢复次数
 *
 * @param id              事务id
 * @param retry           恢复次数
 * @param applicationName 应用名称
 * @return true 成功
 */
@Override
public Boolean updateRetry(String id, Integer retry, 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;
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:28,代码来源:MongoRecoverTransactionServiceImpl.java

示例2: updateParticipant

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * 更新 List<Participant>  只更新这一个字段数据
 *
 * @param tccTransaction 实体对象
 */
@Override
public int updateParticipant(TccTransaction tccTransaction) {
    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(tccTransaction.getTransId()));
    Update update = new Update();
    try {
        update.set("contents", objectSerializer.serialize(tccTransaction.getParticipants()));
    } catch (TccException e) {
        e.printStackTrace();
    }
    final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
    if (writeResult.getN() <= 0) {
        throw new TccRuntimeException("更新数据异常!");
    }
    return 1;
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:22,代码来源:MongoCoordinatorRepository.java

示例3: updateFailTransaction

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * 更新事务失败日志
 *
 * @param mythTransaction 实体对象
 * @return rows 1 成功
 * @throws MythRuntimeException 异常信息
 */
@Override
public int updateFailTransaction(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("更新数据异常!");
    }
    return CommonConstant.SUCCESS;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:25,代码来源:MongoCoordinatorRepository.java

示例4: updateParticipant

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * 更新 List<Participant>  只更新这一个字段数据
 *
 * @param mythTransaction 实体对象
 */
@Override
public int updateParticipant(MythTransaction mythTransaction) throws MythRuntimeException {
    Query query = new Query();
    query.addCriteria(new Criteria("transId").is(mythTransaction.getTransId()));
    Update update = new Update();
    try {
        update.set("contents", objectSerializer.serialize(mythTransaction.getMythParticipants()));
    } catch (MythException e) {
        e.printStackTrace();
    }
    final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName);
    if (writeResult.getN() <= 0) {
        throw new MythRuntimeException("更新数据异常!");
    }
    return CommonConstant.SUCCESS;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:22,代码来源:MongoCoordinatorRepository.java

示例5: saveResourcePlan

import com.mongodb.WriteResult; //导入依赖的package包/类
@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;
}
 
开发者ID:fengzhizi715,项目名称:ProxyPool,代码行数:24,代码来源:ProxyResourceDaoImpl.java

示例6: createPasswordRecoveryToken

import com.mongodb.WriteResult; //导入依赖的package包/类
public SmartiUser createPasswordRecoveryToken(String login) {
    final SmartiUser mongoUser = findUser(login);
    if (mongoUser == null) {
        return null;
    }

    final Date now = new Date(),
            expiry = DateUtils.addHours(now, 24);
    final String token = HashUtils.sha256(UUID.randomUUID() + mongoUser.getLogin());
    final SmartiUser.PasswordRecovery recovery = new SmartiUser.PasswordRecovery(token, now, expiry);

    final WriteResult result = updateMongoUser(mongoUser.getLogin(), Update.update(SmartiUser.FIELD_RECOVERY, recovery));
    if (result.getN() == 1) {
        return getSmaritUser(mongoUser.getLogin());
    } else {
        return null;
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:19,代码来源:MongoUserDetailsService.java

示例7: updateMessage

import com.mongodb.WriteResult; //导入依赖的package包/类
@Override
public Conversation updateMessage(ObjectId conversationId, Message message) {
    final Query query = new Query(Criteria.where("_id").is(conversationId))
            .addCriteria(Criteria.where("messages._id").is(message.getId()));

    final Update update = new Update()
            .set("messages.$", message)
            .currentDate("lastModified");

    final WriteResult writeResult = mongoTemplate.updateFirst(query, update, Conversation.class);
    if (writeResult.getN() == 1) {
        return mongoTemplate.findById(conversationId, Conversation.class);
    } else {
        return null;
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:17,代码来源:ConversationRepositoryImpl.java

示例8: saveIfNotLastModifiedAfter

import com.mongodb.WriteResult; //导入依赖的package包/类
@Override
public Conversation saveIfNotLastModifiedAfter(Conversation conversation, Date lastModified) {
    
    final Query query = new Query();
    query.addCriteria(Criteria.where("_id").is(conversation.getId()));
    query.addCriteria(Criteria.where("lastModified").lte(lastModified));

    BasicDBObject data = new BasicDBObject();
    mongoTemplate.getConverter().write(conversation, data);
    final Update update = new Update();
    data.entrySet().stream()
        .filter(e -> !Objects.equals("lastModified", e.getKey()))
        .forEach(e -> update.set(e.getKey(), e.getValue()));
    update.currentDate("lastModified");

    final WriteResult writeResult = mongoTemplate.updateFirst(query, update, Conversation.class);
    if (writeResult.getN() == 1) {
        return mongoTemplate.findById(conversation.getId(), Conversation.class);
    } else {
        throw new ConcurrentModificationException(
                String.format("Conversation %s has been modified after %tF_%<tT.%<tS (%tF_%<tT.%<tS)", conversation.getId(), lastModified, conversation.getLastModified()));
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:24,代码来源:ConversationRepositoryImpl.java

示例9: shouldInsertOneHeroWithAutomaticObjectId

import com.mongodb.WriteResult; //导入依赖的package包/类
@Test
public void shouldInsertOneHeroWithAutomaticObjectId() {
    //GIVEN
    Address castleWinterfell = new Address("Winterfell", "Westeros", Region.THE_NORTH);

    Set<Human> children = Sets.newHashSet();
    children.add(Hero.createHeroWithoutChildrenAndNoBeasts("Robb", "Stark", castleWinterfell));
    children.add(Heroine.createHeroineWithoutChildrenAndNoBeasts("Sansa", "Stark", castleWinterfell));
    children.add(Heroine.createHeroineWithoutChildrenAndNoBeasts("Arya", "Stark", castleWinterfell));
    children.add(Hero.createHeroWithoutChildrenAndNoBeasts("Bran", "Stark", castleWinterfell));
    children.add(Hero.createHeroWithoutChildrenAndNoBeasts("Rickon", "Stark", castleWinterfell));
    children.add(Hero.createHeroWithoutChildrenAndNoBeasts("Jon", "Snow", castleWinterfell));

    Hero eddardStark = Hero.createHeroWithoutBeasts("Eddard", "Stark", castleWinterfell, children);

    //WHEN
    WriteResult insert = heroes.insert(eddardStark);

    //THEN
    Assertions.assertThat(insert.getError()).isNull();
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:22,代码来源:TestInsertion.java

示例10: shouldAddFieldToTheLightbringer

import com.mongodb.WriteResult; //导入依赖的package包/类
@Test
public void shouldAddFieldToTheLightbringer() {
    //GIVEN
    WeaponDetails details = new WeaponDetails("The one who pulls out this sword from fire will be named Lord's Chosen ...", "Azor Ahai");

    //WHEN
    WriteResult lightbringer = weapons.update("{_id: #}", "Lightbringer").with("{$set: {details: #}}", details);

    //THEN
    assertThat(lightbringer.getError()).isNull();

    //AND WHEN
    Sword sword = weapons.findOne("{_id: 'Lightbringer'}").as(Sword.class);


    //THEN
    assertThat(sword).isNotNull();
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:19,代码来源:TestUpdate.java

示例11: addCall

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * Add the specified mvc to the specified database
 *
 * @param dbSpecPath
 * @param mvc
 * @return
 */
static String addCall(String dbSpecPath, MongoVariantContext mvc) {

    NA12878DBArgumentCollection args = new NA12878DBArgumentCollection(dbSpecPath);

    String errorMessage = null;
    NA12878KnowledgeBase kb = null;
    try {
        kb = new NA12878KnowledgeBase(null, args);
        WriteResult wr = kb.addCall(mvc);
        errorMessage = wr.getError();
    } catch (Exception ex) {
        errorMessage = ex.getMessage();
        if (errorMessage == null) errorMessage = "" + ex;
    } finally {
        if (kb != null) kb.close();
    }

    return errorMessage;
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:27,代码来源:VariantReviewDialog.java

示例12: doPut

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * Perform a single 'put' operation on the local object store.
 *
 * @param ref  Object reference string of the object to be written.
 * @param obj  JSON string encoding the object to be written.
 * @param collection  Collection to put to.
 *
 * @return a ResultDesc object describing the success or failure of the
 *    operation.
 */
private ResultDesc doPut(String ref, String obj, DBCollection collection,
                         boolean requireNew)
{
    String failure = null;
    if (obj == null) {
        failure = "no object data given";
    } else {
        try {
            DBObject objectToWrite = jsonLiteralToDBObject(obj, ref);
            if (requireNew) {
                WriteResult wr = collection.insert(objectToWrite);
            } else {
                DBObject query = new BasicDBObject();
                query.put("ref", ref);
                collection.update(query, objectToWrite, true, false);
            }
        } catch (Exception e) {
            failure = e.getMessage();
        }
    }
    return new ResultDesc(ref, failure);
}
 
开发者ID:FUDCo,项目名称:Elko,代码行数:33,代码来源:MongoObjectStore.java

示例13: doUpdate

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * Perform a single 'update' operation on the local object store.
 *
 * @param ref  Object reference string of the object to be written.
 * @param version  Expected version number of object before updating.
 * @param obj  JSON string encoding the object to be written.
 * @param collection  Collection to put to.
 *
 * @return an UpdateResultDesc object describing the success or failure of
 *    the operation.
 */
private UpdateResultDesc doUpdate(String ref, int version, String obj,
                                  DBCollection collection)
{
    String failure = null;
    boolean atomicFailure = false;
    if (obj == null) {
        failure = "no object data given";
    } else {
        try {
            DBObject objectToWrite = jsonLiteralToDBObject(obj, ref);
            DBObject query = new BasicDBObject();
            query.put("ref", ref);
            query.put("version", version);
            WriteResult result =
                collection.update(query, objectToWrite, false, false);
            if (result.getN() != 1) {
                failure = "stale version number on update";
                atomicFailure = true;
            }
        } catch (Exception e) {
            failure = e.getMessage();
        }
    }
    return new UpdateResultDesc(ref, failure, atomicFailure);
}
 
开发者ID:FUDCo,项目名称:Elko,代码行数:37,代码来源:MongoObjectStore.java

示例14: updateOrCreate

import com.mongodb.WriteResult; //导入依赖的package包/类
@Override
public boolean updateOrCreate(final Collection<MongoApproval> mongoApprovals) {
	boolean result = true;
	for (MongoApproval mongoApproval : mongoApprovals) {
		final Update update = Update
				.update("expiresAt", mongoApproval.getExpiresAt())
				.addToSet("status", mongoApproval.getStatus())
				.addToSet("lastModifiedAt",
						mongoApproval.getLastUpdatedAt());

		final WriteResult writeResult = mongoTemplate.upsert(
				byUserIdAndClientIdAndScope(mongoApproval), update,
				MongoApproval.class);

		if (writeResult.getN() != 1) {
			result = false;
		}
	}
	return result;
}
 
开发者ID:cloudade,项目名称:authorization-server-with-mongodb,代码行数:21,代码来源:MongoApprovalRepositoryImpl.java

示例15: storeToMongoDb

import com.mongodb.WriteResult; //导入依赖的package包/类
/**
 * This method extracts database collection name and inserts passet object in 
 * database.
 * @param object
 *        Object to insert in database
 * @return inserted object
 * @throws ObjectNotStoredException
 */
private FfmaDomainObject storeToMongoDb(FfmaDomainObject object)
	throws ObjectNotStoredException {

	// TODO: check if exists? last time ? etc
	DBCollection mongoCollection = db.getCollectionFromString(object
			.getClass().getSimpleName());
	WriteResult res = mongoCollection.insert((BasicDBObject) object);
	log.debug("storeToMongoDb() coll:" + mongoCollection + ", res: " + res.toString());
	try {
		return retrieveObject(object);
	} catch (Exception e) {
		throw new ObjectNotStoredException(
				"Cannot store and retreive object from db after creation!",
				e);
	}
}
 
开发者ID:ait-ngcms,项目名称:ffma,代码行数:25,代码来源:BaseMongoDbManager.java


注:本文中的com.mongodb.WriteResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。