Search in sources :

Example 96 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class MultiStorage method mutate.

@Override
public void mutate(List<? extends Mutation> mutations) throws ExecutionException {
    checkArgument(mutations.size() != 0);
    if (mutations.size() == 1) {
        Mutation mutation = mutations.get(0);
        if (mutation instanceof Put) {
            put((Put) mutation);
        } else if (mutation instanceof Delete) {
            delete((Delete) mutation);
        }
        return;
    }
    mutations = copyAndSetTargetToIfNot(mutations);
    getStorage(mutations.get(0)).mutate(mutations);
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Put(com.scalar.db.api.Put)

Example 97 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class JdbcDatabaseTest method whenDeleteOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException.

@Test
public void whenDeleteOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException() throws Exception {
    // Arrange
    when(jdbcService.delete(any(), any())).thenReturn(false);
    // Act Assert
    assertThatThrownBy(() -> {
        Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()).forNamespace(NAMESPACE).forTable(TABLE);
        jdbcDatabase.delete(delete);
    }).isInstanceOf(NoMutationException.class);
    verify(connection).close();
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) DeleteIfExists(com.scalar.db.api.DeleteIfExists) Test(org.junit.jupiter.api.Test)

Example 98 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class JdbcDatabaseTest method whenMutateOperationExecuted_shouldCallJdbcService.

@Test
public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception {
    // Arrange
    when(jdbcService.mutate(any(), any())).thenReturn(true);
    // Act
    Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
    Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
    jdbcDatabase.mutate(Arrays.asList(put, delete));
    // Assert
    verify(jdbcService).mutate(any(), any());
    verify(connection).close();
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 99 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class JdbcDatabaseTest method whenMutateOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException.

@Test
public void whenMutateOperationExecutedAndJdbcServiceThrowsSQLException_shouldThrowExecutionException() throws Exception {
    // Arrange
    when(jdbcService.mutate(any(), any())).thenThrow(sqlException);
    // Act Assert
    assertThatThrownBy(() -> {
        Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").forNamespace(NAMESPACE).forTable(TABLE);
        Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
        jdbcDatabase.mutate(Arrays.asList(put, delete));
    }).isInstanceOf(ExecutionException.class);
    verify(connection).close();
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 100 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class JdbcDatabaseTest method whenMutateOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException.

@Test
public void whenMutateOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException() throws Exception {
    // Arrange
    when(jdbcService.mutate(any(), any())).thenReturn(false);
    // Act Assert
    assertThatThrownBy(() -> {
        Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfNotExists()).forNamespace(NAMESPACE).forTable(TABLE);
        Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()).forNamespace(NAMESPACE).forTable(TABLE);
        jdbcDatabase.mutate(Arrays.asList(put, delete));
    }).isInstanceOf(NoMutationException.class);
    verify(connection).close();
}
Also used : PutIfNotExists(com.scalar.db.api.PutIfNotExists) Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) DeleteIfExists(com.scalar.db.api.DeleteIfExists) Test(org.junit.jupiter.api.Test)

Aggregations

Delete (com.scalar.db.api.Delete)174 Key (com.scalar.db.io.Key)112 Test (org.junit.jupiter.api.Test)111 Put (com.scalar.db.api.Put)59 Get (com.scalar.db.api.Get)29 Result (com.scalar.db.api.Result)29 Test (org.junit.Test)25 DeleteIfExists (com.scalar.db.api.DeleteIfExists)24 ConditionalExpression (com.scalar.db.api.ConditionalExpression)16 DeleteIf (com.scalar.db.api.DeleteIf)15 Mutation (com.scalar.db.api.Mutation)14 MutationCondition (com.scalar.db.api.MutationCondition)11 Scan (com.scalar.db.api.Scan)11 PutIfNotExists (com.scalar.db.api.PutIfNotExists)10 TextValue (com.scalar.db.io.TextValue)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)8 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)6 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)6 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)6 PartitionKey (com.azure.cosmos.models.PartitionKey)5