Clear indexed data if property value is set to null.
Closes #2882 Original pull request: #2895
This commit is contained in:
committed by
Mark Paluch
parent
d5927bec22
commit
2fadbc9917
@@ -122,6 +122,7 @@ public class PathIndexResolver implements IndexResolver {
|
||||
Object propertyValue = accessor.getProperty(persistentProperty);
|
||||
|
||||
if (propertyValue == null) {
|
||||
indexes.addAll(resolveIndex(keyspace, currentPath, persistentProperty, null));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -212,7 +213,18 @@ public class PathIndexResolver implements IndexResolver {
|
||||
|
||||
IndexedData indexedData = null;
|
||||
if (transformedValue == null) {
|
||||
indexedData = new RemoveIndexedData(indexedData);
|
||||
|
||||
indexedData = new RemoveIndexedData(new IndexedData() {
|
||||
@Override
|
||||
public String getIndexName() {
|
||||
return indexDefinition.getIndexName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeyspace() {
|
||||
return indexDefinition.getKeyspace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
indexedData = indexedDataFactoryProvider.getIndexedDataFactory(indexDefinition).createIndexedDataFor(value);
|
||||
}
|
||||
@@ -220,13 +232,13 @@ public class PathIndexResolver implements IndexResolver {
|
||||
}
|
||||
}
|
||||
|
||||
else if (property != null && property.isAnnotationPresent(Indexed.class)) {
|
||||
else if (property != null && value != null && property.isAnnotationPresent(Indexed.class)) {
|
||||
|
||||
SimpleIndexDefinition indexDefinition = new SimpleIndexDefinition(keyspace, path);
|
||||
indexConfiguration.addIndexDefinition(indexDefinition);
|
||||
|
||||
data.add(indexedDataFactoryProvider.getIndexedDataFactory(indexDefinition).createIndexedDataFor(value));
|
||||
} else if (property != null && property.isAnnotationPresent(GeoIndexed.class)) {
|
||||
} else if (property != null && value != null && property.isAnnotationPresent(GeoIndexed.class)) {
|
||||
|
||||
GeoIndexDefinition indexDefinition = new GeoIndexDefinition(keyspace, path);
|
||||
indexConfiguration.addIndexDefinition(indexDefinition);
|
||||
|
||||
@@ -147,6 +147,25 @@ public class RedisKeyValueAdapterTests {
|
||||
assertThat(template.opsForSet().members("persons:firstname:rand")).contains("1");
|
||||
}
|
||||
|
||||
@Test // GH-2882
|
||||
void indexDataShouldBeCleardIfPropertyValueIsSetToNull() {
|
||||
|
||||
Person rand = new Person();
|
||||
rand.firstname = "rand";
|
||||
|
||||
adapter.put("1", rand, "persons");
|
||||
|
||||
assertThat(template.keys("persons*")).contains("persons:firstname:rand");
|
||||
assertThat(template.opsForSet().members("persons:firstname:rand")).contains("1");
|
||||
|
||||
rand.id = "1";
|
||||
rand.firstname = null;
|
||||
adapter.put("1", rand, "persons");
|
||||
|
||||
assertThat(template.keys("persons*")).doesNotContain("persons:firstname:rand");
|
||||
assertThat(template.opsForSet().members("persons:firstname:rand")).doesNotContain("1");
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-744
|
||||
void putWritesSimpleIndexDataWithColonCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user