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


Java PersistenceProvider.createContainerEntityManagerFactory方法代碼示例

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


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

示例1: getEntityManager

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
private synchronized EntityManager getEntityManager(final PersistenceUnitInfo unit) {
    if (entityManagers.containsKey(unit.getPersistenceUnitName())) {
        return entityManagers.get(unit.getPersistenceUnitName());
    }
    final String providerClassName = unit.getPersistenceProviderClassName();
    try {
        final PersistenceProvider provider = (PersistenceProvider) Class.forName(providerClassName).newInstance();
        final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(unit, new HashMap());
        final EntityManager entityManager = emf.createEntityManager();
        entityManagers.put(unit.getPersistenceUnitName(), entityManager);
        entityManager.getTransaction().begin();
        return entityManager;
    } catch (final IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new TestEEfiException("Failed to load persistence provider class " + providerClassName, e);
    }
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:17,代碼來源:JpaInjectionServicesImpl.java

示例2: createContainerEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo unitInfo, Map properties) {
    if (properties == null) {
        properties = new HashMap<String, Object>();
    } else {
        properties = new HashMap<String, Object>(properties);
    }
    PersistenceProvider nativePersistenceProvider = createNativePersistenceProvider(unitInfo, properties);
    if (nativePersistenceProvider == null) {
        return null;
    }
    EntityManagerFactory nativeFactory
        = nativePersistenceProvider.createContainerEntityManagerFactory(unitInfo, properties);
    List<String> ormXmlLocations = new ArrayList<String>(unitInfo.getMappingFileNames());
    ormXmlLocations.add(DEFAULT_ORM_XML_LOCATION);
    Class<? extends SecurityContext> securityContextType = createSecurityContextType(unitInfo, properties);
    Class<? extends AccessRulesProvider> accessRulesProviderType
        = createAccessRulesProviderType(unitInfo, properties);
    return new SecureEntityManagerFactory(unitInfo.getPersistenceUnitName(),
                                          nativeFactory,
                                          ormXmlLocations,
                                          securityContextType,
                                          accessRulesProviderType);
}
 
開發者ID:ArneLimburg,項目名稱:jpasecurity,代碼行數:25,代碼來源:SecurePersistenceProvider.java

示例3: createContainerEntityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@Override
public EntityManagerFactory createContainerEntityManagerFactory(final PersistenceUnitInfo info,
		final Map map) {
	initJpaCounter();
	final PersistenceProvider persistenceProvider = findDelegate(map);
	// on surcharge PersistenceUnitInfo.getPersistenceProviderClassName()
	// pour retourner le PersistenceProvider délégué et pas nous même
	final PersistenceUnitInfo proxiedInfo = createPersistentUnitInfoProxy(info,
			persistenceProvider);
	final EntityManagerFactory entityManagerFactory = persistenceProvider
			.createContainerEntityManagerFactory(proxiedInfo, map);
	if (entityManagerFactory == null) {
		return null;
	}
	return JpaWrapper.createEntityManagerFactoryProxy(entityManagerFactory);
}
 
開發者ID:javamelody,項目名稱:javamelody,代碼行數:19,代碼來源:JpaPersistence.java

示例4: createAndCloseDummyEMF

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
/**
 * Create and close a dummy EMF to give the PersistenceProvider a chance to call
 * punit.addTransformer(). This has to occur as early as possible as weaving needs
 * to be done before the first entity class is loaded. So we can not wait till the
 * real DataSource is found.
 */
private void createAndCloseDummyEMF(PersistenceProvider provider) {
    DataSource dummyDataSource = new DummyDataSource();
    punit.setJtaDataSource(dummyDataSource);
    punit.setNonJtaDataSource(dummyDataSource);
    try {
        EntityManagerFactory emf = provider.createContainerEntityManagerFactory(punit, null);
        emf.close();
    } catch (Exception e) {
        LOGGER.debug("Error while creating the Dummy EntityManagerFactory to allow weaving.", e);
    }
    punit.setJtaDataSource(null);
    punit.setNonJtaDataSource(null);
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:20,代碼來源:PersistenceProviderTracker.java

示例5: init

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
public void init(Application<? extends ApplicationConfiguration> application) {
	List<PersistenceProvider> providers = getProviders();
	if (providers == null || providers.isEmpty()) {
		throw new MinnalException("No JPA persistence provider found");
	}
	PersistenceProvider provider = providers.get(0);
	PersistenceUnitInfo info = createPersistenceUnitInfo(application.getConfiguration(), provider); 
	factory = provider.createContainerEntityManagerFactory(info, null);
	JPA.instance.addPersistenceUnit(info.getPersistenceUnitName(), factory);
	application.addListener(new JerseyApplicationEventListener(application.getConfiguration().getDatabaseConfiguration()));
}
 
開發者ID:minnal,項目名稱:minnal,代碼行數:12,代碼來源:JPAPlugin.java

示例6: createFactory

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
public static EntityManagerFactory createFactory(PersistenceProvider provider, PersistenceUnitInfo info) {
    Map<String, String> properties = new HashMap<>();
    return provider.createContainerEntityManagerFactory(info, properties);
}
 
開發者ID:arievanwi,項目名稱:osgi.ee,代碼行數:5,代碼來源:PersistenceUnitProcessor.java

示例7: call

import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
@Override
public EntityManagerFactory call() throws Exception {
    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(appClassLoader);
    try {
        final Class<?> clazz = appClassLoader.loadClass(persistenceProviderClassName);
        final PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance();

        // Create entity manager factories with the validator factory
        final Map<String, Object> properties = new HashMap<String, Object>();
        if (!ValidationMode.NONE.equals(unitInfo.getValidationMode())) {
            properties.put("javax.persistence.validation.factory",
                    potentialValidators != null && potentialValidators.size() == 1 ? // optim to avoid lookups
                            ensureSerializable(potentialValidators.values().iterator().next()) :
                            new ValidatorFactoryWrapper(potentialValidators));
        }
        if (cdi && "true".equalsIgnoreCase(unitInfo.getProperties().getProperty("tomee.jpa.cdi", "true"))
                && "true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.jpa.cdi", "true"))) {
            properties.put("javax.persistence.bean.manager",
                    Proxy.newProxyInstance(appClassLoader, new Class<?>[]{BeanManager.class}, new BmHandler()));
        }

        customizeProperties(properties);

        // ensure no tx is there cause a managed connection would fail if the provider setAutocCommit(true) and some hib* have this good idea
        final Transaction transaction;
        if (unitInfo.isLazilyInitialized()) {
            transaction = OpenEJB.getTransactionManager().suspend();
        } else {
            transaction = null;
        }
        final EntityManagerFactory emf;
        try {
            emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, properties);
        } finally {
            if (unitInfo.isLazilyInitialized() && transaction != null) {
                OpenEJB.getTransactionManager().resume(transaction);
            }
        }

        if (unitInfo.getProperties() != null
                && "true".equalsIgnoreCase(unitInfo.getProperties().getProperty(OPENEJB_JPA_INIT_ENTITYMANAGER))
                || SystemInstance.get().getOptions().get(OPENEJB_JPA_INIT_ENTITYMANAGER, false)) {
            emf.createEntityManager().close();
        }

        if (unitInfo.getNonJtaDataSource() != null) {
            final ImportSql importer = new ImportSql(appClassLoader, unitInfo.getPersistenceUnitName(), unitInfo.getNonJtaDataSource());
            if (importer.hasSomethingToImport()) {
                emf.createEntityManager().close(); // to let OpenJPA create the database if configured this way
                importer.doImport();
            }
        }

        return emf;
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:60,代碼來源:EntityManagerFactoryCallable.java


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