com.scalar.db.storage.cosmos.MutateStatementHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardb Show documentation
Show all versions of scalardb Show documentation
A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases
The newest version!
package com.scalar.db.storage.cosmos;
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosException;
import com.scalar.db.api.Mutation;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.common.TableMetadataManager;
import com.scalar.db.common.error.CoreError;
import com.scalar.db.exception.storage.ExecutionException;
import com.scalar.db.exception.storage.NoMutationException;
import com.scalar.db.exception.storage.RetriableExecutionException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.concurrent.ThreadSafe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** An abstraction for handler classes for mutate statements */
@ThreadSafe
public abstract class MutateStatementHandler extends StatementHandler {
private static final Logger logger = LoggerFactory.getLogger(MutateStatementHandler.class);
private static final String MUTATION_STORED_PROCEDURE = "mutate.js";
public MutateStatementHandler(CosmosClient client, TableMetadataManager metadataManager) {
super(client, metadataManager);
}
/**
* Executes the specified {@code Mutation}
*
* @param mutation a {@code Mutation} to execute
* @throws ExecutionException if the execution fails
*/
public void handle(Mutation mutation) throws ExecutionException {
try {
execute(mutation);
} catch (CosmosException e) {
throwException(e);
} catch (RuntimeException e) {
throw new ExecutionException(
CoreError.COSMOS_ERROR_OCCURRED_IN_MUTATION.buildMessage(e.getMessage()), e);
}
}
abstract void execute(Mutation mutation) throws CosmosException, ExecutionException;
protected void executeStoredProcedure(Mutation mutation, TableMetadata tableMetadata)
throws CosmosException {
CosmosMutation cosmosMutation = new CosmosMutation(mutation, tableMetadata);
List