Feature - RLiveObjectService.count() method implemented. #2785

pull/2791/head
Nikita Koksharov 5 years ago
parent 170ad40656
commit fbf0f9b8e1

@ -138,6 +138,12 @@ public class RedissonLiveObjectService implements RLiveObjectService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public long count(Class<?> entityClass, Condition condition) {
Set<Object> ids = seachEngine.find(entityClass, condition);
return ids.size();
}
@Override @Override
public <T> T attach(T detachedObject) { public <T> T attach(T detachedObject) {
validateDetached(detachedObject); validateDetached(detachedObject);

@ -70,6 +70,22 @@ public interface RLiveObjectService {
*/ */
<T> Collection<T> find(Class<T> entityClass, Condition condition); <T> Collection<T> find(Class<T> entityClass, Condition condition);
/**
* Counts the entities matches specified <code>condition</code>.
* Usage example:
* <pre>
* long objectsAmount = liveObjectService.count(MyObject.class, Conditions.or(Conditions.in("field", "value1", "value2"),
* Conditions.and(Conditions.eq("field2", "value2"), Conditions.eq("field3", "value5"))));
* </pre>
*
* @see Conditions
*
* @param entityClass - entity class
* @param condition - condition object
* @return amount of live objects.
*/
long count(Class<?> entityClass, Condition condition);
/** /**
* Returns iterator for all entry ids by specified <code>entityClass</code>. * Returns iterator for all entry ids by specified <code>entityClass</code>.
* Ids traversed with SCAN operation. Each SCAN operation loads * Ids traversed with SCAN operation. Each SCAN operation loads

Loading…
Cancel
Save