Search in sources :

Example 16 with TextValue

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);
}
Also used : Delete(com.scalar.db.api.Delete) TextValue(com.scalar.db.io.TextValue) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) DeleteIfExists(com.scalar.db.api.DeleteIfExists) DeleteIf(com.scalar.db.api.DeleteIf) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 17 with TextValue

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);
}
Also used : TextValue(com.scalar.db.io.TextValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) ByteBuffer(java.nio.ByteBuffer) BlobValue(com.scalar.db.io.BlobValue) Test(org.junit.Test)

Example 18 with TextValue

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);
}
Also used : TextValue(com.scalar.db.io.TextValue) Test(org.junit.Test)

Example 19 with TextValue

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;
}
Also used : DoubleValue(com.scalar.db.io.DoubleValue) TextValue(com.scalar.db.io.TextValue) BooleanValue(com.scalar.db.io.BooleanValue) DataType(com.scalar.db.io.DataType) FloatValue(com.scalar.db.io.FloatValue) IntValue(com.scalar.db.io.IntValue) BigIntValue(com.scalar.db.io.BigIntValue) BigIntValue(com.scalar.db.io.BigIntValue) BlobValue(com.scalar.db.io.BlobValue) Nullable(javax.annotation.Nullable)

Example 20 with TextValue

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();
}
Also used : TextValue(com.scalar.db.io.TextValue) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

TextValue (com.scalar.db.io.TextValue)89 Key (com.scalar.db.io.Key)60 IntValue (com.scalar.db.io.IntValue)51 Test (org.junit.jupiter.api.Test)47 Test (org.junit.Test)38 BooleanValue (com.scalar.db.io.BooleanValue)36 Put (com.scalar.db.api.Put)27 BigIntValue (com.scalar.db.io.BigIntValue)27 DoubleValue (com.scalar.db.io.DoubleValue)26 BlobValue (com.scalar.db.io.BlobValue)25 FloatValue (com.scalar.db.io.FloatValue)24 Result (com.scalar.db.api.Result)23 ConditionalExpression (com.scalar.db.api.ConditionalExpression)21 Get (com.scalar.db.api.Get)17 Value (com.scalar.db.io.Value)15 DeleteIf (com.scalar.db.api.DeleteIf)11 Delete (com.scalar.db.api.Delete)8 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)8 PutIf (com.scalar.db.api.PutIf)6 PreparedStatement (java.sql.PreparedStatement)6