|
|
|
@ -20,12 +20,14 @@ import java.lang.reflect.Field;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import net.bytebuddy.description.field.FieldDescription;
|
|
|
|
|
import net.bytebuddy.description.field.FieldList;
|
|
|
|
|
import net.bytebuddy.description.method.MethodDescription;
|
|
|
|
|
import net.bytebuddy.description.type.TypeDescription;
|
|
|
|
|
import net.bytebuddy.matcher.ElementMatchers;
|
|
|
|
|
import org.redisson.api.annotation.RId;
|
|
|
|
|
import org.redisson.cache.LRUCacheMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
@ -37,32 +39,6 @@ public class Introspectior {
|
|
|
|
|
return new TypeDescription.ForLoadedType(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MethodDescription getMethodDescription(Class<?> c, String method) {
|
|
|
|
|
if (method == null || method.isEmpty()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return getTypeDescription(c)
|
|
|
|
|
.getDeclaredMethods()
|
|
|
|
|
.filter(ElementMatchers.hasMethodName(method))
|
|
|
|
|
.getOnly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FieldList<FieldDescription.InDefinedShape> getFieldsDescription(Class<?> c) {
|
|
|
|
|
return getTypeDescription(c)
|
|
|
|
|
.getDeclaredFields();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FieldDescription getFieldDescription(Class<?> c, String field) {
|
|
|
|
|
if (field == null || field.isEmpty()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return getTypeDescription(c)
|
|
|
|
|
.getDeclaredFields()
|
|
|
|
|
.filter(ElementMatchers.named(field))
|
|
|
|
|
.getOnly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FieldList<FieldDescription.InDefinedShape> getFieldsWithAnnotation(Class<?> c, Class<? extends Annotation> a) {
|
|
|
|
|
return getAllFields(c)
|
|
|
|
|
.filter(ElementMatchers.isAnnotatedWith(a));
|
|
|
|
@ -75,4 +51,20 @@ public class Introspectior {
|
|
|
|
|
}
|
|
|
|
|
return new FieldList.ForLoadedFields(fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Class<?>, String> ID_FIELD_NAME_CACHE = new LRUCacheMap<>(500, 0, 0);
|
|
|
|
|
|
|
|
|
|
public static String getREntityIdFieldName(Class<?> cls) {
|
|
|
|
|
String name = ID_FIELD_NAME_CACHE.get(cls);
|
|
|
|
|
if (name == null) {
|
|
|
|
|
name = Introspectior
|
|
|
|
|
.getFieldsWithAnnotation(cls, RId.class)
|
|
|
|
|
.getOnly()
|
|
|
|
|
.getName();
|
|
|
|
|
ID_FIELD_NAME_CACHE.put(cls, name);
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|