|
60 | 60 | import org.springframework.data.cassandra.domain.TypeWithMapId;
|
61 | 61 | import org.springframework.data.cassandra.domain.User;
|
62 | 62 | import org.springframework.data.cassandra.domain.UserToken;
|
| 63 | +import org.springframework.data.cassandra.support.UserDefinedTypeBuilder; |
63 | 64 | import org.springframework.data.cassandra.test.util.RowMockUtil;
|
64 | 65 | import org.springframework.data.projection.EntityProjection;
|
65 | 66 | import org.springframework.data.projection.EntityProjectionIntrospector;
|
66 | 67 | import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
67 | 68 |
|
68 | 69 | import com.datastax.oss.driver.api.core.CqlIdentifier;
|
69 | 70 | import com.datastax.oss.driver.api.core.cql.Row;
|
| 71 | +import com.datastax.oss.driver.api.core.data.UdtValue; |
70 | 72 | import com.datastax.oss.driver.api.core.type.DataTypes;
|
71 | 73 | import com.datastax.oss.driver.internal.core.data.DefaultTupleValue;
|
72 | 74 | import com.datastax.oss.driver.internal.core.type.DefaultTupleType;
|
@@ -1308,9 +1310,8 @@ private static class TypeWithConvertedCollections {
|
1308 | 1310 | @CassandraType(type = CassandraType.Name.SET,
|
1309 | 1311 | typeArguments = CassandraType.Name.INT) private Set<Condition> conditionSet;
|
1310 | 1312 |
|
1311 |
| - @CassandraType(type = CassandraType.Name.MAP, |
1312 |
| - typeArguments = { CassandraType.Name.INT, |
1313 |
| - CassandraType.Name.INT }) private Map<Condition, Condition> conditionMap; |
| 1313 | + @CassandraType(type = CassandraType.Name.MAP, typeArguments = { CassandraType.Name.INT, |
| 1314 | + CassandraType.Name.INT }) private Map<Condition, Condition> conditionMap; |
1314 | 1315 |
|
1315 | 1316 | }
|
1316 | 1317 |
|
@@ -1481,7 +1482,8 @@ void readPrefixedEmbeddedType() {
|
1481 | 1482 | Row source = RowMockUtil.newRowMock(column("id", "id-1", DataTypes.TEXT), column("prefixage", 30, DataTypes.INT),
|
1482 | 1483 | column("prefixfirstname", "fn", DataTypes.TEXT));
|
1483 | 1484 |
|
1484 |
| - WithPrefixedNullableEmbeddedType target = mappingCassandraConverter.read(WithPrefixedNullableEmbeddedType.class, source); |
| 1485 | + WithPrefixedNullableEmbeddedType target = mappingCassandraConverter.read(WithPrefixedNullableEmbeddedType.class, |
| 1486 | + source); |
1485 | 1487 | assertThat(target.nested).isEqualTo(new EmbeddedWithSimpleTypes("fn", 30, null));
|
1486 | 1488 | }
|
1487 | 1489 |
|
@@ -1514,6 +1516,29 @@ void shouldApplyCustomConverterToMapLikeType() {
|
1514 | 1516 | assertThat(target.theJson.get("hello")).isEqualTo("world");
|
1515 | 1517 | }
|
1516 | 1518 |
|
| 1519 | + @Test // GH-1240 |
| 1520 | + void shouldReadOpenProjectionWithNestedObject() { |
| 1521 | + |
| 1522 | + com.datastax.oss.driver.api.core.type.UserDefinedType authorType = UserDefinedTypeBuilder.forName("author") |
| 1523 | + .withField("firstName", DataTypes.TEXT).withField("lastName", DataTypes.TEXT).build(); |
| 1524 | + |
| 1525 | + UdtValue udtValue = authorType.newValue().setString("firstName", "Walter").setString("lastName", "White"); |
| 1526 | + |
| 1527 | + Row source = RowMockUtil.newRowMock(column("id", "id-1", DataTypes.TEXT), column("name", "my-book", DataTypes.INT), |
| 1528 | + column("author", udtValue, authorType)); |
| 1529 | + |
| 1530 | + EntityProjectionIntrospector introspector = EntityProjectionIntrospector.create( |
| 1531 | + mappingCassandraConverter.getProjectionFactory(), |
| 1532 | + EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy() |
| 1533 | + .and((target, underlyingType) -> !mappingCassandraConverter.getCustomConversions().isSimpleType(target)), |
| 1534 | + mappingContext); |
| 1535 | + |
| 1536 | + BookProjection projection = mappingCassandraConverter |
| 1537 | + .project(introspector.introspect(BookProjection.class, Book.class), source); |
| 1538 | + |
| 1539 | + assertThat(projection.getName()).isEqualTo("my-book by Walter White"); |
| 1540 | + } |
| 1541 | + |
1517 | 1542 | static class TypeWithJsonObject {
|
1518 | 1543 |
|
1519 | 1544 | JSONObject theJson;
|
@@ -1542,4 +1567,33 @@ public String convert(JSONObject source) {
|
1542 | 1567 | }
|
1543 | 1568 |
|
1544 | 1569 | }
|
| 1570 | + |
| 1571 | + interface BookProjection { |
| 1572 | + |
| 1573 | + @Value("#{target.name + ' by ' + target.author.firstName + ' ' + target.author.lastName}") |
| 1574 | + String getName(); |
| 1575 | + } |
| 1576 | + |
| 1577 | + @Data |
| 1578 | + static class Book { |
| 1579 | + |
| 1580 | + @Id String id; |
| 1581 | + |
| 1582 | + String name; |
| 1583 | + |
| 1584 | + Author author = new Author(); |
| 1585 | + |
| 1586 | + } |
| 1587 | + |
| 1588 | + @Data |
| 1589 | + @UserDefinedType |
| 1590 | + static class Author { |
| 1591 | + |
| 1592 | + @Id String id; |
| 1593 | + |
| 1594 | + String firstName; |
| 1595 | + |
| 1596 | + String lastName; |
| 1597 | + |
| 1598 | + } |
1545 | 1599 | }
|
0 commit comments