@SuppressWarnings("unchecked") @Test public void test() { TransactionalMethodMatcher matcher = new TransactionalMethodMatcher(); for (Class<?> cl : Arrays.asList(ServiceA.class, ServiceB.class, ServiceBImpl.class, ServiceC.class)) { System.out.println(cl.getSimpleName()); for (Method m : cl.getMethods()) { if (m.getName().toLowerCase().contains("tx")) { boolean matched = matcher.matches(m); System.out.println(" " + m.getName() + " : " + matched); assertEquals(m.getName() + "failed", matched, m.getName().toLowerCase().startsWith("tx")); } } System.out.println(); } }
@Override public boolean matches(Method method) { if (method.getAnnotation(NotTransactional.class) != null) { return false; } else if (method.getAnnotation(Transactional.class) != null) { return handle(method, method.getAnnotation(Transactional.class)); } else if (method.getDeclaringClass().getAnnotation(Transactional.class) != null) { return handle(method, method.getDeclaringClass().getAnnotation(Transactional.class)); } for (Class<?> iface : method.getDeclaringClass().getInterfaces()) { if (iface.getAnnotation(Transactional.class) != null) { return handle(method, iface.getAnnotation(Transactional.class)); } else { for (Method m : iface.getMethods()) { if (m.getName().equals(method.getName()) && m.getAnnotation(Transactional.class) != null && equals(m.getParameterTypes(), method.getParameterTypes())) { return handle(method, m.getAnnotation(Transactional.class)); } } } } return false; }
TransactionalMethodMatcher extends AbstractMatcher<Method> implements Provider<Map<Method, Transactional>> { @Override public boolean matches(Method method) { if (method.getAnnotation(NotTransactional.class) != null) { return false; } else if (method.getAnnotation(Transactional.class) != null) { return handle(method, method.getAnnotation(Transactional.class)); } else if (method.getDeclaringClass().getAnnotation(Transactional.class) != null) { return handle(method, method.getDeclaringClass().getAnnotation(Transactional.class)); } for (Class<?> iface : method.getDeclaringClass().getInterfaces()) { if (iface.getAnnotation(Transactional.class) != null) { return handle(method, iface.getAnnotation(Transactional.class)); } else { for (Method m : iface.getMethods()) { if (m.getName().equals(method.getName()) && m.getAnnotation(Transactional.class) != null && equals(m.getParameterTypes(), method.getParameterTypes())) { return handle(method, m.getAnnotation(Transactional.class)); } } } } return false; } }
TransactionalMethodMatcher extends AbstractMatcher<Method> implements Provider<Map<Method, Transactional>> { @Override public boolean matches(Method method) { if (method.getAnnotation(NotTransactional.class) != null) { return false; } else if (method.getAnnotation(Transactional.class) != null) { return handle(method, method.getAnnotation(Transactional.class)); } else if (method.getDeclaringClass().getAnnotation(Transactional.class) != null) { return handle(method, method.getDeclaringClass().getAnnotation(Transactional.class)); } for (Class<?> iface : method.getDeclaringClass().getInterfaces()) { if (iface.getAnnotation(Transactional.class) != null) { return handle(method, iface.getAnnotation(Transactional.class)); } else { for (Method m : iface.getMethods()) { if (m.getName().equals(method.getName()) && m.getAnnotation(Transactional.class) != null && equals(m.getParameterTypes(), method.getParameterTypes())) { return handle(method, m.getAnnotation(Transactional.class)); } } } } return false; }  }
TransactionalMethodMatcher extends AbstractMatcher<Method> implements Provider<Map<Method, Transactional>> { @Override public boolean matches(Method method) { if (method.getAnnotation(NotTransactional.class) != null) { return false; } else if (method.getAnnotation(Transactional.class) != null) { return handle(method, method.getAnnotation(Transactional.class)); } else if (method.getDeclaringClass().getAnnotation(Transactional.class) != null) { return handle(method, method.getDeclaringClass().getAnnotation(Transactional.class)); } for (Class<?> iface : method.getDeclaringClass().getInterfaces()) { if (iface.getAnnotation(Transactional.class) != null) { return handle(method, iface.getAnnotation(Transactional.class)); } else { for (Method m : iface.getMethods()) { if (m.getName().equals(method.getName()) && m.getAnnotation(Transactional.class) != null && equals(m.getParameterTypes(), method.getParameterTypes())) { return handle(method, m.getAnnotation(Transactional.class)); } } } } return false; }  @Override boolean matches(Method method); @Override Map<Method, Transactional> get(); }
TransactionalMethodMatcher extends AbstractMatcher<Method> implements Provider<Map<Method, Transactional>> { @Override public boolean matches(Method method) { if (method.getAnnotation(NotTransactional.class) != null) { return false; } else if (method.getAnnotation(Transactional.class) != null) { return handle(method, method.getAnnotation(Transactional.class)); } else if (method.getDeclaringClass().getAnnotation(Transactional.class) != null) { return handle(method, method.getDeclaringClass().getAnnotation(Transactional.class)); } for (Class<?> iface : method.getDeclaringClass().getInterfaces()) { if (iface.getAnnotation(Transactional.class) != null) { return handle(method, iface.getAnnotation(Transactional.class)); } else { for (Method m : iface.getMethods()) { if (m.getName().equals(method.getName()) && m.getAnnotation(Transactional.class) != null && equals(m.getParameterTypes(), method.getParameterTypes())) { return handle(method, m.getAnnotation(Transactional.class)); } } } } return false; }  @Override boolean matches(Method method); @Override Map<Method, Transactional> get();  }