Search in sources :

Example 46 with Delete

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

the class CosmosMutationTest method makeConditionalQuery_MutationWithoutClusteringKeyGiven_ShouldReturnQuery.

@Test
public void makeConditionalQuery_MutationWithoutClusteringKeyGiven_ShouldReturnQuery() {
    // Arrange
    when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2)));
    Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
    Delete delete = new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    CosmosMutation cosmosMutation = new CosmosMutation(delete, metadata);
    String concatenatedPartitionKey = cosmosMutation.getConcatenatedPartitionKey();
    // Act
    String actual = cosmosMutation.makeConditionalQuery();
    // Assert
    assertThat(actual).isEqualTo("select * from Record r where r.concatenatedPartitionKey = '" + concatenatedPartitionKey + "'");
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 47 with Delete

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

the class JdbcServiceTest method whenDeleteOperationWithDeleteIfExistsConditionExecuted_shouldReturnTrueAndCallQueryBuilder.

@Test
public void whenDeleteOperationWithDeleteIfExistsConditionExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
    // Arrange
    when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
    when(connection.prepareStatement(any())).thenReturn(preparedStatement);
    when(preparedStatement.executeUpdate()).thenReturn(1);
    // Act
    Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()).forNamespace(NAMESPACE).forTable(TABLE);
    boolean ret = jdbcService.delete(delete, connection);
    // Assert
    assertThat(ret).isTrue();
    verify(operationChecker).check(any(Delete.class));
    verify(queryBuilder).deleteFrom(any(), any(), any());
}
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 48 with Delete

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

the class JdbcServiceTest method whenDeleteOperationWithDeleteIfConditionExecuted_shouldReturnTrueAndCallQueryBuilder.

@Test
public void whenDeleteOperationWithDeleteIfConditionExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
    // Arrange
    when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.where(any(), any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
    when(connection.prepareStatement(any())).thenReturn(preparedStatement);
    when(preparedStatement.executeUpdate()).thenReturn(1);
    // Act
    Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIf(new ConditionalExpression("v1", new TextValue("val2"), ConditionalExpression.Operator.EQ))).forNamespace(NAMESPACE).forTable(TABLE);
    boolean ret = jdbcService.delete(delete, connection);
    // Assert
    assertThat(ret).isTrue();
    verify(operationChecker).check(any(Delete.class));
    verify(queryBuilder).deleteFrom(any(), any(), any());
}
Also used : Delete(com.scalar.db.api.Delete) TextValue(com.scalar.db.io.TextValue) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Key(com.scalar.db.io.Key) DeleteIf(com.scalar.db.api.DeleteIf) Test(org.junit.jupiter.api.Test)

Example 49 with Delete

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

the class JdbcServiceTest method whenDeleteOperationExecuted_shouldReturnTrueAndCallQueryBuilder.

@Test
public void whenDeleteOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
    // Arrange
    when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
    when(connection.prepareStatement(any())).thenReturn(preparedStatement);
    // Act
    Delete delete = new Delete(new Key("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE);
    boolean ret = jdbcService.delete(delete, connection);
    // Assert
    assertThat(ret).isTrue();
    verify(operationChecker).check(any(Delete.class));
    verify(queryBuilder).deleteFrom(any(), any(), any());
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 50 with Delete

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

the class JdbcServiceTest method whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder.

@Test
public void whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throws Exception {
    // Arrange
    when(connection.prepareStatement(any())).thenReturn(preparedStatement);
    when(queryBuilder.upsertInto(any(), any(), any())).thenReturn(upsertQueryBuilder);
    when(upsertQueryBuilder.values(any(), any(), any())).thenReturn(upsertQueryBuilder);
    when(upsertQueryBuilder.build()).thenReturn(upsertQuery);
    when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.where(any(), any())).thenReturn(deleteQueryBuilder);
    when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
    // 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);
    boolean ret = jdbcService.mutate(Arrays.asList(put, delete), connection);
    // Assert
    assertThat(ret).isTrue();
    verify(operationChecker).check(anyList());
    verify(operationChecker).check(any(Put.class));
    verify(operationChecker).check(any(Delete.class));
    verify(queryBuilder).upsertInto(any(), any(), any());
    verify(queryBuilder).deleteFrom(any(), any(), any());
}
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)

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