Example usage for com.mongodb WriteResult toString

List of usage examples for com.mongodb WriteResult toString

Introduction

In this page you can find the example usage for com.mongodb WriteResult toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.toschu.repositoryapi.api.Implemented.MongoDBMorphia.java

/**
 * searchs existing Entity and replace them with the new own
 *
 * @param entity/* www .ja v a 2  s. c om*/
 * @param elements
 */
private void mergeEntity(T entity, Set<T> elements) {
    boolean merged = false;
    Datastore datastore = createDataStore(databaseName);
    for (T currentElement : elements) {
        if (currentElement.equals(entity)) {
            try {
                logger.info("merging");
                merged = true;
                WriteResult delete = datastore.delete(currentElement);
                logger.info(delete.toString());
                Key<T> save = datastore.save(entity);
                logger.info(save);
                logger.info("merged:\t" + merged);
            } catch (UpdateException ue) {
                if (!ue.getMessage().toLowerCase().equals("Nothing updated".toLowerCase())) {
                    throw ue;
                }
            }
        } else {
        }
    }
    if (!merged) {
        logger.info("new Entity");
        datastore.save(entity);
    }
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.tasklets.FilesByStudyDropperStep.java

License:Apache License

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    Query query = new Query(new Criteria(STUDYID_FIELD).is(inputParameters.getStudyId()));

    logger.info("Deleting files from study \"{}\"", inputParameters.getStudyId(),
            dbParameters.getCollectionFilesName());
    logger.trace("Query used: {}", query);
    WriteResult writeResult = mongoOperations.remove(query, dbParameters.getCollectionFilesName());
    logger.info("Result: {}", writeResult.toString());

    return RepeatStatus.FINISHED;
}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.tasklets.PullFilesAndStatisticsFromVariantGivenStudyIdStep.java

License:Apache License

private void dropVariantsAndStatisticsByStudy(String studyId) {
    String filesStudyIdField = String.format("%s.%s", FILES_FIELD, STUDYID_FIELD);
    Query query = Query.query(Criteria.where(filesStudyIdField).is(studyId));

    DBObject containsStudyId = new BasicDBObject(STUDYID_FIELD, studyId);
    Update update = new Update().pull(FILES_FIELD, containsStudyId).pull(STATS_FIELD, containsStudyId);

    logger.trace("Update operation with Query : {} and Update: {}", query, update);
    WriteResult writeResult = mongoOperations.updateMulti(query, update,
            dbParameters.getCollectionVariantsName());
    logger.info("Result: {}", writeResult.toString());

}

From source file:uk.ac.ebi.eva.pipeline.jobs.steps.tasklets.SingleStudyVariantsDropperStep.java

License:Apache License

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    String filesStudyIdField = String.format("%s.%s", FILES_FIELD, STUDYID_FIELD);
    Query query = new Query(
            new Criteria(filesStudyIdField).is(inputParameters.getStudyId()).and(FILES_FIELD).size(1));
    logger.info("Deleting variants reported only in study \"{}\"", inputParameters.getStudyId());
    logger.trace("Query used: {}", query);
    WriteResult writeResult = mongoOperations.remove(query, dbParameters.getCollectionVariantsName());
    logger.info("Result: {}", writeResult.toString());

    return RepeatStatus.FINISHED;
}

From source file:uk.ac.ncl.aries.entanglement.revlog.RevisionLogDirectToMongoDbImpl.java

License:Apache License

private void rollback(TransactionRollback op) throws RevisionLogException {
    String transactionUid = op.getUid();
    try {//from   w w w .jav a2  s .com
        logger.info("************* ROLLING BACK TRANSACTION: " + transactionUid);
        DBObject query = new BasicDBObject(FIELD_TXN_UID, transactionUid);
        WriteResult result = revLogCol.remove(query);
        logger.info(result.toString());
        logger.info("************* ROLLING COMPLETED: " + transactionUid);
    } catch (Exception e) {
        logger.info("************* ROLLING FAILED: " + transactionUid);
        throw new RevisionLogException("Failed to roll back transaction: " + transactionUid, e);
    }
}