All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.ext.mongo.impl.config.ReadConcernLevelParser Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
package io.vertx.ext.mongo.impl.config;

import com.mongodb.ConnectionString;
import com.mongodb.ReadConcern;
import com.mongodb.ReadConcernLevel;
import io.vertx.core.json.JsonObject;

import java.util.Optional;

class ReadConcernLevelParser {

  private final ConnectionString connectionString;
  private final JsonObject config;

  ReadConcernLevelParser(ConnectionString connectionString, JsonObject config) {
    this.connectionString = connectionString;
    this.config = config;
  }

  Optional readConcern() {
    return tryToParseFromConnectionString().map(this::lift).orElseGet(this::tryToParseFromConfig);
  }

  private Optional lift(ReadConcern readConcern) {
    return Optional.ofNullable(readConcern);
  }

  private Optional tryToParseFromConnectionString() {
    return Optional.ofNullable(connectionString)
      .flatMap(cs -> Optional.ofNullable(cs.getReadConcern()));
  }

  private Optional tryToParseFromConfig() {
    return Optional.ofNullable(config)
      .flatMap(cfg -> Optional.ofNullable(cfg.getString("readConcernLevel")))
      .map(ReadConcernLevel::fromString)
      .map(ReadConcern::new);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy