Java 类javax.persistence.spi.PersistenceProviderResolverHolder 实例源码

项目:trakxmap    文件:DB.java   
/**
 * 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() {

        }
    });
}
项目:javamelody    文件:JpaPersistence.java   
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"));
        }
    }
}
项目:deltaspike    文件:PersistenceConfigurationProviderTest.java   
@Deployment
public static WebArchive deploy()
{
    // set the dummy PersistenceProviderResolver which creates our DummyEntityManagerFactory
    PersistenceProviderResolverHolder.setPersistenceProviderResolver(new TestPersistenceProviderResolver());

    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "unitDefinitionTest.jar")
            .addPackage(ArchiveUtils.SHARED_PACKAGE)
            .addClass(PersistenceConfigurationProviderTest.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    return ShrinkWrap.create(WebArchive.class)
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
}
项目:deltaspike    文件:EntityManagerFactoryProducerTest.java   
@Deployment
public static WebArchive deploy()
{
    // set the dummy PersistenceProviderResolver which creates our DummyEntityManagerFactory
    PersistenceProviderResolverHolder.setPersistenceProviderResolver(new TestPersistenceProviderResolver());

    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "unitDefinitionTest.jar")
            .addPackage(ArchiveUtils.SHARED_PACKAGE)
            .addPackage(EntityManagerFactoryProducerTest.class.getPackage().getName())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsResource(new StringAsset(TestPersistenceProviderResolver.class.getName()),
                    "META-INF/services/javax.persistence.spi.PersistenceProviderResolver");

    return ShrinkWrap.create(WebArchive.class)
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
}
项目:aries-jpa    文件:AriesJPASpecActivator.java   
@Override
public void start(BundleContext context) throws Exception {
    emfResolver = new EMFBuilderServiceResolver(context);

    tracker = new ServiceTracker<PersistenceProvider, PersistenceProvider>(context, 
            PersistenceProvider.class, null);
    tracker.open();

    PersistenceProviderResolverHolder.setPersistenceProviderResolver(this);
}
项目:aries-jpa    文件:AriesJPASpecActivator.java   
@Override
public void start(BundleContext context) throws Exception {
    emfResolver = new EMFBuilderServiceResolver(context);

    tracker = new ServiceTracker<PersistenceProvider, PersistenceProvider>(context, 
            PersistenceProvider.class, null);
    tracker.open();

    PersistenceProviderResolverHolder.setPersistenceProviderResolver(this);
}
项目:javamelody    文件:TestJpa.java   
private PersistenceProvider getJpaPersistence() {
    final List<PersistenceProvider> persistenceProviders = PersistenceProviderResolverHolder
            .getPersistenceProviderResolver().getPersistenceProviders();
    for (final PersistenceProvider persistenceProvider : persistenceProviders) {
        if (persistenceProvider instanceof JpaPersistence) {
            return persistenceProvider;
        }
    }
    throw new IllegalStateException("JpaPersistence not found in PersistenceProviders");
}
项目:activejpa    文件:JPA.java   
private JPA() {
    List<PersistenceProvider> providers = PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders();
    if (providers != null) {
        String providerClass = providers.get(0).getClass().getCanonicalName();
        if (providerClass.equals(HIBERNATE_PERSISTENCE) || providerClass.equals(HIBERNATE_JPA_PERSISTENCE)) {
            cacheableHint = "org.hibernate.cacheable";
        } else if (providerClass.equals(ECLIPSE_PERSISTENCE)) {
            cacheableHint = "eclipselink.query-results-cache";
        } else if (providerClass.equals(OPENJPA_PERSISTENCE)) {
            cacheableHint = "openjpa.QueryCache";
        }
    }
}
项目:aries-jpa    文件:AriesJPASpecActivator.java   
@Override
public void stop(BundleContext context) throws Exception {
    PersistenceProviderResolverHolder.setPersistenceProviderResolver(null);
    tracker.close();
    emfResolver.close();
}
项目:aries-jpa    文件:AriesJPASpecActivator.java   
@Override
public void stop(BundleContext context) throws Exception {
    PersistenceProviderResolverHolder.setPersistenceProviderResolver(null);
    tracker.close();
    emfResolver.close();
}
项目:hibhik    文件:CustomPersistence.java   
protected static List<PersistenceProvider> getProviders() {
    return PersistenceProviderResolverHolder
            .getPersistenceProviderResolver()
            .getPersistenceProviders();
}
项目:hammock    文件:EntityManagerFactoryProvider.java   
@Produces
@ApplicationScoped
public PersistenceProvider getPersistenceProvider() {
    return PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders().get(0);
}
项目:minnal    文件:JPAPlugin.java   
protected List<PersistenceProvider> getProviders() {
    return PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders();
}
项目:de.thomasdarimont.labs.jpa    文件:EclipseLinkPlainJpaTests.java   
@BeforeClass
public static void setupClass() {
    System.setProperty(ECLIPSELINK_PERSISTENCEXML, "META-INF/eclipselink-plainjpa-persistence.xml");
    PersistenceProviderResolverHolder.setPersistenceProviderResolver(new EclipseLinkOnlyPersistenceProviderResolve());
    emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
}