Example usage for javax.persistence EntityManagerFactory getClass

List of usage examples for javax.persistence EntityManagerFactory getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.compass.gps.device.jpa.entities.DatanucleusJpaEntitiesLocator.java

private static JDOPersistenceManagerFactory extractPMF(EntityManagerFactory emf) {
    Class pmfHolderClass = emf.getClass();
    while (!pmfHolderClass.getName().equals(EntityManagerFactoryImpl.class.getName())) {
        pmfHolderClass = pmfHolderClass.getSuperclass();
        if (pmfHolderClass == Object.class) {
            throw new IllegalStateException("Failed to find PMF from [" + emf.getClass() + "], no ["
                    + EntityManagerFactoryImpl.class.getName() + "] found");
        }/* www .j  a va  2  s .com*/
    }
    try {
        Field field = pmfHolderClass.getDeclaredField("pmf");
        field.setAccessible(true);
        return (JDOPersistenceManagerFactory) field.get(emf);
    } catch (NoSuchFieldException e) {
        throw new IllegalStateException("Failed to extract PMF from [" + emf.getClass() + "], no field [pmf]");
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Failed to extract PMF from [" + emf.getClass() + "], illegal access");
    }
}

From source file:org.compass.gps.device.jpa.extractor.NativeJpaHelper.java

public static <T> T detectNativeJpa(EntityManagerFactory emf, NativeJpaCallback<T> callback)
        throws JpaGpsDeviceException {
    EntityManagerFactory nativeEmf = extractNativeJpa(emf);

    Set interfaces = ClassUtils.getAllInterfacesAsSet(nativeEmf);
    Set<String> interfacesAsStrings = new HashSet<String>();
    for (Object anInterface : interfaces) {
        interfacesAsStrings.add(((Class) anInterface).getName());
    }// ww  w  .  ja  va  2  s .c  o m

    Class clazz = nativeEmf.getClass();
    while (clazz != Object.class) {
        interfacesAsStrings.add(clazz.getName());
        clazz = clazz.getSuperclass();
    }

    T retVal;
    if (interfacesAsStrings.contains("org.hibernate.ejb.HibernateEntityManagerFactory")) {
        retVal = callback.onHibernate();
    } else if (interfacesAsStrings
            .contains("oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl")) {
        retVal = callback.onTopLinkEssentials();
    } else if (interfacesAsStrings.contains("org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl")) {
        retVal = callback.onEclipseLink();
    } else if (interfacesAsStrings.contains("org.apache.openjpa.persistence.OpenJPAEntityManagerFactory")) {
        retVal = callback.onOpenJPA();
    } else if (interfacesAsStrings.contains("org.datanucleus.jpa.EntityManagerFactoryImpl")) {
        retVal = callback.onDatanucleus();
    } else {
        retVal = callback.onUnknown();
    }
    return retVal;
}

From source file:org.eclipse.skalli.services.persistence.EntityManagerServiceBase.java

private EntityManager createEntityManager(EntityManagerFactory entityManagerFactory) throws StorageException {
    try {//  www.  ja  va2s.c o  m
        return entityManagerFactory.createEntityManager();
    } catch (IllegalStateException e) {
        throw new StorageException(MessageFormat.format("Failed to create an entity manager using factory {0}",
                entityManagerFactory.getClass()), e);
    }
}

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  w w.j a  v  a 2  s .co 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);
        }
    }
}