List of usage examples for org.springframework.util ClassUtils getAllInterfacesForClassAsSet
public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, @Nullable ClassLoader classLoader)
From source file:org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.java
/** * Create a proxy of the given EntityManagerFactory. We do this to be able * to return transaction-aware proxies for application-managed * EntityManagers, and to introduce the NamedEntityManagerFactory interface * @param emf EntityManagerFactory as returned by the persistence provider, * if initialized already// w ww .ja va 2 s .c o m * @return proxy entity manager */ protected EntityManagerFactory createEntityManagerFactoryProxy(@Nullable EntityManagerFactory emf) { Set<Class<?>> ifcs = new LinkedHashSet<>(); Class<?> entityManagerFactoryInterface = this.entityManagerFactoryInterface; if (entityManagerFactoryInterface != null) { ifcs.add(entityManagerFactoryInterface); } else if (emf != null) { ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(emf.getClass(), this.beanClassLoader)); } else { ifcs.add(EntityManagerFactory.class); } ifcs.add(EntityManagerFactoryInfo.class); try { return (EntityManagerFactory) Proxy.newProxyInstance(this.beanClassLoader, ifcs.toArray(new Class<?>[ifcs.size()]), new ManagedEntityManagerFactoryInvocationHandler(this)); } catch (IllegalArgumentException ex) { if (entityManagerFactoryInterface != null) { throw new IllegalStateException("EntityManagerFactory interface [" + entityManagerFactoryInterface + "] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the " + "'entityManagerFactoryInterface' property to plain [javax.persistence.EntityManagerFactory]", ex); } else { throw new IllegalStateException("Conflicting EntityManagerFactory interfaces - " + "consider specifying the 'jpaVendorAdapter' or 'entityManagerFactoryInterface' property " + "to select a specific EntityManagerFactory interface to proceed with", ex); } } }
From source file:org.springframework.orm.jpa.ExtendedEntityManagerCreator.java
/** * Actually create the EntityManager proxy. * @param rawEm raw EntityManager/*www . j a va2 s.c o m*/ * @param emIfc the (potentially vendor-specific) EntityManager * interface to proxy, or {@code null} for default detection of all interfaces * @param cl the ClassLoader to use for proxy creation (maybe {@code null}) * @param exceptionTranslator the PersistenceException translator to use * @param jta whether to create a JTA-aware EntityManager * (or {@code null} if not known in advance) * @param containerManaged whether to follow container-managed EntityManager * or application-managed EntityManager semantics * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return the EntityManager proxy */ private static EntityManager createProxy(EntityManager rawEm, @Nullable Class<? extends EntityManager> emIfc, @Nullable ClassLoader cl, @Nullable PersistenceExceptionTranslator exceptionTranslator, @Nullable Boolean jta, boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(rawEm, "EntityManager must not be null"); Set<Class<?>> ifcs = new LinkedHashSet<>(); if (emIfc != null) { ifcs.add(emIfc); } else { ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(rawEm.getClass(), cl)); } ifcs.add(EntityManagerProxy.class); return (EntityManager) Proxy.newProxyInstance( (cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()), ifcs.toArray(new Class<?>[ifcs.size()]), new ExtendedEntityManagerInvocationHandler(rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction)); }