Search in sources :

Example 1 with RObjectReactive

use of org.redisson.api.RObjectReactive in project redisson by redisson.

the class RedissonObjectFactory method toReference.

public static RedissonReference toReference(RedissonReactiveClient redissonReactive, Object object) {
    if (object instanceof RObjectReactive && !(object instanceof RLiveObject)) {
        RObjectReactive rObject = ((RObjectReactive) object);
        redissonReactive.getCodecProvider().registerCodec((Class) rObject.getCodec().getClass(), (Class) rObject.getClass(), rObject.getName(), rObject.getCodec());
        return new RedissonReference(object.getClass(), ((RObjectReactive) object).getName(), ((RObjectReactive) object).getCodec());
    }
    try {
        if (object instanceof RLiveObject) {
            Class<? extends Object> rEntity = object.getClass().getSuperclass();
            REntity anno = rEntity.getAnnotation(REntity.class);
            NamingScheme ns = anno.namingScheme().getDeclaredConstructor(Codec.class).newInstance(redissonReactive.getCodecProvider().getCodec(anno, (Class) rEntity));
            String name = Introspectior.getFieldsWithAnnotation(rEntity, RId.class).getOnly().getName();
            Class<?> type = rEntity.getDeclaredField(name).getType();
            return new RedissonReference(rEntity, ns.getName(rEntity, type, name, ((RLiveObject) object).getLiveObjectId()));
        }
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    return null;
}
Also used : Codec(org.redisson.client.codec.Codec) RObjectReactive(org.redisson.api.RObjectReactive) REntity(org.redisson.api.annotation.REntity) RedissonReference(org.redisson.RedissonReference) NamingScheme(org.redisson.liveobject.resolver.NamingScheme) RLiveObject(org.redisson.api.RLiveObject)

Aggregations

RedissonReference (org.redisson.RedissonReference)1 RLiveObject (org.redisson.api.RLiveObject)1 RObjectReactive (org.redisson.api.RObjectReactive)1 REntity (org.redisson.api.annotation.REntity)1 Codec (org.redisson.client.codec.Codec)1 NamingScheme (org.redisson.liveobject.resolver.NamingScheme)1