use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.
@Test
public void delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly() throws IOException, ExecutionException {
// Arrange
List<Put> puts = preparePuts();
List<Delete> deletes = prepareDeletes();
storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
deletes.get(0).withCondition(new DeleteIfExists());
deletes.get(1).withCondition(new DeleteIf(new ConditionalExpression(columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
// Act
assertThatCode(() -> storage.delete(Arrays.asList(deletes.get(0), deletes.get(1), deletes.get(2)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(new Scan(new Key(columnName1, 0)));
assertThat(results.size()).isEqualTo(0);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ValueBinderTest method visit_AcceptCalledMultipleTimesWithNullValue_ShouldSkipNull.
@Test
public void visit_AcceptCalledMultipleTimesWithNullValue_ShouldSkipNull() {
// Arrange
IntValue value1 = new IntValue(ANY_NAME, ANY_INT);
BlobValue value2 = new BlobValue(ANY_NAME, (byte[]) null);
TextValue value3 = new TextValue(ANY_NAME, (String) null);
IntValue value4 = new IntValue(ANY_NAME, ANY_INT);
ValueBinder binder = new ValueBinder(bound);
// Act
value1.accept(binder);
value2.accept(binder);
value3.accept(binder);
value4.accept(binder);
// Assert
verify(bound).setInt(0, ANY_INT);
verify(bound, never()).setBytes(anyInt(), any(ByteBuffer.class));
verify(bound, never()).setString(anyInt(), anyString());
verify(bound).setInt(3, ANY_INT);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ValueBinderTest method visit_TextValueAcceptCalled_ShouldCallSetString.
@Test
public void visit_TextValueAcceptCalled_ShouldCallSetString() {
// Arrange
TextValue value = new TextValue(ANY_NAME, ANY_STRING);
ValueBinder binder = new ValueBinder(bound);
// Act
value.accept(binder);
// Assert
verify(bound).setString(0, ANY_STRING);
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class ResultInterpreter method getValue.
@Nullable
private Value<?> getValue(String name, ResultSet resultSet) throws SQLException {
Value<?> ret;
DataType dataType = metadata.getColumnDataType(name);
switch(dataType) {
case BOOLEAN:
ret = new BooleanValue(name, resultSet.getBoolean(name));
break;
case INT:
ret = new IntValue(name, resultSet.getInt(name));
break;
case BIGINT:
ret = new BigIntValue(name, resultSet.getLong(name));
break;
case FLOAT:
// To handle Float.MAX_VALUE in MySQL, we need to get the value as double, then cast it to
// float
ret = new FloatValue(name, (float) resultSet.getDouble(name));
break;
case DOUBLE:
ret = new DoubleValue(name, resultSet.getDouble(name));
break;
case TEXT:
ret = new TextValue(name, resultSet.getString(name));
break;
case BLOB:
ret = new BlobValue(name, resultSet.getBytes(name));
break;
default:
throw new AssertionError();
}
if (resultSet.wasNull()) {
return null;
}
return ret;
}
use of com.scalar.db.io.TextValue in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly.
@Test
public void delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() throws ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(columnName1, pKey);
Key clusteringKey = new Key(columnName4, cKey);
// Act
Delete delete = prepareDelete(pKey, cKey);
delete.withCondition(new DeleteIf(new ConditionalExpression(columnName2, new TextValue(Integer.toString(pKey)), ConditionalExpression.Operator.EQ)));
assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
// Assert
Optional<Result> actual = storage.get(new Get(partitionKey, clusteringKey));
assertThat(actual.isPresent()).isFalse();
}
Aggregations