- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {Gson g =
new Gson()
GsonBuilder gsonBuilder;gsonBuilder.create()
new GsonBuilder().create()
- Smart code suggestions by Codota
}
/** * Deletes the document identified by key. * * @param key the identifier of the deleted document */ public void delete(final K key) { delete(key, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
/** * Deletes all documents from this repository. */ public void deleteAll() { deleteAll(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
/** * Updates the document if it is already present in the repository. * * @param value the new value * @return true, if the document was updated, false otherwise. */ public boolean update(final V value) { return update(value, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
public void update(final V value) { final K key = keyOf(value); collection().replaceOne(byId(key), encode(value)); }
public V create(final V value) { Document doc = encode(value); collection().insertOne(doc); return decode(doc); }
/** * 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); }
/** * 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 all documents from this repository. * * @param maxTime max time for the operation * @param timeUnit the time unit for the maxTime value */ public void deleteAll(final long maxTime, final TimeUnit timeUnit) { collectionWithWriteTimeout(maxTime, timeUnit).deleteMany(matchAll()); }
@Test public void shouldNotUpdateIfEtagNotMatch() { // given final TestObject testObject = new TestObject("someId", "someValue", "someEtagWhichIsNotInTheDb"); testee.create(testObject); // when final UpdateIfMatchResult updated = testee.updateIfMatch(testObject, "someOtherETag"); // then assertThat(updated, is(UpdateIfMatchResult.CONCURRENTLY_MODIFIED)); }
@PostConstruct public void postConstruct() { ensureIndexes(); }
@Test public void shouldNotUpdateIfEtagNotExists() { // given final TestObject testObject = new TestObject("someId", "someValue"); // when final UpdateIfMatchResult updated = testee.updateIfMatch(testObject, "someETag"); // then assertThat(updated, is(UpdateIfMatchResult.NOT_FOUND)); }
@Test public void shouldNotCreateOrUpdateWithMissingId() { // given final TestObject testObject = new TestObject(null, "someValue"); // when / then assertThrows(NullPointerException.class, () -> { final TestObject resultingObject = testee.createOrUpdate(testObject); }); }
@Test public void shouldNotCreateWithMissingId() { // given final TestObject testObject = new TestObject(null, "someValue"); // when / then assertThrows(NullPointerException.class, () -> { testee.create(testObject); }); }
public boolean matches(final Object object) { return ((object instanceof TestObject) && ((TestObject) object).equalsWithoutEtag(testObject)); } }
/** * Deletes the document identified by key. * * @param key the identifier of the deleted document */ public void delete(final K key) { delete(key, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
/** * 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 all documents from this repository. */ public void deleteAll() { deleteAll(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
/** * Updates the document if it is already present in the repository. * * @param value the new value * @return true, if the document was updated, false otherwise. */ public boolean update(final V value) { return update(value, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
/** * Deletes all documents from this repository. * @param maxTime max time for the operation * @param timeUnit the time unit for the maxTime value */ public void deleteAll(final long maxTime, final TimeUnit timeUnit) { collectionWithWriteTimeout(maxTime, timeUnit).deleteMany(matchAll()); }
@PostConstruct public void postConstruct() { ensureIndexes(); }