DATAREDIS-530 - Fix PartialUpdate removing existing indexes.
We now make sure to leave existing indexes untouched when using PartialUpdate. We also fixed a glitch, where index values have not been removed correctly when saving entities with null values, along the way. Original pull request: #207.
This commit is contained in:
committed by
Mark Paluch
parent
0d24b5a573
commit
f5a506cb8d
@@ -76,6 +76,16 @@ class IndexWriter {
|
||||
* @param indexValues can be {@literal null}.
|
||||
*/
|
||||
public void updateIndexes(Object key, Iterable<IndexedData> indexValues) {
|
||||
createOrUpdateIndexes(key, indexValues, IndexWriteMode.PARTIAL_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates indexes by first removing key from existing one and then persisting new index data.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param indexValues can be {@literal null}.
|
||||
*/
|
||||
public void deleteAndUpdateIndexes(Object key, Iterable<IndexedData> indexValues) {
|
||||
createOrUpdateIndexes(key, indexValues, IndexWriteMode.UPDATE);
|
||||
}
|
||||
|
||||
@@ -96,7 +106,7 @@ class IndexWriter {
|
||||
removeKeyFromIndexes(data.getKeyspace(), binKey);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (ObjectUtils.nullSafeEquals(IndexWriteMode.PARTIAL_UPDATE, writeMode)) {
|
||||
removeKeyFromExistingIndexes(binKey, indexValues);
|
||||
}
|
||||
|
||||
@@ -229,6 +239,6 @@ class IndexWriter {
|
||||
*/
|
||||
private static enum IndexWriteMode {
|
||||
|
||||
CREATE, UPDATE
|
||||
CREATE, UPDATE, PARTIAL_UPDATE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
if (isNew) {
|
||||
indexWriter.createIndexes(key, rdo.getIndexedData());
|
||||
} else {
|
||||
indexWriter.updateIndexes(key, rdo.getIndexedData());
|
||||
indexWriter.deleteAndUpdateIndexes(key, rdo.getIndexedData());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import org.springframework.data.keyvalue.core.KeyValueAdapter;
|
||||
import org.springframework.data.keyvalue.core.KeyValueCallback;
|
||||
import org.springframework.data.keyvalue.core.KeyValueTemplate;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.core.mapping.RedisMappingContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -121,6 +120,7 @@ public class RedisKeyValueTemplate extends KeyValueTemplate {
|
||||
|
||||
if (objectToInsert instanceof PartialUpdate) {
|
||||
doPartialUpdate((PartialUpdate<?>) objectToInsert);
|
||||
return;
|
||||
}
|
||||
|
||||
super.insert(id, objectToInsert);
|
||||
@@ -135,6 +135,7 @@ public class RedisKeyValueTemplate extends KeyValueTemplate {
|
||||
|
||||
if (objectToUpdate instanceof PartialUpdate) {
|
||||
doPartialUpdate((PartialUpdate<?>) objectToUpdate);
|
||||
return;
|
||||
}
|
||||
|
||||
super.update(objectToUpdate);
|
||||
|
||||
Reference in New Issue
Block a user