@Override public OperationSideEffect isMethodSafe(MethodSignature m, TypedValue base, List<TypedValue> args) { if (metamodel.isSafeMethod(m)) { return OperationSideEffect.NONE; } else { // Use reflection to get info about the method (or would it be better // to do this through direct bytecode inspection?) try { Method reflectedMethod = Annotations.asmMethodSignatureToReflectionMethod(m); return Annotations.methodHasSomeAnnotations(reflectedMethod, metamodel.getSafeMethodAnnotations()) ? OperationSideEffect.NONE : OperationSideEffect.UNSAFE; } catch (ClassNotFoundException|NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } return OperationSideEffect.UNSAFE; } }
public static Method asmMethodSignatureToReflectionMethod(MethodSignature m) throws ClassNotFoundException, NoSuchMethodException { Class<?> reflectedClass = Class.forName(m.getOwnerType().getClassName()); Type []argTypes = Type.getMethodType(m.desc).getArgumentTypes(); Class<?> []argClasses = new Class[argTypes.length]; for (int n = 0; n < argTypes.length; n++) argClasses[n] = asmTypeToClass(argTypes[n]); return reflectedClass.getMethod(m.name, argClasses); }
public static <T extends Annotation> T methodFindAnnotation(MethodSignature sig, Class<T> annotation) { try { Method m = asmMethodSignatureToReflectionMethod(sig); return m.getAnnotation(annotation); } catch (ClassNotFoundException | NoSuchMethodException e) { e.printStackTrace(); return null; } } }
.asmMethodSignatureToReflectionMethod(m); && Collection.class.isAssignableFrom(reflectedMethod.getDeclaringClass())) return OperationSideEffect.NONE; if (Annotations.methodHasSomeAnnotations(reflectedMethod, safeMethodAnnotations)) return OperationSideEffect.NONE;
protected ColumnExpressions<?> getAndValidateArg(int argIndex, Type argType) throws TypedValueVisitorException { // Currently, we only support parameters of a few small simple types. // We should also support more complex types (e.g. entities) and allow // fields/methods of those entities to be called in the query (code // motion will be used to push those field accesses or method calls // outside the query where they will be evaluated and then passed in // as a parameter) try { if (!ALLOWED_QUERY_PARAMETER_TYPES.contains(argType) && (Annotations.asmTypeToClass(argType).isPrimitive() || (!metamodel.isKnownEnumType(argType.getInternalName()) && !metamodel.isKnownManagedType(argType.getClassName()) && !metamodel.isKnownConvertedType(argType.getClassName())))) throw new TypedValueVisitorException("Accessing a field with unhandled type: " + Annotations.asmTypeToClass(argType).getName()); } catch (ClassNotFoundException e) { throw new TypedValueVisitorException("Accessing a field with unhandled type", e); } return ColumnExpressions.singleColumn(new SimpleRowReader<>(), new ParameterExpression(lambda.getLambdaIndex(), argIndex)); }
@Override public OperationSideEffect isMethodSafe(MethodSignature m, TypedValue base, List<TypedValue> args) { if (metamodel.isSafeMethod(m)) { return OperationSideEffect.NONE; } else { // Use reflection to get info about the method (or would it be better // to do this through direct bytecode inspection?) try { Method reflectedMethod = Annotations.asmMethodSignatureToReflectionMethod(m); return Annotations.methodHasSomeAnnotations(reflectedMethod, metamodel.getSafeMethodAnnotations()) ? OperationSideEffect.NONE : OperationSideEffect.UNSAFE; } catch (ClassNotFoundException|NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } return OperationSideEffect.UNSAFE; } }
protected JPQLQuery<?> getAndValidateSubQueryArg(int argIndex, Type argType) throws TypedValueVisitorException { // There are a few cases where collections can be passed into a query. try { if (!Collection.class.isAssignableFrom(Annotations.asmTypeToClass(argType))) { throw new TypedValueVisitorException("Using an unhandled type as a subquery parameter"); } } catch (ClassNotFoundException e) { throw new TypedValueVisitorException("Cannot find the class of the object being used as a parameter."); } ParameterAsQuery<?> query = new ParameterAsQuery<>(); query.cols = ColumnExpressions.singleColumn(new SimpleRowReader<>(), new ParameterExpression(lambda.getLambdaIndex(), argIndex)); return query; }
&& (Annotations.asmTypeToClass(argType).isPrimitive() || (!metamodel.isKnownEnumType(argType.getInternalName()) && !metamodel.isKnownManagedType(argType.getClassName()) && !metamodel.isKnownConvertedType(argType.getClassName())))) throw new TypedValueVisitorException("Accessing a field with unhandled type: " + Annotations.asmTypeToClass(argType).getName());