use of com.datastax.oss.driver.api.core.type.ListType in project java-driver by datastax.
the class UserDefinedTypeListParserTest method should_resolve_nested_dependency.
@Test
public void should_resolve_nested_dependency() {
UserDefinedTypeParser parser = new UserDefinedTypeParser(new DataTypeCqlNameParser(), context);
Map<CqlIdentifier, UserDefinedType> types = parser.parse(KEYSPACE_ID, mockTypeRow("ks", "a", ImmutableList.of("bs"), ImmutableList.of("frozen<tuple<int, frozen<list<frozen<b>>>>>")), mockTypeRow("ks", "b", ImmutableList.of("i"), ImmutableList.of("int")));
assertThat(types).hasSize(2);
UserDefinedType aType = types.get(CqlIdentifier.fromInternal("a"));
UserDefinedType bType = types.get(CqlIdentifier.fromInternal("b"));
TupleType tupleType = (TupleType) aType.getFieldTypes().get(0);
ListType listType = (ListType) tupleType.getComponentTypes().get(1);
assertThat(listType.getElementType()).isEqualTo(bType);
}
use of com.datastax.oss.driver.api.core.type.ListType in project java-driver by datastax.
the class DataTypeDetachableTest method list_should_be_attached_if_its_element_is.
@Test
public void list_should_be_attached_if_its_element_is() {
TupleType tuple = DataTypes.tupleOf(DataTypes.INT);
ListType list = DataTypes.listOf(tuple);
assertThat(tuple.isDetached()).isTrue();
assertThat(list.isDetached()).isTrue();
tuple.attach(attachmentPoint);
assertThat(list.isDetached()).isFalse();
}
use of com.datastax.oss.driver.api.core.type.ListType in project java-driver by datastax.
the class CachingCodecRegistryTest method should_allow_covariance_for_lookups_by_cql_type_and_value.
@Test
public void should_allow_covariance_for_lookups_by_cql_type_and_value() {
TestCachingCodecRegistry registry = new TestCachingCodecRegistry(mockCache);
registry.register(new ACodec());
InOrder inOrder = inOrder(mockCache);
inOrder.verify(mockCache).lookup(DataTypes.INT, GenericType.of(A.class), false);
// covariance allowed
assertThat(registry.codecFor(DataTypes.INT, new B())).isInstanceOf(ACodec.class);
// no cache hit since we find the custom codec directly
inOrder.verifyNoMoreInteractions();
// note: in Java, type parameters are always invariant, so List<B> is not a subtype of List<A>;
// but in practice, a codec for List<A> is capable of encoding a List<B>, so we allow it (even
// if in driver 3.x that was forbidden).
List<B> list = Lists.newArrayList(new B());
ListType cqlType = DataTypes.listOf(DataTypes.INT);
TypeCodec<List<B>> actual = registry.codecFor(cqlType, list);
assertThat(actual).isInstanceOf(ListCodec.class);
assertThat(actual.getJavaType()).isEqualTo(GenericType.listOf(A.class));
assertThat(actual.accepts(list)).isTrue();
// accepts(GenericType) remains invariant, so it returns false for List<B>
assertThat(actual.accepts(GenericType.listOf(B.class))).isFalse();
inOrder.verify(mockCache).lookup(cqlType, GenericType.listOf(B.class), true);
inOrder.verifyNoMoreInteractions();
}
Aggregations