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


Java PersistenceProvider類代碼示例

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


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

示例1: fixDeprecatedHibernateWarning

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
/**
 * fixes the warning (Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb
 * .HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.)
 *
 * must be called before getting the EntityManagerFactory
 */
private static void fixDeprecatedHibernateWarning() {
    PersistenceProviderResolverHolder.setPersistenceProviderResolver(new PersistenceProviderResolver() {
        private final List<PersistenceProvider> providers_ =
                Arrays.asList(new PersistenceProvider[]{new HibernatePersistenceProvider()});

        @Override
        public List<PersistenceProvider> getPersistenceProviders() {
            return providers_;
        }

        @Override
        public void clearCachedProviders() {

        }
    });
}
 
開發者ID:sothawo,項目名稱:trakxmap,代碼行數:23,代碼來源:DB.java

示例2: setUp

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    URL persistenceProviderUrl = FileUtil.getArchiveRoot(PersistenceProvider.class.getProtectionDomain().getCodeSource().getLocation());
    ProtectionDomain domain = Resource.class.getProtectionDomain();
    System.out.println("Protection domain: " + domain);
    CodeSource source = domain.getCodeSource();
    System.out.println("Code source: " + source);
    if (source != null) {
        URL location = source.getLocation();
        System.out.println("Location: " + location);
        URL resourceUrl = FileUtil.getArchiveRoot(location);
        addCompileRoots(Arrays.asList(persistenceProviderUrl, resourceUrl));
    } else {
        addCompileRoots(Arrays.asList(persistenceProviderUrl));
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:PersistenceTestCase.java

示例3: 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

示例4: createFilter

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
private static Filter createFilter(BundleContext context, PersistenceUnit punit) {
    String filter;
    if (punit.getPersistenceProviderClassName() != null) {
        filter = String.format("(&(objectClass=%s)(%s=%s))",
                               PersistenceProvider.class.getName(),
                               JAVAX_PERSISTENCE_PROVIDER,
                               punit.getPersistenceProviderClassName());
    } else {
        filter = String.format("(objectClass=%s)", PersistenceProvider.class.getName());
    }

    try {
        return context.createFilter(filter);
    } catch (InvalidSyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:18,代碼來源:PersistenceProviderTracker.java

示例5: addingService

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
@Override
public StoredPerProvider addingService(ServiceReference<PersistenceProvider> reference) {
    String providerName = (String)reference.getProperty(JAVAX_PERSISTENCE_PROVIDER);
    // FIXME should be set when creating the EMF was successful
    if (punit.getPersistenceProviderClassName() == null) {
        punit.setProviderClassName(providerName);
    }
    StoredPerProvider stored = new StoredPerProvider();
    LOGGER.info("Found provider for " + punit.getPersistenceUnitName() + " " + punit.getPersistenceProviderClassName());
    
    PersistenceProvider provider = context.getService(reference);

    createAndCloseDummyEMF(provider);

    stored.builder = new AriesEntityManagerFactoryBuilder(context, provider, reference.getBundle(), punit);
    Dictionary<String, ?> props = AriesEntityManagerFactoryBuilder.createBuilderProperties(punit, punit.getBundle());
    stored.reg = context.registerService(EntityManagerFactoryBuilder.class, stored.builder , props);
    return stored;
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:20,代碼來源:PersistenceProviderTracker.java

示例6: createDataSourceTracker

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
private ServiceTracker<?, ?> createDataSourceTracker(PersistenceProvider provider) {
     if (usesDataSource()) {
     	synchronized (this) {
	driver = "Pre Configured DataSource";
}
         if (!usesDataSourceService()) {
             LOGGER.warn("Persistence unit " + persistenceUnit.getPersistenceUnitName() + " refers to a non OSGi service DataSource");
             return null;
         }
         DataSourceTracker dsTracker = new DataSourceTracker(containerContext, this, 
         		DataSourceTracker.getDsName(persistenceUnit));
         return dsTracker;
     } else if (usesDSF()) {
     	String jdbcClass = DSFTracker.getDriverName(persistenceUnit);
     	synchronized (this) {
	driver = jdbcClass;
}
DSFTracker dsfTracker = new DSFTracker(containerContext, this, 
         		jdbcClass);
         return dsfTracker;
     } else {
         LOGGER.debug("Persistence unit " + getPUName() + " does not refer a DataSource. "
                      +"It can only be used with EntityManagerFactoryBuilder.");
         return null;
     }
 }
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:27,代碼來源:AriesEntityManagerFactoryBuilder.java

示例7: handlePotentialEclipseLink

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
private void handlePotentialEclipseLink(Bundle b) {
    if (!ECLIPSELINK_JPA_PROVIDER_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName())) {
        return;
    }
    if (registeredProviders.containsKey(b)) {
        return;
    }
    
    PersistenceProvider provider = createEclipselinkProvider(b);
    if (provider == null) {
        return;
    }

    LOG.debug("Adding new EclipseLink provider for bundle {}", b);
    PersistenceProvider proxiedProvider = new EclipseLinkPersistenceProvider(provider, b);
    
    Dictionary<String, Object> props = new Hashtable<String, Object>(); // NOSONAR
    props.put("org.apache.aries.jpa.container.weaving.packages", getJPAPackages(b));
    props.put("javax.persistence.provider", ECLIPSELINK_JPA_PROVIDER_CLASS_NAME);
    ServiceRegistration<?> reg = context.registerService(PersistenceProvider.class, proxiedProvider, props);
    
    ServiceRegistration<?> old = registeredProviders.putIfAbsent(b, reg);
    if (old != null) {
        reg.unregister();
    }
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:27,代碼來源:Activator.java

示例8: 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

示例9: 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

示例10: createNativePersistenceProvider

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
private PersistenceProvider createNativePersistenceProvider(String unitName, Map properties, XmlParser xmlParser) {
    String overriddenPersistenceProviderClassName = (String)properties.get(PERSISTENCE_PROVIDER_PROPERTY);
    if (isOtherPersistenceProvider(overriddenPersistenceProviderClassName)) {
        return null;
    }
    String persistenceProviderClassName = getPersistenceProviderClassName(unitName, xmlParser);
    if (isOtherPersistenceProvider(overriddenPersistenceProviderClassName, persistenceProviderClassName)) {
        return null;
    }
    String nativePersistenceProviderClassName
        = getNativePersistenceProviderClassName(unitName,
                                                overriddenPersistenceProviderClassName,
                                                persistenceProviderClassName,
                                                properties,
                                                xmlParser);
    properties.put(PERSISTENCE_PROVIDER_PROPERTY, nativePersistenceProviderClassName);
    return createNativePersistenceProvider(nativePersistenceProviderClassName);
}
 
開發者ID:ArneLimburg,項目名稱:jpasecurity,代碼行數:19,代碼來源:SecurePersistenceProvider.java

示例11: start

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
    this.bundleContext = bundleContext;
    debugPrintln("Activating ...");

    HibernatePersistence persistenceProvider = new HibernatePersistence();

    Dictionary<String, String> props = new Hashtable<String, String>();
    props.put(JAVAX_PERSISTENCE_PROVIDER_PROP, persistenceProvider
            .getClass().getName());

    serviceRegistration = context
            .registerService(PersistenceProvider.class.getName(),
                    persistenceProvider, props);

    debugPrintln("Service: ".concat(PersistenceProvider.class.getName())
            .concat(" registered. Bundle activated."));
}
 
開發者ID:gvSIGAssociation,項目名稱:gvnix1,代碼行數:19,代碼來源:Activator.java

示例12: entityManagerFactory

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
/**
 * Construit un {@link LocalContainerEntityManagerFactoryBean} à partir d'un ensemble d'options usuelles.
 */
public static LocalContainerEntityManagerFactoryBean entityManagerFactory(IJpaConfigurationProvider provider) {
	LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
	
	entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
	entityManagerFactoryBean.setJpaProperties(getJpaProperties(provider));
	entityManagerFactoryBean.setDataSource(provider.getDataSource());
	entityManagerFactoryBean.setPackagesToScan(getPackagesToScan(provider.getJpaPackageScanProviders()));
	
	PersistenceProvider persistenceProvider = provider.getPersistenceProvider();
	if (persistenceProvider != null) {
		entityManagerFactoryBean.setPersistenceProvider(persistenceProvider);
	}
	
	return entityManagerFactoryBean;
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:19,代碼來源:JpaConfigUtils.java

示例13: 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

示例14: guessDelegate

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
private void guessDelegate() {
	// https://issues.apache.org/jira/browse/SIRONA-44
	// https://github.com/javamelody/javamelody/issues/460
	final List<PersistenceProvider> persistenceProviders = PersistenceProviderResolverHolder
			.getPersistenceProviderResolver().getPersistenceProviders();
	for (final PersistenceProvider persistenceProvider : persistenceProviders) {
		if (!getClass().isInstance(persistenceProvider)) {
			delegate = persistenceProvider;
			break;
		}
	}
	if (delegate == null) {
		for (final String provider : PROVIDERS) {
			try {
				delegate = newPersistence(provider);
				break;
			} catch (final Throwable th2) { // NOPMD
				continue;
			}
		}
		if (delegate == null) {
			throw new IllegalStateException(
					new ClassNotFoundException("Can't find a delegate"));
		}
	}
}
 
開發者ID:javamelody,項目名稱:javamelody,代碼行數:27,代碼來源:JpaPersistence.java

示例15: create

import javax.persistence.spi.PersistenceProvider; //導入依賴的package包/類
private void create(Bundle bundle, Context context) {
    Map.Entry<String, PersistenceProvider> pp = provider.get(context.definition.provider);
    // Do the registration of the service asynchronously. Since it may imply all kinds of
    // listening actions performed as a result of it, it may block the bundle handling.
    // However, indicate that we are in the process of the actions by
    // setting the used provider.
    context.usedProvider = pp.getKey();
    new Thread(() -> {
        synchronized (context) {
            if (context.usedProvider != null) {
                PersistenceUnitInfo info = PersistenceUnitProcessor.getPersistenceUnitInfo(bundle,
                        context.definition, pp.getValue());
                context.factory = PersistenceUnitProcessor.createFactory(pp.getValue(), info);
                Hashtable<String, Object> props = new Hashtable<>();
                props.put(EntityManagerFactoryBuilder.JPA_UNIT_NAME, context.definition.name);
                props.put(PersistenceUnitTransactionType.class.getName(), info.getTransactionType().name());
                context.registration = bundle.getBundleContext().registerService(
                        EntityManagerFactory.class, context.factory, props);
            }
        }
    }).start();
}
 
開發者ID:arievanwi,項目名稱:osgi.ee,代碼行數:23,代碼來源:JpaBundleChangeListener.java


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