Fixed - RLiveObjectService.persist() and merge() methods, when called with multiple arguments, return detached objects

pull/6244/head
Nikita Koksharov 4 months ago
parent 8cb9a373f8
commit c9cd7d5c57

@ -245,7 +245,7 @@ public class RedissonLiveObjectService implements RLiveObjectService {
}
if (type == RCascadeType.PERSIST) {
CommandBatchService checkExecutor = new CommandBatchService(batchService);
CommandBatchService checkExecutor = new CommandBatchService(commandExecutor);
for (Entry<String, Object> entry : name2id.entrySet()) {
RMap<String, Object> map = new RedissonMap<>(checkExecutor, entry.getKey(), null, null, null);
map.containsKeyAsync("redisson_live_object");
@ -284,7 +284,15 @@ public class RedissonLiveObjectService implements RLiveObjectService {
ClassIntrospector.get().reset();
batchService.execute();
return new ArrayList<>(detached2Attached.keySet());
classCache.clear();
List<T> attachedObjects = new ArrayList<>();
for (Object attachedObject : detached2Attached.values()) {
RLiveObject lo = asLiveObject(attachedObject);
T nlo = (T) createLiveObject(attachedObject.getClass().getSuperclass(), lo.getLiveObjectId(), commandExecutor, classCache);
attachedObjects.add(nlo);
}
return attachedObjects;
}
private <T> Object getId(T detachedObject) {

@ -1420,6 +1420,7 @@ public class RedissonLiveObjectServiceTest extends RedisDockerTest {
assertNotNull(service.get(TestClass.class, new ObjectId(100)));
persisted.setCode("CODE");
assertNotNull(service.get(TestClass.class, new ObjectId(100)));
assertThat(service.get(TestClass.class, new ObjectId(101))).isNull();
}
@Test
@ -2435,7 +2436,7 @@ public class RedissonLiveObjectServiceTest extends RedisDockerTest {
objects.clear();
for (int i = 0; i < objectsAmount; i++) {
TestREntity e = (TestREntity) attachedObjects.get(i);
TestREntity e = new TestREntity();
e.setName("" + i);
e.setValue("value" + i*1000);
objects.add(e);
@ -2443,6 +2444,10 @@ public class RedissonLiveObjectServiceTest extends RedisDockerTest {
List<Object> attachedObjects2 = s.merge(objects.toArray());
assertThat(attachedObjects2).hasSize(objectsAmount);
TestREntity e = (TestREntity) attachedObjects2.get(1);
assertThat(e.getName()).isNotNull();
assertThat(e.getValue()).isEqualTo("value1000");
assertThat(redisson.getKeys().count()).isEqualTo(objectsAmount);
}
@ -2462,6 +2467,14 @@ public class RedissonLiveObjectServiceTest extends RedisDockerTest {
List<Object> attachedObjects = s.persist(objects.toArray());
assertThat(attachedObjects).hasSize(objectsAmount);
TestREntity e = (TestREntity) attachedObjects.get(0);
assertThat(e.getName()).isNotNull();
e.setValue("test");
assertThat(e.getValue()).isEqualTo("test");
TestREntity rr = s.get(TestREntity.class, "0");
assertThat(rr.getValue()).isEqualTo("test");
assertThat(redisson.getKeys().count()).isEqualTo(objectsAmount);
}

Loading…
Cancel
Save