Tabnine Logo
AbstractMongoRepository
Code IndexAdd Tabnine to your IDE (free)

How to use
AbstractMongoRepository
in
de.otto.edison.mongo

Best Java code snippets using de.otto.edison.mongo.AbstractMongoRepository (Showing top 20 results out of 315)

origin: de.otto.edison/edison-mongo

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);
}
origin: de.otto.edison/mongo

public void update(final V value) {
  final K key = keyOf(value);
  collection().replaceOne(byId(key), encode(value));
}
origin: de.otto.edison/mongo

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));
  }
}
origin: de.otto.edison/edison-mongo

public V create(final V value, final long maxTime, final TimeUnit timeUnit) {
  final K key = keyOf(value);
  if (key != null) {
    final Document doc = encode(value);
    collectionWithWriteTimeout(maxTime, timeUnit).insertOne(doc);
    return decode(doc);
  } else {
    throw new NullPointerException("Key must not be null");
  }
}
origin: de.otto.edison/mongo

public V create(final V value) {
  Document doc = encode(value);
  collection().insertOne(doc);
  return decode(doc);
}
origin: de.otto.edison/edison-mongo

                   final long maxTime,
                   final TimeUnit timeUnit) {
final K key = keyOf(value);
if (key != null) {
  final Bson query = and(eq(AbstractMongoRepository.ID, key), eq(ETAG, eTag));
  final Document updatedETaggable = collectionWithWriteTimeout(maxTime, timeUnit).findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER));
  if (isNull(updatedETaggable)) {
    final boolean documentExists = collection()
        .count(eq(AbstractMongoRepository.ID, key), new CountOptions().maxTime(maxTime, timeUnit)) != 0;
    if (documentExists) {
origin: de.otto.edison/mongo

public void delete(final K key) {
  collection().deleteOne(byId(key));
}
origin: de.otto.edison/edison-mongo

public void createOrUpdateBulk(final Collection<V> values, final long maxTime, final TimeUnit timeUnit) {
  if (values.isEmpty()) {
    return;
  }
  final List<ReplaceOneModel<Document>> bulkOperations = values.stream()
      .map(value -> new ReplaceOneModel<>(
          eq(ID, keyOf(value)),
          encode(value),
          BULK_UPSERT_OPERATION))
      .collect(toList());
  collectionWithWriteTimeout(maxTime, timeUnit)
      .bulkWrite(bulkOperations, BULK_WRITE_OPTIONS);
}
origin: de.otto.edison/mongo

public long size() {
  return collection().count();
}
origin: de.otto.edison/mongo

public void deleteAll() {
  collection().deleteMany(matchAll());
}
origin: otto-de/edison-microservice

/**
 * 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));
}
origin: otto-de/edison-microservice

/**
 * 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());
}
origin: otto-de/edison-microservice

public Stream<V> findAllAsStream(final long maxTime, final TimeUnit timeUnit) {
  return toStream(
      collection().find()
          .maxTime(maxTime, timeUnit))
      .map(this::decode);
}
origin: de.otto.edison/edison-mongo

/**
 * 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);
}
origin: de.otto.edison/edison-mongo

public V create(final V value) {
  return create(value, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS);
}
origin: otto-de/edison-microservice

public V createOrUpdate(final V value) {
  return createOrUpdate(value, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS);
}
origin: otto-de/edison-microservice

                   final long maxTime,
                   final TimeUnit timeUnit) {
final K key = keyOf(value);
if (key != null) {
  final Bson query = and(eq(AbstractMongoRepository.ID, key), eq(ETAG, eTag));
  final Document updatedETaggable = collectionWithWriteTimeout(maxTime, timeUnit).findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER));
  if (isNull(updatedETaggable)) {
    final boolean documentExists = collection()
        .countDocuments(eq(AbstractMongoRepository.ID, key), new CountOptions().maxTime(maxTime, timeUnit)) != 0;
    if (documentExists) {
origin: de.otto.edison/mongo

public Optional<V> findOne(final K key) {
  return ofNullable(collection()
      .find(byId(key))
      .map(this::decode)
      .first());
}
origin: otto-de/edison-microservice

public void createOrUpdateBulk(final Collection<V> values, final long maxTime, final TimeUnit timeUnit) {
  if (values.isEmpty()) {
    return;
  }
  final List<ReplaceOneModel<Document>> bulkOperations = values.stream()
      .map(value -> new ReplaceOneModel<>(
          eq(ID, keyOf(value)),
          encode(value),
          BULK_UPSERT_OPERATION))
      .collect(toList());
  collectionWithWriteTimeout(maxTime, timeUnit)
      .bulkWrite(bulkOperations, BULK_WRITE_OPTIONS);
}
origin: de.otto.edison/edison-mongo

protected MongoCollection<Document> collectionWithWriteTimeout(long maxTime, TimeUnit timeUnit) {
  return collection()
      .withWriteConcern(collection().getWriteConcern().withWTimeout(maxTime, timeUnit));
}
de.otto.edison.mongoAbstractMongoRepository

Most used methods

  • byId
    Returns a query that is selecting documents by ID.
  • collection
  • decode
    Decode a MongoDB Document into a value.
  • encode
    Encode a value into a MongoDB Document.
  • findOne
    Find a single value with the specified key, if existing.
  • keyOf
    Returns the key / identifier from the given value. The key of a document must never be null.
  • matchAll
    Returns a query that is selecting all documents.
  • collectionWithWriteTimeout
  • create
  • createOrUpdate
  • createOrUpdateBulk
  • delete
    Deletes the document identified by key.
  • createOrUpdateBulk,
  • delete,
  • deleteAll,
  • ensureIndexes,
  • findAll,
  • findAllAsStream,
  • getFindIterable,
  • size,
  • toStream,
  • update

Popular in Java

  • Reading from database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • getSystemService (Context)
  • compareTo (BigDecimal)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • JLabel (javax.swing)
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now