/** * 2017-05-24 · reworked from SpringHibernateJpaPersistenceProvider so that we can inject a custom * {@link EntityManagerFactoryBuilderImpl}; previous implementation that overrides * {@link InterceptorAwareHibernatePersistenceProvider#getEntityManagerFactoryBuilder} no longer works * as there are several paths with various arguments and the overloaded one was no longer called. */ @Override @SuppressWarnings("rawtypes") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(info), properties) { @Override protected void populate(SessionFactoryBuilder sfBuilder, StandardServiceRegistry ssr) { super.populate(sfBuilder, ssr); if (InterceptorAwareHibernatePersistenceProvider.this.interceptor != null) { LOGGER.warn("Installing our Spring managed interceptor."); sfBuilder.applyInterceptor(InterceptorAwareHibernatePersistenceProvider.this.interceptor); } } }.build(); }
@Test public void test() { PersistenceUnitInfoImpl persistenceUnitInfo = new PersistenceUnitInfoImpl( LongToNumericTypeTest.class.getName(), Collections.singletonList( Event.class.getName() ), validateProperties() ); Map<String, Object> configuration = new HashMap<>(); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor( persistenceUnitInfo), configuration ); EntityManagerFactory emf = null; try { emf = entityManagerFactoryBuilder.build(); } finally { if ( emf != null ) { emf.close(); } } }
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<>(); configuration.put(AvailableSettings.INTERCEPTOR, interceptor()); Integrator integrator = integrator(); if (integrator != null) { configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator)); } EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<String, Object>(); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<String, Object>(); configuration.put(AvailableSettings.INTERCEPTOR, interceptor()); Integrator integrator = integrator(); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }
/** * TODO : cache entity manager. * * @param info * the info * @return the entity manager factory */ public static EntityManagerFactory createEntityManagerFactory(PersistenceUnitInfo info) { // Map<String, Object> integrationSettings = new HashMap<>(); // integrationSettings.put(AvailableSettings.INTERCEPTOR, new // JKCustomSessionFactoryInterceptor()); PersistenceUnitInfoDescriptor puDescriptor = new PersistenceUnitInfoDescriptor(info); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(puDescriptor, null); EntityManagerFactory emf = entityManagerFactoryBuilder.build(); return emf; }
@Override @SuppressWarnings("rawtypes") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { final List<String> mergedClassesAndPackages = new ArrayList<String>(info.getManagedClassNames()); if (info instanceof SmartPersistenceUnitInfo) { mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages()); } return new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(info) { @Override public List<String> getManagedClassNames() { return mergedClassesAndPackages; } }, properties).build(); }
@Component public EntityManagerFactory entityManagerFactory () { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(); PersistenceUnitDescriptor descriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo); EntityManagerFactoryBuilder entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(descriptor, null); return entityManagerFactoryBuilder.build(); }
@Override protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties, ClassLoader providedClassLoader) { PersistenceUnitInfo info = new RapidoidPersistenceUnitInfo(persistenceUnitName, dataSource, providedClassLoader); PersistenceUnitInfoDescriptor persistenceUnit = new PersistenceUnitInfoDescriptor(info); return emfBuilder(persistenceUnit, properties, providedClassLoader); }
protected EntityManagerFactory newEntityManagerFactory() { PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl( getClass().getSimpleName(), entityClassNames(), getProperties() ); Map<String, Object> configuration = new HashMap<>(); configuration.put(org.hibernate.jpa.AvailableSettings.INTERCEPTOR, interceptor()); EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl( new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration ); return entityManagerFactoryBuilder.build(); }