當前位置: 首頁>>代碼示例>>Java>>正文


Java PersistenceProvider.createEntityManagerFactory方法代碼示例

本文整理匯總了Java中javax.persistence.spi.PersistenceProvider.createEntityManagerFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceProvider.createEntityManagerFactory方法的具體用法?Java PersistenceProvider.createEntityManagerFactory怎麽用?Java PersistenceProvider.createEntityManagerFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.persistence.spi.PersistenceProvider的用法示例。


在下文中一共展示了PersistenceProvider.createEntityManagerFactory方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createNativeEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
/**
 * Initialize the EntityManagerFactory for the given configuration.
 * @throws javax.persistence.PersistenceException in case of JPA initialization errors
 */
@Override
protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException {
	if (logger.isInfoEnabled()) {
		logger.info("Building JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'");
	}
	PersistenceProvider provider = getPersistenceProvider();
	if (provider != null) {
		// Create EntityManagerFactory directly through PersistenceProvider.
		EntityManagerFactory emf = provider.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap());
		if (emf == null) {
			throw new IllegalStateException(
					"PersistenceProvider [" + provider + "] did not return an EntityManagerFactory for name '" +
					getPersistenceUnitName() + "'");
		}
		return emf;
	}
	else {
		// Let JPA perform its standard PersistenceProvider autodetection.
		return Persistence.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:LocalEntityManagerFactoryBean.java

示例2: createEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
    
	EntityManagerFactory emf = null;
    List<PersistenceProvider> providers = getProviders();
    PersistenceProvider defaultProvider = null;
    for (PersistenceProvider provider : providers) {
        if (provider instanceof HibernatePersistence) {
            defaultProvider = provider;
            continue;
        }
        emf = provider.createEntityManagerFactory(persistenceUnitName, properties);
        if (emf != null) {
            break;
        }
    }
    if (emf == null && defaultProvider != null)
        emf = defaultProvider.createEntityManagerFactory( persistenceUnitName, properties );
    if ( emf == null ) {
        throw new PersistenceException( "No Persistence provider for EntityManager named " + persistenceUnitName );
    }
    return emf;
}
 
開發者ID:intercommit,項目名稱:hibhik,代碼行數:23,代碼來源:CustomPersistence.java

示例3: getEmf

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
public EntityManagerFactory getEmf()
{
    Bundle thisBundle = FrameworkUtil.getBundle( EmfUtil.class );
    BundleContext context = thisBundle.getBundleContext();
    ServiceReference[] refs = null;
    try
    {
        refs = context.getServiceReferences( EntityManagerFactory.class.getName(),
                "(osgi.unit.name=pluginsPUnit)" );
    }
    catch ( Exception isEx )
    {
        throw new IllegalStateException( "Filter error", isEx );
    }
    if ( refs != null )
    {
        emf = ( EntityManagerFactory ) context.getService( refs[0] );
    }
    if ( emf == null )
    {


        ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() );
        PersistenceProvider persistenceProvider = ( PersistenceProvider ) context.getService( serviceReference );

        emf = persistenceProvider.createEntityManagerFactory( "pluginsPUnit", null );
    }
    return emf;
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:30,代碼來源:EmfUtil.java

示例4: createEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@Override
public EntityManagerFactory createEntityManagerFactory(final String unit, final Map map) {
	initJpaCounter();
	final PersistenceProvider persistenceProvider = findDelegate(map);
	final ClassLoader tccl = tccl();

	final ClassLoader hack = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // pour findbugs
		/** {@inheritDoc} */
		@Override
		public ClassLoader run() {
			return new JpaOverridePersistenceXmlClassLoader(tccl,
					persistenceProvider.getClass().getName());
		}
	});

	Thread.currentThread().setContextClassLoader(hack);
	try {
		final EntityManagerFactory entityManagerFactory = persistenceProvider
				.createEntityManagerFactory(unit, map);
		if (entityManagerFactory == null) {
			return null;
		}
		return JpaWrapper.createEntityManagerFactoryProxy(entityManagerFactory);
	} finally {
		Thread.currentThread().setContextClassLoader(tccl);
	}
}
 
開發者ID:javamelody,項目名稱:javamelody,代碼行數:30,代碼來源:JpaPersistence.java

示例5: entityManagerFactoryMySQL

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
@Produces
@ApplicationScoped
@Default
@Startup
public EntityManagerFactory entityManagerFactoryMySQL(@InjectableProperties(file = "jpa-mysql") Map<String, String> properties) {
    PersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
    return persistenceProvider.createEntityManagerFactory("MySQL", properties);
}
 
開發者ID:gabfssilva,項目名稱:deltaspike-jpa-jsf,代碼行數:9,代碼來源:DefaultProducer.java

示例6: getEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
private EntityManagerFactory getEntityManagerFactory() {
	if ( emf == null ) {
		Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class );
		// Could get this by wiring up OsgiTestBundleActivator as well.
		BundleContext context = thisBundle.getBundleContext();

		ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() );
		PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService( serviceReference );

		emf = persistenceProvider.createEntityManagerFactory( "unmanaged-jpa", null );
	}
	return emf;
}
 
開發者ID:hibernate,項目名稱:hibernate-demos,代碼行數:14,代碼來源:HibernateUtil.java

示例7: getEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
private static EntityManagerFactory getEntityManagerFactory() {
	if ( emf == null ) {
		Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class );
		// Could get this by wiring up OsgiTestBundleActivator as well.
		BundleContext context = thisBundle.getBundleContext();

		ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() );
		PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService( serviceReference );

		emf = persistenceProvider.createEntityManagerFactory( "unmanaged-jpa", null );
	}
	return emf;
}
 
開發者ID:kelvinst,項目名稱:hibernate-tutorials,代碼行數:14,代碼來源:HibernateUtil.java


注:本文中的javax.persistence.spi.PersistenceProvider.createEntityManagerFactory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。