package org.mongodb.morphia.query;


import com.mongodb.WriteResult;

import static java.lang.String.format;

This class holds various metrics about the results of an update operation.
/** * This class holds various metrics about the results of an update operation. */
public class UpdateResults { private final WriteResult wr;
Creates an UpdateResults
Params:
  • wr – the WriteResult from the driver.
/** * Creates an UpdateResults * * @param wr the WriteResult from the driver. */
public UpdateResults(final WriteResult wr) { this.wr = wr; }
Returns:number inserted; this should be either 0/1.
/** * @return number inserted; this should be either 0/1. */
public int getInsertedCount() { return !getUpdatedExisting() ? getN() : 0; }
Returns:the new _id field if an insert/upsert was performed
/** * @return the new _id field if an insert/upsert was performed */
public Object getNewId() { return wr.getUpsertedId(); }
Returns:number updated
/** * @return number updated */
public int getUpdatedCount() { return getUpdatedExisting() ? getN() : 0; }
Returns:true if updated, false if inserted or none effected
/** * @return true if updated, false if inserted or none effected */
public boolean getUpdatedExisting() { return wr.isUpdateOfExisting(); }
Returns:the underlying data
/** * @return the underlying data */
public WriteResult getWriteResult() { return wr; }
Returns:number of affected documents
/** * @return number of affected documents */
protected int getN() { return wr.getN(); } @Override public String toString() { return format("UpdateResults{wr=%s}", wr); } }