RLiveObjectService.delete throws NPE if entity doesn't exist. #1401

pull/1423/head
Nikita 7 years ago
parent cd39e884c9
commit b4f69ba974

@ -485,8 +485,12 @@ public class RedissonLiveObjectService implements RLiveObjectService {
}
@Override
public <T, K> void delete(Class<T> entityClass, K id) {
asLiveObject(get(entityClass, id)).delete();
public <T, K> boolean delete(Class<T> entityClass, K id) {
T entity = get(entityClass, id);
if (entity == null) {
return false;
}
return asLiveObject(entity).delete();
}
@Override

@ -120,9 +120,11 @@ public interface RLiveObjectService {
* @param <K> Key type
* @param entityClass - object class
* @param id - object id
*
* @return <code>true</code> if entity was deleted successfully, <code>false</code> otherwise
*/
<T, K> void delete(Class<T> entityClass, K id);
<T, K> boolean delete(Class<T> entityClass, K id);
/**
* To cast the instance to RLiveObject instance.
*

@ -1401,6 +1401,11 @@ public class RedissonLiveObjectServiceTest extends BaseTest {
assertThat(redisson.getKeys().count()).isEqualTo(1);
}
@Test
public void testDeleteNotExisted() {
RLiveObjectService service = redisson.getLiveObjectService();
assertThat(service.delete(Customer.class, "id")).isFalse();
}
@Test
public void testDelete() {

Loading…
Cancel
Save