Package org.redisson

Class RedissonLiveObjectService

java.lang.Object
org.redisson.RedissonLiveObjectService
All Implemented Interfaces:
RLiveObjectService

public class RedissonLiveObjectService extends Object implements RLiveObjectService
  • Constructor Details

  • Method Details

    • createLiveObject

      public <T> T createLiveObject(Class<T> entityClass, Object id)
    • get

      public <T> T get(Class<T> entityClass, Object id)
      Description copied from interface: RLiveObjectService
      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:
      1. An array i.e. byte[], int[], Integer[], etc.
      2. or a RObject i.e. RedissonMap
      3. or a Class with REntity annotation.
      Specified by:
      get in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      entityClass - - entity class
      id - identifier
      Returns:
      a proxied object if it exists in redis, or null if not.
    • find

      public <T> Collection<T> find(Class<T> entityClass, Condition condition)
      Description copied from interface: RLiveObjectService
      Finds the entities matches specified condition. 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"))));
       
      Specified by:
      find in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      entityClass - - entity class
      condition - - condition object
      Returns:
      collection of live objects or empty collection.
      See Also:
    • count

      public long count(Class<?> entityClass, Condition condition)
      Description copied from interface: RLiveObjectService
      Counts the entities matches specified condition. 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"))));
       
      Specified by:
      count in interface RLiveObjectService
      Parameters:
      entityClass - - entity class
      condition - - condition object
      Returns:
      amount of live objects.
      See Also:
    • attach

      public <T> T attach(T detachedObject)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      attach in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      detachedObject - - not proxied object
      Returns:
      proxied object
    • merge

      public <T> T merge(T detachedObject)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      merge in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      detachedObject - - not proxied object
      Returns:
      proxied object
    • persist

      public <T> T persist(T detachedObject)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      persist in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      detachedObject - - not proxied object
      Returns:
      proxied object
    • persist

      public <T> List<T> persist(T... detachedObjects)
      Description copied from interface: RLiveObjectService
      Returns proxied attached objects for the detached objects. Stores all the NON NULL field values.

      Executed in a batch mode.

      Specified by:
      persist in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      detachedObjects - - not proxied objects
      Returns:
      list of proxied objects
    • merge

      public <T> List<T> merge(T... detachedObjects)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      merge in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      detachedObjects - - not proxied objects
      Returns:
      proxied object
    • persist

      public <T> List<T> persist(RCascadeType type, T... detachedObjects)
    • detach

      public <T> T detach(T attachedObject)
      Description copied from interface: RLiveObjectService
      Returns unproxied detached object for the attached object.
      Specified by:
      detach in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      attachedObject - - proxied object
      Returns:
      proxied object
    • delete

      public <T> void delete(T attachedObject)
      Description copied from interface: RLiveObjectService
      Deletes attached object including all nested objects.
      Specified by:
      delete in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      attachedObject - - proxied object
    • delete

      public <T> long delete(Class<T> entityClass, Object... ids)
      Description copied from interface: RLiveObjectService
      Deletes object by class and ids including all nested objects.
      Specified by:
      delete in interface RLiveObjectService
      Type Parameters:
      T - Entity type
      Parameters:
      entityClass - - object class
      ids - - object ids
      Returns:
      amount of deleted objects
    • delete

      public RFuture<Long> delete(Object id, Class<?> entityClass, NamingScheme namingScheme, CommandBatchService ce)
    • findIds

      public <K> Iterable<K> findIds(Class<?> entityClass)
      Description copied from interface: RLiveObjectService
      Returns iterator for all entry ids by specified entityClass. Ids traversed with SCAN operation. Each SCAN operation loads up to count keys per request.
      Specified by:
      findIds in interface RLiveObjectService
      Type Parameters:
      K - Key type
      Parameters:
      entityClass - - entity class
      Returns:
      collection of ids or empty collection.
    • findIds

      public <K> Iterable<K> findIds(Class<?> entityClass, int count)
      Description copied from interface: RLiveObjectService
      Returns iterator for all entry ids by specified entityClass. Ids traversed with SCAN operation. Each SCAN operation loads up to count keys per request.
      Specified by:
      findIds in interface RLiveObjectService
      Type Parameters:
      K - Key type
      Parameters:
      entityClass - - entity class
      count - - keys loaded per request to Redis
      Returns:
      collection of ids or empty collection.
    • asLiveObject

      public <T> RLiveObject asLiveObject(T instance)
      Description copied from interface: RLiveObjectService
      To cast the instance to RLiveObject instance.
      Specified by:
      asLiveObject in interface RLiveObjectService
      Type Parameters:
      T - type of instance
      Parameters:
      instance - - live object
      Returns:
      RLiveObject compatible object
    • asRMap

      public <T, K, V> RMap<K,V> asRMap(T instance)
      Description copied from interface: RLiveObjectService
      To cast the instance to RMap instance.
      Specified by:
      asRMap in interface RLiveObjectService
      Type Parameters:
      T - type of instance
      K - type of key
      V - type of value
      Parameters:
      instance - - live object
      Returns:
      RMap compatible object
    • isLiveObject

      public <T> boolean isLiveObject(T instance)
      Description copied from interface: RLiveObjectService
      Returns true if the instance is a instance of RLiveObject.
      Specified by:
      isLiveObject in interface RLiveObjectService
      Type Parameters:
      T - type of instance
      Parameters:
      instance - - live object
      Returns:
      true object is RLiveObject
    • isExists

      public <T> boolean isExists(T instance)
      Description copied from interface: RLiveObjectService
      Returns true if the RLiveObject already exists in redis. It will return false if the passed object is not a RLiveObject.
      Specified by:
      isExists in interface RLiveObjectService
      Type Parameters:
      T - type of instance
      Parameters:
      instance - - live object
      Returns:
      true object exists
    • registerClass

      public void registerClass(Class<?> cls)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      registerClass in interface RLiveObjectService
      Parameters:
      cls - - class
    • unregisterClass

      public void unregisterClass(Class<?> cls)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      unregisterClass in interface RLiveObjectService
      Parameters:
      cls - It can be either the proxied class or the unproxied conterpart.
    • isClassRegistered

      public boolean isClassRegistered(Class<?> cls)
      Description copied from interface: RLiveObjectService
      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.
      Specified by:
      isClassRegistered in interface RLiveObjectService
      Parameters:
      cls - - type of instance
      Returns:
      true if class already registered