Skip to content

Commit 73bcfe6

Browse files
committed
Properly consider frozen map creation.
We now correctly consider the Frozen annotation when annotating a property to define a frozen<map<…>> type. Previously we conly considered frozen key and value components instead of the entire type. Closes #1148
1 parent 522e241 commit 73bcfe6

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/convert/ColumnType.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,21 @@ static ColumnType mapOf(ColumnType keyType, ColumnType valueType) {
159159
* @return
160160
*/
161161
static CassandraColumnType mapOf(CassandraColumnType keyType, CassandraColumnType valueType) {
162+
return ColumnType.mapOf(keyType, valueType, false);
163+
}
164+
165+
/**
166+
* Creates a Map {@link CassandraColumnType} given its {@link CassandraColumnType key and value types}.
167+
*
168+
* @param keyType must not be {@literal null}.
169+
* @param valueType must not be {@literal null}.
170+
* @param frozen
171+
* @return
172+
* @since 3.1.12
173+
*/
174+
static CassandraColumnType mapOf(CassandraColumnType keyType, CassandraColumnType valueType, boolean frozen) {
162175
return new DefaultCassandraColumnType(ClassTypeInformation.MAP,
163-
() -> DataTypes.mapOf(keyType.getDataType(), valueType.getDataType()), keyType, valueType);
176+
() -> DataTypes.mapOf(keyType.getDataType(), valueType.getDataType(), frozen), keyType, valueType);
164177
}
165178

166179
/**

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/convert/DefaultColumnTypeResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private CassandraColumnType createCassandraTypeDescriptor(TypeInformation<?> typ
410410
FrozenIndicator frozenValue = frozen.getFrozen(1);
411411

412412
return ColumnType.mapOf(resolve(typeInformation.getRequiredComponentType(), frozenKey),
413-
resolve(typeInformation.getRequiredMapValueType(), frozenValue));
413+
resolve(typeInformation.getRequiredMapValueType(), frozenValue), frozen.isFrozen());
414414
}
415415

416416
CassandraPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(typeInformation);

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/convert/ColumnTypeResolverUnitTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ void setPropertyWithFrozenAnnotationOnElement() {
260260
.describedAs("The element type should be frozen").isTrue();
261261
}
262262

263+
@Test // GH-1148
264+
void frozenMapProperty() {
265+
266+
BasicCassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(Person.class);
267+
268+
DataType dataType = resolver.resolve(entity.getRequiredPersistentProperty("frozenMap")).getDataType();
269+
270+
assertThat(dataType).isInstanceOf(MapType.class);
271+
assertThat(((MapType) dataType).isFrozen()).isTrue();
272+
assertThat(dataType.asCql(true, false)).isEqualTo("frozen<map<text, text>>");
273+
}
274+
263275
@Test // DATACASS-465
264276
void mapPropertyWithFrozenAnnotationOnKey() {
265277

@@ -345,6 +357,8 @@ static class Person {
345357
@Frozen Set<String> frozenSet;
346358
Set<@Frozen MyUdt> frozenSetContent;
347359

360+
@Frozen Map<String, String> frozenMap;
361+
348362
Map<@Frozen MyUdt, MyUdt> frozenMapKey;
349363

350364
Map<MyUdt, @Frozen MyUdt> frozenMapValue;

0 commit comments

Comments
 (0)