Skip to content

Commit

Permalink
Handling object update scenario such that an update overwrites the in…
Browse files Browse the repository at this point in the history
…dex of a field with a prior index entry.
  • Loading branch information
gsharma authored and Jonathan Leibiusky committed Dec 26, 2010
1 parent 051ec19 commit 939768c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/main/java/redis/clients/johm/JOhm.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public static <T> T save(final Object model) {

@SuppressWarnings("unchecked")
public static <T> T save(final Object model, boolean saveChildren) {
if (!isNew(model)) {
delete(model.getClass(), JOhmUtils.getId(model));
}
final Nest nest = initIfNeeded(model);

final Map<String, String> hashedObject = new HashMap<String, String>();
Expand Down Expand Up @@ -290,7 +293,8 @@ public static boolean delete(Class<?> clazz, int id, boolean deleteIndexes,
fieldValue = JOhmUtils.getId(fieldValue);
}
if (!JOhmUtils.isNullOrEmpty(fieldValue)) {
nest.cat(field.getName()).cat(fieldValue).del();
nest.cat(field.getName()).cat(fieldValue).srem(
String.valueOf(id));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/redis/clients/johm/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ public void cannotSearchAfterDeletingIndexes() {
assertNotNull(JOhm.get(User.class, id));

List<User> users = JOhm.find(User.class, "age", 88);
assertEquals(1, users.size());
assertEquals(0, users.size()); // index already updated
users = JOhm.find(User.class, "age", 77);
assertEquals(1, users.size());
assertEquals(0, users.size()); // index already updated
users = JOhm.find(User.class, "age", 66);
assertEquals(1, users.size());

Expand Down

0 comments on commit 939768c

Please sign in to comment.