Package graphql.schema
Class PropertyFetchingImpl
- java.lang.Object
-
- graphql.schema.PropertyFetchingImpl
-
public class PropertyFetchingImpl extends java.lang.Object
A re-usable class that can fetch from POJOs
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PropertyFetchingImpl.CachedLambdaFunction
private class
PropertyFetchingImpl.CachedMethod
private static class
PropertyFetchingImpl.CacheKey
private static class
PropertyFetchingImpl.FastNoSuchMethodException
private static interface
PropertyFetchingImpl.MethodFinder
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,java.lang.reflect.Field>
FIELD_CACHE
private java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,PropertyFetchingImpl.CachedLambdaFunction>
LAMBDA_CACHE
private static org.slf4j.Logger
log
private java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,PropertyFetchingImpl.CachedMethod>
METHOD_CACHE
private java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,PropertyFetchingImpl.CacheKey>
NEGATIVE_CACHE
private java.lang.Class<?>
singleArgumentType
private java.util.concurrent.atomic.AtomicBoolean
USE_LAMBDA_FACTORY
private java.util.concurrent.atomic.AtomicBoolean
USE_NEGATIVE_CACHE
private java.util.concurrent.atomic.AtomicBoolean
USE_SET_ACCESSIBLE
-
Constructor Summary
Constructors Constructor Description PropertyFetchingImpl(java.lang.Class<?> singleArgumentType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearReflectionCache()
private java.lang.reflect.Method
findPubliclyAccessibleMethod(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Class<?> rootClass, java.lang.String methodName, boolean dfeInUse, boolean allowStaticMethods)
Invoking public methods on package-protected classes via reflection causes exceptions.private java.lang.reflect.Method
findRecordMethod(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Class<?> rootClass, java.lang.String methodName)
private java.lang.reflect.Method
findViaSetAccessible(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Class<?> aClass, java.lang.String methodName, boolean dfeInUse)
java.lang.Object
getPropertyValue(java.lang.String propertyName, java.lang.Object object, GraphQLType graphQLType, boolean dfeInUse, java.util.function.Supplier<java.lang.Object> singleArgumentValue)
private java.lang.Object
getPropertyViaFieldAccess(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Object object, java.lang.String propertyName)
private java.lang.Object
getPropertyViaGetterMethod(java.lang.Object object, java.lang.String propertyName, GraphQLType graphQLType, PropertyFetchingImpl.MethodFinder methodFinder, java.util.function.Supplier<java.lang.Object> singleArgumentValue)
private java.lang.Object
getPropertyViaGetterUsingPrefix(java.lang.Object object, java.lang.String propertyName, java.lang.String prefix, PropertyFetchingImpl.MethodFinder methodFinder, java.util.function.Supplier<java.lang.Object> singleArgumentValue)
private java.lang.Object
getPropertyViaRecordMethod(java.lang.Object object, java.lang.String propertyName, PropertyFetchingImpl.MethodFinder methodFinder, java.util.function.Supplier<java.lang.Object> singleArgumentValue)
private boolean
hasZeroArgs(java.lang.reflect.Method mth)
private java.lang.Object
invokeField(java.lang.Object object, java.lang.reflect.Field field)
private java.lang.Object
invokeMethod(java.lang.Object object, java.util.function.Supplier<java.lang.Object> singleArgumentValue, java.lang.reflect.Method method, boolean takesSingleArgument)
private boolean
isBooleanProperty(GraphQLType graphQLType)
private boolean
isNegativelyCached(PropertyFetchingImpl.CacheKey key)
private boolean
isSuitablePublicMethod(java.lang.reflect.Method method, boolean allowStaticMethods)
private java.util.Optional<java.util.function.Function<java.lang.Object,java.lang.Object>>
lambdaGetter(java.lang.String propertyName, java.lang.Object object)
private PropertyFetchingImpl.CacheKey
mkCacheKey(java.lang.Object object, java.lang.String propertyName)
private static java.util.Comparator<? super java.lang.reflect.Method>
mostMethodArgsFirst()
private void
putInNegativeCache(PropertyFetchingImpl.CacheKey key)
boolean
setUseLambdaFactory(boolean flag)
boolean
setUseNegativeCache(boolean flag)
boolean
setUseSetAccessible(boolean flag)
private boolean
takesSingleArgumentTypeAsOnlyArgument(java.lang.reflect.Method mth)
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
USE_SET_ACCESSIBLE
private final java.util.concurrent.atomic.AtomicBoolean USE_SET_ACCESSIBLE
-
USE_LAMBDA_FACTORY
private final java.util.concurrent.atomic.AtomicBoolean USE_LAMBDA_FACTORY
-
USE_NEGATIVE_CACHE
private final java.util.concurrent.atomic.AtomicBoolean USE_NEGATIVE_CACHE
-
LAMBDA_CACHE
private final java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,PropertyFetchingImpl.CachedLambdaFunction> LAMBDA_CACHE
-
METHOD_CACHE
private final java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,PropertyFetchingImpl.CachedMethod> METHOD_CACHE
-
FIELD_CACHE
private final java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,java.lang.reflect.Field> FIELD_CACHE
-
NEGATIVE_CACHE
private final java.util.concurrent.ConcurrentMap<PropertyFetchingImpl.CacheKey,PropertyFetchingImpl.CacheKey> NEGATIVE_CACHE
-
singleArgumentType
private final java.lang.Class<?> singleArgumentType
-
-
Method Detail
-
getPropertyValue
public java.lang.Object getPropertyValue(java.lang.String propertyName, java.lang.Object object, GraphQLType graphQLType, boolean dfeInUse, java.util.function.Supplier<java.lang.Object> singleArgumentValue)
-
lambdaGetter
private java.util.Optional<java.util.function.Function<java.lang.Object,java.lang.Object>> lambdaGetter(java.lang.String propertyName, java.lang.Object object)
-
isNegativelyCached
private boolean isNegativelyCached(PropertyFetchingImpl.CacheKey key)
-
putInNegativeCache
private void putInNegativeCache(PropertyFetchingImpl.CacheKey key)
-
getPropertyViaRecordMethod
private java.lang.Object getPropertyViaRecordMethod(java.lang.Object object, java.lang.String propertyName, PropertyFetchingImpl.MethodFinder methodFinder, java.util.function.Supplier<java.lang.Object> singleArgumentValue) throws java.lang.NoSuchMethodException
- Throws:
java.lang.NoSuchMethodException
-
getPropertyViaGetterMethod
private java.lang.Object getPropertyViaGetterMethod(java.lang.Object object, java.lang.String propertyName, GraphQLType graphQLType, PropertyFetchingImpl.MethodFinder methodFinder, java.util.function.Supplier<java.lang.Object> singleArgumentValue) throws java.lang.NoSuchMethodException
- Throws:
java.lang.NoSuchMethodException
-
getPropertyViaGetterUsingPrefix
private java.lang.Object getPropertyViaGetterUsingPrefix(java.lang.Object object, java.lang.String propertyName, java.lang.String prefix, PropertyFetchingImpl.MethodFinder methodFinder, java.util.function.Supplier<java.lang.Object> singleArgumentValue) throws java.lang.NoSuchMethodException
- Throws:
java.lang.NoSuchMethodException
-
findPubliclyAccessibleMethod
private java.lang.reflect.Method findPubliclyAccessibleMethod(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Class<?> rootClass, java.lang.String methodName, boolean dfeInUse, boolean allowStaticMethods) throws java.lang.NoSuchMethodException
Invoking public methods on package-protected classes via reflection causes exceptions. This method searches a class's hierarchy for public visibility parent classes with the desired getter. This particular case is required to support AutoValue style data classes, which have abstract public interfaces implemented by package-protected (generated) subclasses.- Throws:
java.lang.NoSuchMethodException
-
isSuitablePublicMethod
private boolean isSuitablePublicMethod(java.lang.reflect.Method method, boolean allowStaticMethods)
-
findRecordMethod
private java.lang.reflect.Method findRecordMethod(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Class<?> rootClass, java.lang.String methodName) throws java.lang.NoSuchMethodException
- Throws:
java.lang.NoSuchMethodException
-
findViaSetAccessible
private java.lang.reflect.Method findViaSetAccessible(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Class<?> aClass, java.lang.String methodName, boolean dfeInUse) throws java.lang.NoSuchMethodException
- Throws:
java.lang.NoSuchMethodException
-
getPropertyViaFieldAccess
private java.lang.Object getPropertyViaFieldAccess(PropertyFetchingImpl.CacheKey cacheKey, java.lang.Object object, java.lang.String propertyName) throws PropertyFetchingImpl.FastNoSuchMethodException
-
invokeMethod
private java.lang.Object invokeMethod(java.lang.Object object, java.util.function.Supplier<java.lang.Object> singleArgumentValue, java.lang.reflect.Method method, boolean takesSingleArgument) throws PropertyFetchingImpl.FastNoSuchMethodException
-
invokeField
private java.lang.Object invokeField(java.lang.Object object, java.lang.reflect.Field field)
-
isBooleanProperty
private boolean isBooleanProperty(GraphQLType graphQLType)
-
clearReflectionCache
public void clearReflectionCache()
-
setUseSetAccessible
public boolean setUseSetAccessible(boolean flag)
-
setUseLambdaFactory
public boolean setUseLambdaFactory(boolean flag)
-
setUseNegativeCache
public boolean setUseNegativeCache(boolean flag)
-
mkCacheKey
private PropertyFetchingImpl.CacheKey mkCacheKey(java.lang.Object object, java.lang.String propertyName)
-
hasZeroArgs
private boolean hasZeroArgs(java.lang.reflect.Method mth)
-
takesSingleArgumentTypeAsOnlyArgument
private boolean takesSingleArgumentTypeAsOnlyArgument(java.lang.reflect.Method mth)
-
mostMethodArgsFirst
private static java.util.Comparator<? super java.lang.reflect.Method> mostMethodArgsFirst()
-
-