javax.persistence.spi.PersistenceProviderResolver源码实例Demo

类javax.persistence.spi.PersistenceProviderResolver源码实例Demo

下面列出了javax.persistence.spi.PersistenceProviderResolver 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: Persistence.java
/**
 * 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;
}
 
源代码2 项目: lams   文件: Persistence.java
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;
}
 
源代码3 项目: javamelody   文件: JpaPersistence.java
/**
 * 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");
	}
}
 
源代码4 项目: javamelody   文件: JpaPersistence.java
JavaMelodyPersistenceProviderResolver(PersistenceProviderResolver delegate) {
	super();
	this.delegate = delegate;
}
 
源代码5 项目: lams   文件: Persistence.java
/**
 * 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);
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法