use of com.scalar.db.api.DeleteIf in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method bind_DeleteOperationWithIfGiven_ShouldBindProperly.
@Test
public void bind_DeleteOperationWithIfGiven_ShouldBindProperly() {
// Arrange
configureBehavior(null);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIf(new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ)));
// Act
handler.bind(prepared, del);
// Assert
verify(bound).setString(0, ANY_TEXT_1);
verify(bound).setString(1, ANY_TEXT_2);
verify(bound).setInt(2, ANY_INT_1);
verify(bound).setString(3, ANY_TEXT_3);
}
use of com.scalar.db.api.DeleteIf in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithAllValidArguments_shouldNotThrowAnyException.
@Test
public void whenCheckingDeleteOperationWithAllValidArguments_shouldNotThrowAnyException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
MutationCondition condition = new DeleteIf(new ConditionalExpression(COL1, new IntValue(1), ConditionalExpression.Operator.EQ));
Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatCode(() -> operationChecker.check(delete)).doesNotThrowAnyException();
}
use of com.scalar.db.api.DeleteIf in project scalardb by scalar-labs.
the class ConditionalQueryBuilderTest method visit_DeleteIfAcceptCalled_ShouldCallWhere.
@Test
public void visit_DeleteIfAcceptCalled_ShouldCallWhere() {
// Arrange
DeleteIf condition = new DeleteIf(new ConditionalExpression(ANY_NAME_1, ANY_INT_VALUE, Operator.EQ), new ConditionalExpression(ANY_NAME_2, ANY_INT_VALUE, Operator.GT));
ConditionalQueryBuilder builder = new ConditionalQueryBuilder(select);
// Act
condition.accept(builder);
// Assert
verify(select).and(DSL.field("r.values[\"" + ANY_NAME_1 + "\"]").equal(ANY_INT));
verify(select).and(DSL.field("r.values[\"" + ANY_NAME_2 + "\"]").greaterThan(ANY_INT));
}
use of com.scalar.db.api.DeleteIf 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());
}
use of com.scalar.db.api.DeleteIf in project scalardb by scalar-labs.
the class ConditionExpressionBuilderTest method visit_DeleteIfAcceptCalled_ShouldCallWhere.
@Test
public void visit_DeleteIfAcceptCalled_ShouldCallWhere() {
// Arrange
DeleteIf condition = ConditionBuilder.deleteIf(ConditionBuilder.column(ANY_NAME_1).isEqualToInt(ANY_INT_VALUE.getAsInt())).and(ConditionBuilder.column(ANY_NAME_2).isGreaterThanInt(ANY_INT_VALUE.getAsInt())).and(ConditionBuilder.column(ANY_NAME_3).isNullInt()).and(ConditionBuilder.column(ANY_NAME_4).isNotNullInt()).build();
ConditionExpressionBuilder builder = new ConditionExpressionBuilder(DynamoOperation.CONDITION_COLUMN_NAME_ALIAS, DynamoOperation.CONDITION_VALUE_ALIAS);
// Act
condition.accept(builder);
String actual = builder.build();
// Assert
assertThat(actual).isEqualTo("#ccol0 = :cval0 AND #ccol1 > :cval1 " + "AND (attribute_not_exists(#ccol2) OR #ccol2 = :cval2) " + "AND (attribute_exists(#ccol3) AND NOT #ccol3 = :cval3)");
}
Aggregations