/** * Deletes the document identified by key. * * @param key the identifier of the deleted document * @param maxTime max time for the operation * @param timeUnit the time unit for the maxTime value */ public void delete(final K key, final long maxTime, final TimeUnit timeUnit) { collectionWithWriteTimeout(maxTime, timeUnit).deleteOne(byId(key)); }
/** * Deletes the document identified by key. * * @param key the identifier of the deleted document * @param maxTime max time for the operation * @param timeUnit the time unit for the maxTime value */ public void delete(final K key, final long maxTime, final TimeUnit timeUnit) { collectionWithWriteTimeout(maxTime, timeUnit).deleteOne(byId(key)); }
public void delete(final K key) { collection().deleteOne(byId(key)); }
public Optional<V> findOne(final K key) { return ofNullable(collection() .find(byId(key)) .map(this::decode) .first()); }
/** * Find a single value with the specified key, if existing. * * @param key the key to search for * @param maxTime the maximum time for this request * @param timeUnit the time unit in which {@code maxTime} is specified * @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, final long maxTime, final TimeUnit timeUnit) { return ofNullable(collection() .find(byId(key)) .maxTime(maxTime, timeUnit) .map(this::decode) .first()); }
public void update(final V value) { final K key = keyOf(value); collection().replaceOne(byId(key), encode(value)); }
/** * Find a single value with the specified key, if existing. * * @param key the key to search for * @param maxTime the maximum time for this request * @param timeUnit the time unit in which {@code maxTime} is specified * @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, final long maxTime, final TimeUnit timeUnit) { return ofNullable(collection() .find(byId(key)) .maxTime(maxTime, timeUnit) .map(this::decode) .first()); }
/** * Updates the document if it is already present in the repository. * * @param value the new value * @param maxTime max time for the update * @param timeUnit the time unit for the maxTime value * @return true, if the document was updated, false otherwise. */ public boolean update(final V value, final long maxTime, final TimeUnit timeUnit) { final K key = keyOf(value); if (key != null) { return collectionWithWriteTimeout(maxTime, timeUnit) .replaceOne(byId(key), encode(value)) .getModifiedCount() == 1; } else { throw new IllegalArgumentException("Key must not be null"); } }
/** * Updates the document if it is already present in the repository. * * @param value the new value * @param maxTime max time for the update * @param timeUnit the time unit for the maxTime value * @return true, if the document was updated, false otherwise. */ public boolean update(final V value, final long maxTime, final TimeUnit timeUnit) { final K key = keyOf(value); if (key != null) { return collectionWithWriteTimeout(maxTime, timeUnit) .replaceOne(byId(key), encode(value)) .getModifiedCount() == 1; } else { throw new IllegalArgumentException("Key must not be null"); } }
public V createOrUpdate(final V value, final long maxTime, final TimeUnit timeUnit) { final Document doc = encode(value); collectionWithWriteTimeout(maxTime, timeUnit) .replaceOne(byId(keyOf(value)), doc, new UpdateOptions().upsert(true)); return decode(doc); }
public V createOrUpdate(final V value, final long maxTime, final TimeUnit timeUnit) { final Document doc = encode(value); collectionWithWriteTimeout(maxTime, timeUnit) .replaceOne(byId(keyOf(value)), doc, new ReplaceOptions().upsert(true)); return decode(doc); }