Package org.redisson.api
Interface RLiveObjectService
-
- All Known Implementing Classes:
RedissonLiveObjectService
public interface RLiveObjectService
The pre-registration of each entity class is not necessary. Entity's getters and setters operations gets redirected to Redis automatically.- Author:
- Rui Gu (https://github.com/jackygurui), Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> RLiveObject
asLiveObject(T instance)
To cast the instance to RLiveObject instance.<T,K,V>
RMap<K,V>asRMap(T instance)
To cast the instance to RMap instance.<T> T
attach(T detachedObject)
Returns proxied object for the detached object.long
count(Class<?> entityClass, Condition condition)
Counts the entities matches specifiedcondition
.<T> long
delete(Class<T> entityClass, Object... ids)
Deletes object by class and ids including all nested objects.<T> void
delete(T attachedObject)
Deletes attached object including all nested objects.<T> T
detach(T attachedObject)
Returns unproxied detached object for the attached object.<T> Collection<T>
find(Class<T> entityClass, Condition condition)
Finds the entities matches specifiedcondition
.<K> Iterable<K>
findIds(Class<?> entityClass)
Returns iterator for all entry ids by specifiedentityClass
.<K> Iterable<K>
findIds(Class<?> entityClass, int count)
Returns iterator for all entry ids by specifiedentityClass
.<T> T
get(Class<T> entityClass, Object id)
Finds the entity from Redis with the id.boolean
isClassRegistered(Class<?> cls)
Check if the class is registered in the cache.<T> boolean
isExists(T instance)
Returns true if the RLiveObject already exists in redis.<T> boolean
isLiveObject(T instance)
Returns true if the instance is a instance of RLiveObject.<T> T
merge(T detachedObject)
Returns proxied object for the detached object.<T> T
persist(T detachedObject)
Returns proxied attached object for the detached object.<T> List<T>
persist(T... detachedObjects)
Returns proxied attached objects for the detached objects.void
registerClass(Class<?> cls)
Pre register the class with the service, registering all the classes on startup can speed up the instance creation.void
unregisterClass(Class<?> cls)
Unregister the class with the service.
-
-
-
Method Detail
-
get
<T> T get(Class<T> entityClass, Object id)
Finds the entity from Redis with the id. The entityClass should have a field annotated with RId, and the entityClass itself should have REntity annotated. The type of the RId can be anything except the followings:- An array i.e. byte[], int[], Integer[], etc.
- or a RObject i.e. RedissonMap
- or a Class with REntity annotation.
- Type Parameters:
T
- Entity type- Parameters:
entityClass
- - entity classid
- identifier- Returns:
- a proxied object if it exists in redis, or null if not.
-
find
<T> Collection<T> find(Class<T> entityClass, Condition condition)
Finds the entities matches specifiedcondition
. Usage example:Collection objects = liveObjectService.find(MyObject.class, Conditions.or(Conditions.in("field", "value1", "value2"), Conditions.and(Conditions.eq("field2", "value2"), Conditions.eq("field3", "value5"))));
- Type Parameters:
T
- Entity type- Parameters:
entityClass
- - entity classcondition
- - condition object- Returns:
- collection of live objects or empty collection.
- See Also:
Conditions
-
count
long count(Class<?> entityClass, Condition condition)
Counts the entities matches specifiedcondition
. Usage example:long objectsAmount = liveObjectService.count(MyObject.class, Conditions.or(Conditions.in("field", "value1", "value2"), Conditions.and(Conditions.eq("field2", "value2"), Conditions.eq("field3", "value5"))));
- Parameters:
entityClass
- - entity classcondition
- - condition object- Returns:
- amount of live objects.
- See Also:
Conditions
-
findIds
<K> Iterable<K> findIds(Class<?> entityClass)
Returns iterator for all entry ids by specifiedentityClass
. Ids traversed with SCAN operation. Each SCAN operation loads up tocount
keys per request.- Type Parameters:
K
- Key type- Parameters:
entityClass
- - entity class- Returns:
- collection of ids or empty collection.
-
findIds
<K> Iterable<K> findIds(Class<?> entityClass, int count)
Returns iterator for all entry ids by specifiedentityClass
. Ids traversed with SCAN operation. Each SCAN operation loads up tocount
keys per request.- Type Parameters:
K
- Key type- Parameters:
entityClass
- - entity classcount
- - keys loaded per request to Redis- Returns:
- collection of ids or empty collection.
-
attach
<T> T attach(T detachedObject)
Returns proxied object for the detached object. Discard all the field values already in the detached instance. The class representing this object should have a field annotated with RId, and the object should hold a non null value in that field. If this object is not in redis then a new blank proxied instance with the same RId field value will be created.- Type Parameters:
T
- Entity type- Parameters:
detachedObject
- - not proxied object- Returns:
- proxied object
- Throws:
IllegalArgumentException
- if the object is is a RLiveObject instance.
-
merge
<T> T merge(T detachedObject)
Returns proxied object for the detached object. Transfers all the NON NULL field values to the redis server. It does not delete any existing data in redis in case of the field value is null. The class representing this object should have a field annotated with RId, and the object should hold a non null value in that field. If this object is not in redis then a new hash key will be created to store it. Otherwise overrides current object state in Redis with the given object state.- Type Parameters:
T
- Entity type- Parameters:
detachedObject
- - not proxied object- Returns:
- proxied object
- Throws:
IllegalArgumentException
- if the object is is a RLiveObject instance.
-
persist
<T> T persist(T detachedObject)
Returns proxied attached object for the detached object. Transfers all the NON NULL field values to the redis server. Only when the it does not already exist.- Type Parameters:
T
- Entity type- Parameters:
detachedObject
- - not proxied object- Returns:
- proxied object
-
persist
<T> List<T> persist(T... detachedObjects)
Returns proxied attached objects for the detached objects. Stores all the NON NULL field values.Executed in a batch mode.
- Type Parameters:
T
- Entity type- Parameters:
detachedObjects
- - not proxied objects- Returns:
- list of proxied objects
-
detach
<T> T detach(T attachedObject)
Returns unproxied detached object for the attached object.- Type Parameters:
T
- Entity type- Parameters:
attachedObject
- - proxied object- Returns:
- proxied object
-
delete
<T> void delete(T attachedObject)
Deletes attached object including all nested objects.- Type Parameters:
T
- Entity type- Parameters:
attachedObject
- - proxied object
-
delete
<T> long delete(Class<T> entityClass, Object... ids)
Deletes object by class and ids including all nested objects.- Type Parameters:
T
- Entity type- Parameters:
entityClass
- - object classids
- - object ids- Returns:
- amount of deleted objects
-
asLiveObject
<T> RLiveObject asLiveObject(T instance)
To cast the instance to RLiveObject instance.- Type Parameters:
T
- type of instance- Parameters:
instance
- - live object- Returns:
- RLiveObject compatible object
-
asRMap
<T,K,V> RMap<K,V> asRMap(T instance)
To cast the instance to RMap instance.- Type Parameters:
T
- type of instanceK
- type of keyV
- type of value- Parameters:
instance
- - live object- Returns:
- RMap compatible object
-
isLiveObject
<T> boolean isLiveObject(T instance)
Returns true if the instance is a instance of RLiveObject.- Type Parameters:
T
- type of instance- Parameters:
instance
- - live object- Returns:
true
object is RLiveObject
-
isExists
<T> boolean isExists(T instance)
Returns true if the RLiveObject already exists in redis. It will return false if the passed object is not a RLiveObject.- Type Parameters:
T
- type of instance- Parameters:
instance
- - live object- Returns:
true
object exists
-
registerClass
void registerClass(Class<?> cls)
Pre register the class with the service, registering all the classes on startup can speed up the instance creation. This is NOT mandatory since the class will also be registered lazily when it is first used. All classed registered with the service is stored in a class cache. The cache is independent between different RedissonClient instances. When a class is registered in one RLiveObjectService instance it is also accessible in another RLiveObjectService instance so long as they are created by the same RedissonClient instance.- Parameters:
cls
- - class
-
unregisterClass
void unregisterClass(Class<?> cls)
Unregister the class with the service. This is useful after you decide the class is no longer required. A class will be automatically unregistered if the service encountered any errors during proxying or creating the object, since those errors are not recoverable. All classed registered with the service is stored in a class cache. The cache is independent between different RedissonClient instances. When a class is registered in one RLiveObjectService instance it is also accessible in another RLiveObjectService instance so long as they are created by the same RedissonClient instance.- Parameters:
cls
- It can be either the proxied class or the unproxied conterpart.
-
isClassRegistered
boolean isClassRegistered(Class<?> cls)
Check if the class is registered in the cache. All classed registered with the service is stored in a class cache. The cache is independent between different RedissonClient instances. When a class is registered in one RLiveObjectService instance it is also accessible in another RLiveObjectService instance so long as they are created by the same RedissonClient instance.- Parameters:
cls
- - type of instance- Returns:
true
if class already registered
-
-