/** * Checks if the given class contains a method with the same signature. * * @param targetClass The class to check * @param method The source method * @return if it contains a method with the same signature. */ public static boolean containsMethod(Class<?> targetClass, Method method) { return extractMethod(targetClass, method) != null; }
/** * Checks if the given class contains a method with the same signature. * * @param targetClass The class to check * @param method The source method * @return if it contains a method with the same signature. */ public static boolean containsMethod(Class<?> targetClass, Method method) { return extractMethod(targetClass, method) != null; }
/** * Extracts a method matching the source method, allowing generic type parameters to be substituted as * long as they are properly castable. * * @param clazz The target class * @param sourceMethod The source method. * @return the extracted method or <code>null</code> */ public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod) { Method exactMethod = extractMethod(clazz, sourceMethod); if (exactMethod == null) { String methodName = sourceMethod.getName(); Class<?>[] parameterTypes = sourceMethod.getParameterTypes(); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && allSameType(method.getParameterTypes(), parameterTypes)) { return method; } } return null; } else { return exactMethod; } }
/** * Extracts a method matching the source method, allowing generic type parameters to be substituted as * long as they are properly castable. * * @param clazz The target class * @param sourceMethod The source method. * @return the extracted method or <code>null</code> */ public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod) { Method exactMethod = extractMethod(clazz, sourceMethod); if (exactMethod == null) { String methodName = sourceMethod.getName(); Class<?>[] parameterTypes = sourceMethod.getParameterTypes(); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && allSameType(method.getParameterTypes(), parameterTypes)) { return method; } } return null; } else { return exactMethod; } }
private boolean needsTransaction(EntityViewCdiQueryInvocationContext context) { boolean requiresTx = false; Method method = context.getMethod(); if (ClassUtils.containsMethod(EntityRepositoryHandler.class, method)) { Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, method); requiresTx = executed.isAnnotationPresent(RequiresTransaction.class); } return requiresTx || context.getRepositoryMethod().requiresTransaction(); } }
private boolean needsTransaction(EntityViewCdiQueryInvocationContext context) { boolean requiresTx = false; Method method = context.getMethod(); if (ClassUtils.containsMethod(EntityRepositoryHandler.class, method)) { Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, method); requiresTx = executed.isAnnotationPresent(RequiresTransaction.class); } return requiresTx || context.getRepositoryMethod().requiresTransaction(); } }
private boolean needsTransaction(EntityViewCdiQueryInvocationContext context) { boolean requiresTx = false; Method method = context.getMethod(); if (ClassUtils.containsMethod(EntityRepositoryHandler.class, method)) { Method executed = ClassUtils.extractMethod(EntityRepositoryHandler.class, method); requiresTx = executed.isAnnotationPresent(RequiresTransaction.class); } return requiresTx || context.getRepositoryMethod().requiresTransaction(); } }
private void initRequiresTransaction(RepositoryMethodMetadata repositoryMethodMetadata) { boolean requiresTransaction = false; if (ClassUtils.containsMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod())) { Method originalMethod = ClassUtils.extractMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod()); if (originalMethod.isAnnotationPresent(RequiresTransaction.class)) { requiresTransaction = true; } } Query query = repositoryMethodMetadata.getQuery(); Modifying modifying = repositoryMethodMetadata.getModifying(); if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying != null) { requiresTransaction = true; } repositoryMethodMetadata.setRequiresTransaction(requiresTransaction); } }
private void initRequiresTransaction(RepositoryMethodMetadata repositoryMethodMetadata) { boolean requiresTransaction = false; if (ClassUtils.containsMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod())) { Method originalMethod = ClassUtils.extractMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod()); if (originalMethod.isAnnotationPresent(RequiresTransaction.class)) { requiresTransaction = true; } } Query query = repositoryMethodMetadata.getQuery(); Modifying modifying = repositoryMethodMetadata.getModifying(); if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying != null) { requiresTransaction = true; } repositoryMethodMetadata.setRequiresTransaction(requiresTransaction); } }
private void initRequiresTransaction(RepositoryMethodMetadata repositoryMethodMetadata) { boolean requiresTransaction = false; if (ClassUtils.containsMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod())) { Method originalMethod = ClassUtils.extractMethod(EntityRepositoryHandler.class, repositoryMethodMetadata.getMethod()); if (originalMethod.isAnnotationPresent(RequiresTransaction.class)) { requiresTransaction = true; } } Query query = repositoryMethodMetadata.getQuery(); Modifying modifying = repositoryMethodMetadata.getModifying(); if ((query != null && !query.lock().equals(LockModeType.NONE)) || modifying != null) { requiresTransaction = true; } repositoryMethodMetadata.setRequiresTransaction(requiresTransaction); } }