DATACASS-770 - Fix type derivation for Set typed query and update values.
DefaultColumnTypeResolver now resolves correctly set-typed values to a set<…> column type. This change fixes a bug related to adding new elements to a Set via UpdateMapper. Original pull request: #174.
This commit is contained in:
committed by
Mark Paluch
parent
a97ee47ba6
commit
2e161dbb9f
@@ -65,6 +65,7 @@ import com.datastax.oss.driver.api.core.type.reflect.GenericType;
|
||||
* Default {@link ColumnTypeResolver} implementation backed by {@link CustomConversions} and {@link CodecRegistry}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Marko Janković
|
||||
* @since 3.0
|
||||
*/
|
||||
class DefaultColumnTypeResolver implements ColumnTypeResolver {
|
||||
@@ -290,7 +291,7 @@ class DefaultColumnTypeResolver implements ColumnTypeResolver {
|
||||
}
|
||||
|
||||
if (value instanceof Set) {
|
||||
return ColumnType.listOf(DefaultColumnType.OBJECT);
|
||||
return ColumnType.setOf(DefaultColumnType.OBJECT);
|
||||
}
|
||||
|
||||
if (value instanceof UdtValue) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -54,6 +55,7 @@ import com.datastax.oss.driver.api.core.type.DataTypes;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @author Marko Janković
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UpdateMapperUnitTests {
|
||||
@@ -63,6 +65,7 @@ public class UpdateMapperUnitTests {
|
||||
CassandraPersistentEntity<?> persistentEntity;
|
||||
|
||||
Currency currency = Currency.getInstance("EUR");
|
||||
Currency currencyUSD = Currency.getInstance("USD");
|
||||
|
||||
MappingCassandraConverter cassandraConverter;
|
||||
|
||||
@@ -207,6 +210,79 @@ public class UpdateMapperUnitTests {
|
||||
assertThat(update.toString()).isEqualTo("list = []");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldPrependAllToSet() {
|
||||
|
||||
Update update = updateMapper.getMappedObject(Update.empty().addTo("set").prependAll(currencyUSD, currency),
|
||||
persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = {'US Dollar','Euro'} + set_col");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldAppendAllToSet() {
|
||||
|
||||
Update update = updateMapper.getMappedObject(Update.empty().addTo("set").appendAll(currencyUSD, currency),
|
||||
persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = set_col + {'US Dollar','Euro'}");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldPrependAllToSetViaColumnNameCollectionOfElements() {
|
||||
Set<Currency> tmp = new LinkedHashSet<>();
|
||||
tmp.add(currencyUSD);
|
||||
tmp.add(currency);
|
||||
Update update = updateMapper.getMappedObject(Update.empty().addTo("set_col").prependAll(tmp),
|
||||
persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = {'US Dollar','Euro'} + set_col");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldAppendAllToSetViaColumnNameCollectionOfElements() {
|
||||
Set<Currency> tmp = new LinkedHashSet<>();
|
||||
tmp.add(currencyUSD);
|
||||
tmp.add(currency);
|
||||
Update update = updateMapper.getMappedObject(Update.empty().addTo("set_col").appendAll(tmp),
|
||||
persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = set_col + {'US Dollar','Euro'}");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldAppendToSet() {
|
||||
|
||||
Update update = updateMapper.getMappedObject(Update.empty().addTo("set").append(currency),
|
||||
persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = set_col + {'Euro'}");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldPrependToSet() {
|
||||
|
||||
Update update = updateMapper.getMappedObject(Update.empty().addTo("set").prepend(currency),
|
||||
persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = {'Euro'} + set_col");
|
||||
}
|
||||
|
||||
@Test // DATACASS-770
|
||||
public void shouldRemoveFromSet() {
|
||||
|
||||
Update update = updateMapper.getMappedObject(Update.empty().remove("set", currency), persistentEntity);
|
||||
|
||||
assertThat(update.getUpdateOperations()).hasSize(1);
|
||||
assertThat(update.toString()).isEqualTo("set_col = set_col - {'Euro'}");
|
||||
}
|
||||
|
||||
@Test // DATACASS-343
|
||||
public void shouldClearSet() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user