javax.persistence.spi.PersistenceProviderResolver Java Examples

The following examples show how to use javax.persistence.spi.PersistenceProviderResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Persistence.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create and return an EntityManagerFactory for the named persistence unit
 * using the given properties.
 * 
 * @param persistenceUnitName
 *            the name of the persistence unit
 * @param properties
 *            Additional properties to use when creating the factory. 
 *            These properties may include properties to control
 *            schema generation.  The values of these properties override 
 *            any values that may have been configured elsewhere.
 * @return the factory that creates EntityManagers configured according to
 *         the specified persistence unit.
 */
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {

    EntityManagerFactory emf = null;
    PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();

    List<PersistenceProvider> providers = resolver.getPersistenceProviders();

    for (PersistenceProvider provider : providers) {
        emf = provider.createEntityManagerFactory(persistenceUnitName, properties);
        if (emf != null) {
            break;
        }
    }
    if (emf == null) {
        throw new PersistenceException("No Persistence provider for EntityManager named " + persistenceUnitName);
    }
    return emf;
}
 
Example #2
Source File: Persistence.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public boolean isLoaded(Object entity) {
    PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();

    List<PersistenceProvider> providers = resolver.getPersistenceProviders();

    for (PersistenceProvider provider : providers) {
        LoadState loadstate = provider.getProviderUtil().isLoaded(entity);
        if(loadstate == LoadState.LOADED) {
            return true;
        } else if (loadstate == LoadState.NOT_LOADED) {
            return false;
        } // else continue
    }
    //None of the providers could determine the load state
    return true;
}
 
Example #3
Source File: JpaPersistence.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Active le monitoring JPA par défaut,
 * même si <provider>net.bull.javamelody.JpaPersistence</provider> n'est pas dans META-INF/persistence.xml
 */
public static void initPersistenceProviderResolver() {
	try {
		PersistenceProviderResolver resolver = PersistenceProviderResolverHolder
				.getPersistenceProviderResolver();
		if (!(resolver instanceof JavaMelodyPersistenceProviderResolver)) {
			resolver = new JavaMelodyPersistenceProviderResolver(resolver);
			PersistenceProviderResolverHolder.setPersistenceProviderResolver(resolver);
			LOG.debug("JPA persistence provider resolver initialized");
		}
	} catch (final Throwable t) { // NOPMD
		LOG.info("initialization of jpa persistence provider resolver failed, skipping");
	}
}
 
Example #4
Source File: JpaPersistence.java    From javamelody with Apache License 2.0 4 votes vote down vote up
JavaMelodyPersistenceProviderResolver(PersistenceProviderResolver delegate) {
	super();
	this.delegate = delegate;
}
 
Example #5
Source File: Persistence.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create database schemas and/or tables and/or create DDL
 * scripts as determined by the supplied properties.
 * <p>
 * Called when schema generation is to occur as a separate phase
 * from creation of the entity manager factory.
 * <p>
 * @param persistenceUnitName the name of the persistence unit
 * @param map properties for schema generation;  these may
 *             also contain provider-specific properties.  The
 *             value of these properties override any values that
 *             may have been configured elsewhere..             
 * @throws PersistenceException if insufficient or inconsistent
 *         configuration information is provided or if schema
 *         generation otherwise fails.
 *
 * @since Java Persistence 2.1
 */
public static void generateSchema(String persistenceUnitName, Map map) {
    PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();
    List<PersistenceProvider> providers = resolver.getPersistenceProviders();
    
    for (PersistenceProvider provider : providers) {
        if (provider.generateSchema(persistenceUnitName, map)) {
            return;
        }
    }
    
    throw new PersistenceException("No Persistence provider to generate schema named " + persistenceUnitName);
}