/** * Returns the bypassDocumentValidation * * @return the bypassDocumentValidation */ public Boolean getBypassDocumentValidation() { return options.getBypassDocumentValidation(); }
/** * Returns the collation options * * @return the collation options * @mongodb.server.release 3.4 */ public Collation getCollation() { return options.getCollation(); }
/** * Gets the maximum execution time on the server for this operation. The default is 0, which places no limit on the execution time. * * @param timeUnit the time unit to return the result in * @return the maximum execution time in the given time unit * @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time */ public long getMaxTime(final TimeUnit timeUnit) { notNull("timeUnit", timeUnit); return options.getMaxTime(timeUnit); }
final long maxTime, final TimeUnit maxTimeUnit, final WriteConcern writeConcern) { return findAndModify(query != null ? query : new BasicDBObject(), new DBCollectionFindAndModifyOptions() .projection(fields) .sort(sort) .remove(remove) .update(update) .returnNew(returnNew) .upsert(upsert) .bypassDocumentValidation(bypassDocumentValidation) .maxTime(maxTime, maxTimeUnit) .writeConcern(writeConcern));
@Test public void passThrough() { Collation collation = Collation.builder() .locale("en") .caseLevel(true) .build(); DBCollectionFindAndModifyOptions options = new FindAndModifyOptions() .bypassDocumentValidation(true) .collation(collation).getOptions() .maxTime(15, TimeUnit.MINUTES) .projection(new BasicDBObject("field", "value")) .remove(true) .returnNew(true) .sort(new BasicDBObject("field", -1)) .update(new BasicDBObject("$inc", "somefield")) .upsert(true) .writeConcern(WriteConcern.JOURNALED); assertTrue(options.getBypassDocumentValidation()); assertEquals(collation, options.getCollation()); assertEquals(15, options.getMaxTime(TimeUnit.MINUTES)); assertEquals(new BasicDBObject("field", "value"), options.getProjection()); assertTrue(options.isRemove()); assertTrue(options.returnNew()); assertEquals(new BasicDBObject("field", -1), options.getSort()); assertEquals(new BasicDBObject("$inc", "somefield"), options.getUpdate()); assertTrue(options.isUpsert()); assertEquals(WriteConcern.JOURNALED, options.getWriteConcern()); } }
notNull("query", query); notNull("options", options); WriteConcern optionsWriteConcern = options.getWriteConcern(); WriteConcern writeConcern = optionsWriteConcern != null ? optionsWriteConcern : getWriteConcern(); WriteOperation<DBObject> operation; if (options.isRemove()) { operation = new FindAndDeleteOperation<DBObject>(getNamespace(), writeConcern, retryWrites, objectCodec) .filter(wrapAllowNull(query)) .projection(wrapAllowNull(options.getProjection())) .sort(wrapAllowNull(options.getSort())) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .collation(options.getCollation()); } else { DBObject update = options.getUpdate(); if (update == null) { throw new IllegalArgumentException("update can not be null unless it's a remove"); wrap(update)) .filter(wrap(query)) .projection(wrapAllowNull(options.getProjection())) .sort(wrapAllowNull(options.getSort())) .returnOriginal(!options.returnNew()) .upsert(options.isUpsert()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .bypassDocumentValidation(options.getBypassDocumentValidation()) .collation(options.getCollation()) .arrayFilters(wrapAllowNull(options.getArrayFilters(), (Encoder<DBObject>) null)); } else { operation = new FindAndReplaceOperation<DBObject>(getNamespace(), writeConcern, retryWrites, objectCodec,
/** * Returns the update * * @return the update */ DBObject getUpdate() { return options.getUpdate(); }
/** * Returns the upsert * * @return the upsert */ public boolean isUpsert() { return options.isUpsert(); }
/** * Returns the remove * * @return the remove */ public boolean isRemove() { return options.isRemove(); }
/** * Sets the maximum execution time on the server for this operation. * * @param maxTime the max time * @param timeUnit the time unit, which may not be null * @return this * @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time */ public FindAndModifyOptions maxTime(final long maxTime, final TimeUnit timeUnit) { options.maxTime(maxTime, timeUnit); return this; }
/** * Returns the sort * * @return the sort */ DBObject getSort() { return options.getSort(); }
/** * Returns the writeConcern * * @return the writeConcern * @mongodb.server.release 3.2 */ public WriteConcern getWriteConcern() { return options.getWriteConcern(); }
DBObject getProjection() { return options.getProjection(); }
final long maxTime, final TimeUnit maxTimeUnit, final WriteConcern writeConcern) { return findAndModify(query != null ? query : new BasicDBObject(), new DBCollectionFindAndModifyOptions() .projection(fields) .sort(sort) .remove(remove) .update(update) .returnNew(returnNew) .upsert(upsert) .maxTime(maxTime, maxTimeUnit) .writeConcern(writeConcern));
notNull("query", query); notNull("options", options); WriteConcern optionsWriteConcern = options.getWriteConcern(); WriteConcern writeConcern = optionsWriteConcern != null ? optionsWriteConcern : getWriteConcern(); WriteOperation<DBObject> operation; if (options.isRemove()) { operation = new FindAndDeleteOperation<DBObject>(getNamespace(), writeConcern, retryWrites, objectCodec) .filter(wrapAllowNull(query)) .projection(wrapAllowNull(options.getProjection())) .sort(wrapAllowNull(options.getSort())) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .collation(options.getCollation()); } else { DBObject update = options.getUpdate(); if (update == null) { throw new IllegalArgumentException("update can not be null unless it's a remove"); wrap(update)) .filter(wrap(query)) .projection(wrapAllowNull(options.getProjection())) .sort(wrapAllowNull(options.getSort())) .returnOriginal(!options.returnNew()) .upsert(options.isUpsert()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .bypassDocumentValidation(options.getBypassDocumentValidation()) .collation(options.getCollation()) .arrayFilters(wrapAllowNull(options.getArrayFilters(), (Encoder<DBObject>) null)); } else { operation = new FindAndReplaceOperation<DBObject>(getNamespace(), writeConcern, retryWrites, objectCodec,
/** * Returns the update * * @return the update */ DBObject getUpdate() { return options.getUpdate(); }
/** * Returns the upsert * * @return the upsert */ public boolean isUpsert() { return options.isUpsert(); }
/** * Returns the remove * * @return the remove */ public boolean isRemove() { return options.isRemove(); }
/** * Sets the maximum execution time on the server for this operation. * * @param maxTime the max time * @param timeUnit the time unit, which may not be null * @return this * @mongodb.driver.manual reference/method/cursor.maxTimeMS/#cursor.maxTimeMS Max Time */ public FindAndModifyOptions maxTime(final long maxTime, final TimeUnit timeUnit) { options.maxTime(maxTime, timeUnit); return this; }
/** * Returns the sort * * @return the sort */ DBObject getSort() { return options.getSort(); }