org.redisson.api.annotation.REntity Java Examples

The following examples show how to use org.redisson.api.annotation.REntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonObjectBuilder.java    From redisson with Apache License 2.0 5 votes vote down vote up
public NamingScheme getNamingScheme(Class<?> rEntity, Codec c) {
    REntity anno = ClassUtils.getAnnotation(rEntity, REntity.class);
    try {
        return anno.namingScheme().getDeclaredConstructor(Codec.class).newInstance(c);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #2
Source File: RedissonObjectBuilder.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Object fromReference(RedissonClient redisson, RedissonReference rr) throws ReflectiveOperationException {
    Class<? extends Object> type = rr.getType();
    if (type != null) {
        if (ClassUtils.isAnnotationPresent(type, REntity.class)) {
            RedissonLiveObjectService liveObjectService = (RedissonLiveObjectService) redisson.getLiveObjectService();
            
            NamingScheme ns = getNamingScheme(type);
            Object id = ns.resolveId(rr.getKeyName());
            return liveObjectService.createLiveObject(type, id);
        }
    }

    return getObject(redisson, rr, type, codecProvider);
}
 
Example #3
Source File: RedissonReference.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonReference(Class<?> type, String keyName, Codec codec) {
    if (!ClassUtils.isAnnotationPresent(type, REntity.class) && !RObject.class.isAssignableFrom(type) && !RObjectReactive.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException("Class reference has to be a type of either RObject or RLiveObject or RObjectReactive");
    }
    if (RObjectReactive.class.isAssignableFrom(type)) {
        this.type = REACTIVE_MAP.get(type.getName());
    } else {
        this.type = type.getName();
    }
    this.keyName = keyName;
    if (codec != null) {
        this.codec = codec.getClass().getName();
    }
}
 
Example #4
Source File: RedissonReference.java    From redisson with Apache License 2.0 5 votes vote down vote up
/**
 * @param type the type to set
 */
public void setType(Class<?> type) {
    if (!ClassUtils.isAnnotationPresent(type, REntity.class) 
            && (!RObject.class.isAssignableFrom(type) || !RObjectReactive.class.isAssignableFrom(type))) {
        throw new IllegalArgumentException("Class reference has to be a type of either RObject or RLiveObject or RObjectReactive");
    }
    this.type = type.getName();
}
 
Example #5
Source File: DefaultReferenceCodecProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Codec> T getCodec(REntity anno, Class<?> cls, Config config) {
    if (!ClassUtils.isAnnotationPresent(cls, anno.annotationType())) {
        throw new IllegalArgumentException("Annotation REntity does not present on type [" + cls.getCanonicalName() + "]");
    }
    
    Class<?> codecClass;
    if (anno.codec() == REntity.DEFAULT.class) {
        codecClass = config.getCodec().getClass();
    } else {
        codecClass = anno.codec();
    }

    return this.getCodec((Class<T>) codecClass);
}
 
Example #6
Source File: RedissonObjectBuilder.java    From redisson with Apache License 2.0 4 votes vote down vote up
public NamingScheme getNamingScheme(Class<?> entityClass) {
    REntity anno = ClassUtils.getAnnotation(entityClass, REntity.class);
    Codec codec = codecProvider.getCodec(anno, entityClass, config);
    return getNamingScheme(entityClass, codec);
}
 
Example #7
Source File: ReferenceCodecProvider.java    From redisson with Apache License 2.0 2 votes vote down vote up
/**
 * Get a codec instance by a REntity annotation and the class annotated with
 * it.
 * 
 * @param <T> the expected codec type.
 * @param anno REntity annotation used on the class.
 * @param cls The class that has the REntity annotation.
 * @param config Redisson config object
 * 
 * @return the cached codec instance.
 */
<T extends Codec> T getCodec(REntity anno, Class<?> cls, Config config);