Class CosmosDbUtil

java.lang.Object
net.officefloor.nosql.cosmosdb.CosmosDbUtil

public class CosmosDbUtil extends Object
Utility function for Cosmos DB.
Author:
Daniel Sagenschneider
  • Method Details

    • createDatabases

      public static void createDatabases(com.azure.cosmos.CosmosClient client, List<com.azure.cosmos.models.CosmosDatabaseProperties> databases, int waitTimeInSeconds, Logger logger, Level logLevel) throws Exception
      Creates the CosmosDatabase instances ensuring they are available.
      Parameters:
      client - CosmosClient.
      databases - CosmosDatabaseProperties instances of the CosmosDatabase instances to crate.
      waitTimeInSeconds - Time to wait in seconds for CosmosDatabase creation.
      logger - Logger to log progress.
      logLevel - Level for logging.
      Throws:
      Exception - If fails to create the CosmosDatabase instances.
    • createAsyncDatabases

      public static void createAsyncDatabases(com.azure.cosmos.CosmosAsyncClient client, List<com.azure.cosmos.models.CosmosDatabaseProperties> databases, int waitTimeInSeconds, Logger logger, Level logLevel) throws Exception
      Creates the CosmosAsyncDatabase instances ensuring they are available.
      Parameters:
      client - CosmosAsyncClient.
      databases - CosmosDatabaseProperties instances of the CosmosAsyncDatabase instances to crate.
      waitTimeInSeconds - Time to wait in seconds for CosmosAsyncDatabase creation.
      logger - Logger to log progress.
      logLevel - Level for logging.
      Throws:
      Exception - If fails to create the CosmosAsyncDatabase instances.
    • createContainers

      public static void createContainers(com.azure.cosmos.CosmosDatabase database, List<com.azure.cosmos.models.CosmosContainerProperties> containers, int waitTimeInSeconds, Logger logger, Level logLevel) throws Exception
      Creates the CosmosContainer instances ensuring they are available.
      Parameters:
      database - CosmosDatabase.
      containers - CosmosContainerProperties instances of the CosmosContainer instances to create.
      waitTimeInSeconds - Time to wait in seconds for CosmosContainer creation.
      logger - Logger to log progress.
      logLevel - Level for logging.
      Throws:
      Exception - If fails to create the CosmosContainer instances.
    • createAsyncContainers

      public static void createAsyncContainers(com.azure.cosmos.CosmosAsyncDatabase database, List<com.azure.cosmos.models.CosmosContainerProperties> containers, int waitTimeInSeconds, Logger logger, Level logLevel) throws Exception
      Creates the CosmosAsyncContainer instances ensuring they are available.
      Parameters:
      database - CosmosAsyncDatabase.
      containers - CosmosContainerProperties instances of the CosmosAsyncContainer instances to create.
      waitTimeInSeconds - Time to wait in seconds for CosmosAsyncContainer creation.
      logger - Logger to log progress.
      logLevel - Level for logging.
      Throws:
      Exception - If fails to create the CosmosAsyncContainer instances.
    • ignoreNotFound

      public static <R, E extends Throwable> R ignoreNotFound(CosmosDbUtil.CosmosOperation<R,E> operation) throws E
      Ignores NotFoundException (when deleting).
      Type Parameters:
      R - Result.
      E - Possible Exception thrown.
      Parameters:
      operation - CosmosDbUtil.CosmosOperation.
      Returns:
      Result of CosmosException.
      Throws:
      E - Failure of CosmosDbUtil.CosmosOperation.
    • ignoreConflict

      public static <R, E extends Throwable> R ignoreConflict(CosmosDbUtil.CosmosOperation<R,E> operation) throws E

      Ignores conflict.

      Typically on create to ignore if already container by name.

      Type Parameters:
      R - Result.
      E - Possible Exception thrown.
      Parameters:
      operation - CosmosDbUtil.CosmosOperation.
      Returns:
      Result of CosmosDbUtil.CosmosOperation.
      Throws:
      E - Failure of CosmosDbUtil.CosmosOperation.
    • retry

      public static <R, E extends Throwable> R retry(CosmosDbUtil.CosmosOperation<R,E> operation) throws E
      Undertakes the CosmosDbUtil.CosmosOperation with appropriate retrying.
      Type Parameters:
      R - Result.
      E - Possible Exception thrown.
      Parameters:
      operation - CosmosDbUtil.CosmosOperation.
      Returns:
      Result of CosmosDbUtil.CosmosOperation.
      Throws:
      E - Failure of CosmosDbUtil.CosmosOperation.
    • retry

      public static <R, E extends Throwable> R retry(boolean isRead, CosmosDbUtil.CosmosOperation<R,E> operation) throws E
      Undertakes the CosmosDbUtil.CosmosOperation with appropriate retrying.
      Type Parameters:
      R - Result.
      E - Possible Exception thrown.
      Parameters:
      isRead - Indicates if reading.
      operation - CosmosDbUtil.CosmosOperation.
      Returns:
      Result of CosmosDbUtil.CosmosOperation.
      Throws:
      E - Failure of CosmosDbUtil.CosmosOperation.
    • retry

      public static reactor.util.retry.Retry retry()
      Undertakes retry for asynchronous.
      Returns:
      Retry.
    • retry

      public static reactor.util.retry.Retry retry(boolean isRead)
      Undertakes retry for asynchronous.
      Parameters:
      isRead - Indicates if reading.
      Returns:
      Retry.