Example usage for javax.persistence EntityManager getClass

List of usage examples for javax.persistence EntityManager getClass

Introduction

In this page you can find the example usage for javax.persistence EntityManager getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.cloudfoundry.reconfiguration.spring.AbstractJpaBasedCloudServiceBeanFactoryPostProcessorTest.java

private Object getSession(EntityManager manager) {
    Method method = ReflectionUtils.findMethod(manager.getClass(), "getDelegate");
    return ReflectionUtils.invokeMethod(method, manager);
}

From source file:org.codehaus.grepo.query.jpa.repository.DefaultJpaRepository.java

/**
 * Create a close-suppressing proxy for the given JPA EntityManager.
 *
 * @param em The JPA EntityManager to create a proxy for.
 * @return The EntityManager proxy, implementing all interfaces implemented by the passed-in EntityManager object
 *         (that is, also implementing all provider-specific extension interfaces).
 *///from   w w  w .j  a  v  a2  s .  c om
protected EntityManager createEntityManagerProxy(EntityManager em) {
    Class<?>[] ifcs = null;
    EntityManagerFactory emf = getEntityManagerFactory();
    if (emf instanceof EntityManagerFactoryInfo) {
        Class<?> entityManagerInterface = ((EntityManagerFactoryInfo) emf).getEntityManagerInterface();
        if (entityManagerInterface != null) {
            ifcs = new Class[] { entityManagerInterface };
        }
    }
    if (ifcs == null) {
        ifcs = ClassUtils.getAllInterfacesForClass(em.getClass());
    }
    return (EntityManager) Proxy.newProxyInstance(em.getClass().getClassLoader(), ifcs,
            new CloseSuppressingInvocationHandler(em));
}

From source file:org.springframework.orm.jpa.ExtendedEntityManagerCreator.java

/**
 * Actually create the EntityManager proxy.
 * @param rawEm raw EntityManager/*  w  ww . j av  a 2s. co  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));
}