/** * Find a single value with the specified key, if existing. * * @param key the key to search for * @return an Optional containing the requested value, or {@code Optional.empty()} if no value with this key exists */ public Optional<V> findOne(final K key) { return findOne(key, mongoProperties.getDefaultReadTimeout(), TimeUnit.MILLISECONDS); }
/** * Find a single value with the specified key, if existing. * * @param key the key to search for * @return an Optional containing the requested value, or {@code Optional.empty()} if no value with this key exists */ public Optional<V> findOne(final K key) { return findOne(key, mongoProperties.getDefaultReadTimeout(), TimeUnit.MILLISECONDS); }
public void updateIfMatch(final V value, final String eTag) { Bson query = and(eq(AbstractMongoRepository.ID, keyOf(value)), eq(ETAG, eTag)); Document updatedETaggable = collection().findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER)); if (isNull(updatedETaggable)) { Optional<V> findById = findOne(keyOf(value)); if (findById.isPresent()) { throw new ConcurrentModificationException("Entity concurrently modified: " + keyOf(value)); } throw new NotFoundException("Entity does not exist: " + keyOf(value)); } }