Package net.officefloor.nosql.cosmosdb
Class CosmosDbUtil
java.lang.Object
net.officefloor.nosql.cosmosdb.CosmosDbUtil
Utility function for Cosmos DB.
- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCosmosDbUtil.CosmosOperation<R,E extends Throwable> Operation that can be retried. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateAsyncContainers(com.azure.cosmos.CosmosAsyncDatabase database, List<com.azure.cosmos.models.CosmosContainerProperties> containers, int waitTimeInSeconds, Logger logger, Level logLevel) Creates theCosmosAsyncContainerinstances ensuring they are available.static voidcreateAsyncDatabases(com.azure.cosmos.CosmosAsyncClient client, List<com.azure.cosmos.models.CosmosDatabaseProperties> databases, int waitTimeInSeconds, Logger logger, Level logLevel) Creates theCosmosAsyncDatabaseinstances ensuring they are available.static voidcreateContainers(com.azure.cosmos.CosmosDatabase database, List<com.azure.cosmos.models.CosmosContainerProperties> containers, int waitTimeInSeconds, Logger logger, Level logLevel) Creates theCosmosContainerinstances ensuring they are available.static voidcreateDatabases(com.azure.cosmos.CosmosClient client, List<com.azure.cosmos.models.CosmosDatabaseProperties> databases, int waitTimeInSeconds, Logger logger, Level logLevel) Creates theCosmosDatabaseinstances ensuring they are available.static <R,E extends Throwable>
RignoreConflict(CosmosDbUtil.CosmosOperation<R, E> operation) Ignores conflict.static <R,E extends Throwable>
RignoreNotFound(CosmosDbUtil.CosmosOperation<R, E> operation) IgnoresNotFoundException(when deleting).static reactor.util.retry.Retryretry()Undertakes retry for asynchronous.static reactor.util.retry.Retryretry(boolean isRead) Undertakes retry for asynchronous.static <R,E extends Throwable>
Rretry(boolean isRead, CosmosDbUtil.CosmosOperation<R, E> operation) Undertakes theCosmosDbUtil.CosmosOperationwith appropriate retrying.static <R,E extends Throwable>
Rretry(CosmosDbUtil.CosmosOperation<R, E> operation) Undertakes theCosmosDbUtil.CosmosOperationwith appropriate retrying.
-
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 theCosmosDatabaseinstances ensuring they are available.- Parameters:
client-CosmosClient.databases-CosmosDatabasePropertiesinstances of theCosmosDatabaseinstances to crate.waitTimeInSeconds- Time to wait in seconds forCosmosDatabasecreation.logger-Loggerto log progress.logLevel-Levelfor logging.- Throws:
Exception- If fails to create theCosmosDatabaseinstances.
-
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 theCosmosAsyncDatabaseinstances ensuring they are available.- Parameters:
client-CosmosAsyncClient.databases-CosmosDatabasePropertiesinstances of theCosmosAsyncDatabaseinstances to crate.waitTimeInSeconds- Time to wait in seconds forCosmosAsyncDatabasecreation.logger-Loggerto log progress.logLevel-Levelfor logging.- Throws:
Exception- If fails to create theCosmosAsyncDatabaseinstances.
-
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 theCosmosContainerinstances ensuring they are available.- Parameters:
database-CosmosDatabase.containers-CosmosContainerPropertiesinstances of theCosmosContainerinstances to create.waitTimeInSeconds- Time to wait in seconds forCosmosContainercreation.logger-Loggerto log progress.logLevel-Levelfor logging.- Throws:
Exception- If fails to create theCosmosContainerinstances.
-
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 theCosmosAsyncContainerinstances ensuring they are available.- Parameters:
database-CosmosAsyncDatabase.containers-CosmosContainerPropertiesinstances of theCosmosAsyncContainerinstances to create.waitTimeInSeconds- Time to wait in seconds forCosmosAsyncContainercreation.logger-Loggerto log progress.logLevel-Levelfor logging.- Throws:
Exception- If fails to create theCosmosAsyncContainerinstances.
-
ignoreNotFound
public static <R,E extends Throwable> R ignoreNotFound(CosmosDbUtil.CosmosOperation<R, E> operation) throws EIgnoresNotFoundException(when deleting).- Type Parameters:
R- Result.E- PossibleExceptionthrown.- Parameters:
operation-CosmosDbUtil.CosmosOperation.- Returns:
- Result of
CosmosException. - Throws:
E- Failure ofCosmosDbUtil.CosmosOperation.
-
ignoreConflict
public static <R,E extends Throwable> R ignoreConflict(CosmosDbUtil.CosmosOperation<R, E> operation) throws EIgnores conflict.
Typically on create to ignore if already container by name.
- Type Parameters:
R- Result.E- PossibleExceptionthrown.- Parameters:
operation-CosmosDbUtil.CosmosOperation.- Returns:
- Result of
CosmosDbUtil.CosmosOperation. - Throws:
E- Failure ofCosmosDbUtil.CosmosOperation.
-
retry
public static <R,E extends Throwable> R retry(CosmosDbUtil.CosmosOperation<R, E> operation) throws EUndertakes theCosmosDbUtil.CosmosOperationwith appropriate retrying.- Type Parameters:
R- Result.E- PossibleExceptionthrown.- Parameters:
operation-CosmosDbUtil.CosmosOperation.- Returns:
- Result of
CosmosDbUtil.CosmosOperation. - Throws:
E- Failure ofCosmosDbUtil.CosmosOperation.
-
retry
public static <R,E extends Throwable> R retry(boolean isRead, CosmosDbUtil.CosmosOperation<R, E> operation) throws EUndertakes theCosmosDbUtil.CosmosOperationwith appropriate retrying.- Type Parameters:
R- Result.E- PossibleExceptionthrown.- Parameters:
isRead- Indicates if reading.operation-CosmosDbUtil.CosmosOperation.- Returns:
- Result of
CosmosDbUtil.CosmosOperation. - Throws:
E- Failure ofCosmosDbUtil.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.
-