/** * 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() { } }); }
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")); } } }
@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"); }
@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"); }
@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); }
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"); }
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"; } } }
@Override public void stop(BundleContext context) throws Exception { PersistenceProviderResolverHolder.setPersistenceProviderResolver(null); tracker.close(); emfResolver.close(); }
protected static List<PersistenceProvider> getProviders() { return PersistenceProviderResolverHolder .getPersistenceProviderResolver() .getPersistenceProviders(); }
@Produces @ApplicationScoped public PersistenceProvider getPersistenceProvider() { return PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders().get(0); }
protected List<PersistenceProvider> getProviders() { return PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders(); }
@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); }