|
|
|
@ -16,7 +16,6 @@
|
|
|
|
|
package org.redisson.liveobject.core;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Deque;
|
|
|
|
@ -89,6 +88,9 @@ public class RedissonObjectBuilder {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final Config config;
|
|
|
|
|
private final RedissonClient redisson;
|
|
|
|
|
private final RedissonReactiveClient redissonReactive;
|
|
|
|
|
private final RedissonRxClient redissonRx;
|
|
|
|
|
|
|
|
|
|
public static class CodecMethodRef {
|
|
|
|
|
|
|
|
|
@ -105,9 +107,13 @@ public class RedissonObjectBuilder {
|
|
|
|
|
|
|
|
|
|
private final ReferenceCodecProvider codecProvider = new DefaultReferenceCodecProvider();
|
|
|
|
|
|
|
|
|
|
public RedissonObjectBuilder(Config config) {
|
|
|
|
|
public RedissonObjectBuilder(Config config,
|
|
|
|
|
RedissonClient redisson, RedissonReactiveClient redissonReactive, RedissonRxClient redissonRx) {
|
|
|
|
|
super();
|
|
|
|
|
this.config = config;
|
|
|
|
|
this.redisson = redisson;
|
|
|
|
|
this.redissonReactive = redissonReactive;
|
|
|
|
|
this.redissonRx = redissonRx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ReferenceCodecProvider getReferenceCodecProvider() {
|
|
|
|
@ -123,7 +129,7 @@ public class RedissonObjectBuilder {
|
|
|
|
|
new RedissonReference(ar.getClass(), ar.getName(), codec));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RObject createObject(Object id, Class<?> clazz, Class<?> fieldType, String fieldName, RedissonClient redisson) {
|
|
|
|
|
public RObject createObject(Object id, Class<?> clazz, Class<?> fieldType, String fieldName) {
|
|
|
|
|
Class<? extends RObject> mappedClass = getMappedClass(fieldType);
|
|
|
|
|
try {
|
|
|
|
|
if (mappedClass != null) {
|
|
|
|
@ -142,7 +148,7 @@ public class RedissonObjectBuilder {
|
|
|
|
|
/**
|
|
|
|
|
* WARNING: rEntity has to be the class of @This object.
|
|
|
|
|
*/
|
|
|
|
|
private Codec getFieldCodec(Class<?> rEntity, Class<? extends RObject> rObjectClass, String fieldName) throws Exception {
|
|
|
|
|
private Codec getFieldCodec(Class<?> rEntity, Class<? extends RObject> rObjectClass, String fieldName) throws ReflectiveOperationException {
|
|
|
|
|
Field field = ClassUtils.getDeclaredField(rEntity, fieldName);
|
|
|
|
|
if (field.isAnnotationPresent(RObjectField.class)) {
|
|
|
|
|
RObjectField anno = field.getAnnotation(RObjectField.class);
|
|
|
|
@ -197,7 +203,18 @@ public class RedissonObjectBuilder {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object fromReference(RedissonClient redisson, RedissonReference rr) throws Exception {
|
|
|
|
|
public Object fromReference(RedissonReference rr) throws ReflectiveOperationException {
|
|
|
|
|
if (redisson != null) {
|
|
|
|
|
return fromReference(redisson, rr);
|
|
|
|
|
} else if (redissonReactive != null) {
|
|
|
|
|
return fromReference(redissonReactive, rr);
|
|
|
|
|
} else if (redissonRx != null) {
|
|
|
|
|
return fromReference(redissonRx, rr);
|
|
|
|
|
}
|
|
|
|
|
throw new IllegalStateException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Object fromReference(RedissonClient redisson, RedissonReference rr) throws ReflectiveOperationException {
|
|
|
|
|
Class<? extends Object> type = rr.getType();
|
|
|
|
|
if (type != null) {
|
|
|
|
|
if (ClassUtils.isAnnotationPresent(type, REntity.class)) {
|
|
|
|
@ -213,8 +230,7 @@ public class RedissonObjectBuilder {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Object getObject(Object redisson, RedissonReference rr, Class<? extends Object> type,
|
|
|
|
|
ReferenceCodecProvider codecProvider)
|
|
|
|
|
throws IllegalAccessException, InvocationTargetException, Exception, ClassNotFoundException {
|
|
|
|
|
ReferenceCodecProvider codecProvider) throws ReflectiveOperationException {
|
|
|
|
|
if (type != null) {
|
|
|
|
|
CodecMethodRef b = REFERENCES.get(type);
|
|
|
|
|
if (b == null && type.getInterfaces().length > 0) {
|
|
|
|
@ -236,7 +252,7 @@ public class RedissonObjectBuilder {
|
|
|
|
|
return rr.getCodec() == null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object fromReference(RedissonRxClient redisson, RedissonReference rr) throws Exception {
|
|
|
|
|
private Object fromReference(RedissonRxClient redisson, RedissonReference rr) throws ReflectiveOperationException {
|
|
|
|
|
Class<? extends Object> type = rr.getReactiveType();
|
|
|
|
|
/**
|
|
|
|
|
* Live Object from reference in reactive client is not supported yet.
|
|
|
|
@ -244,7 +260,7 @@ public class RedissonObjectBuilder {
|
|
|
|
|
return getObject(redisson, rr, type, codecProvider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object fromReference(RedissonReactiveClient redisson, RedissonReference rr) throws Exception {
|
|
|
|
|
private Object fromReference(RedissonReactiveClient redisson, RedissonReference rr) throws ReflectiveOperationException {
|
|
|
|
|
Class<? extends Object> type = rr.getReactiveType();
|
|
|
|
|
/**
|
|
|
|
|
* Live Object from reference in reactive client is not supported yet.
|
|
|
|
@ -294,7 +310,7 @@ public class RedissonObjectBuilder {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <T extends RObject, K extends Codec> T createRObject(RedissonClient redisson, Class<T> expectedType, String name, K codec) throws Exception {
|
|
|
|
|
private <T extends RObject, K extends Codec> T createRObject(RedissonClient redisson, Class<T> expectedType, String name, K codec) throws ReflectiveOperationException {
|
|
|
|
|
List<Class<?>> interfaces = Arrays.asList(expectedType.getInterfaces());
|
|
|
|
|
for (Class<?> iType : interfaces) {
|
|
|
|
|
if (REFERENCES.containsKey(iType)) {// user cache to speed up things a little.
|
|
|
|
|