List of usage examples for org.springframework.orm.jpa.persistenceunit DefaultPersistenceUnitManager DefaultPersistenceUnitManager
DefaultPersistenceUnitManager
From source file:com.mycompany.projetsportmanager.spring.configuration.BaseConfiguration.java
/** * Builds the persistence unit manager./*from www .j a v a2 s. com*/ * @param dataSource the datasource. * @return the persistence unit manager. */ @Bean public DefaultPersistenceUnitManager persistenceUnitManager() { DefaultPersistenceUnitManager defaultPersistenceUnitManager = new DefaultPersistenceUnitManager(); defaultPersistenceUnitManager.setPersistenceXmlLocation("classpath*:/META-INF/persistence.xml"); defaultPersistenceUnitManager.setDefaultDataSource(dataSource); return defaultPersistenceUnitManager; }
From source file:com.eclecticlogic.pedal.JpaConfiguration.java
/** * @return Introduce custom persistence unit manager so that we can use the orm.xml file to rename the table * mapping for Student.java and verify that we pick up the renamed mapping via ProviderAccess. *//*from w w w . ja va 2 s . c om*/ @Bean public PersistenceUnitManager persistenceUnitManager(DataSource dataSource) { DefaultPersistenceUnitManager manager = new DefaultPersistenceUnitManager(); manager.setPersistenceXmlLocation("classpath:META-INF/pedal-test-persistence.xml"); manager.setDefaultDataSource(dataSource); return manager; }
From source file:fr.paris.lutece.portal.service.jpa.JPAStartupService.java
/** * Initialize JPA objects (Datasource, Persistence Unit Manager, Entity Manager Factory, * Transaction Manager) for each pool./*from w w w . j a v a2 s. c o m*/ */ public void process() { ReferenceList list = new ReferenceList(); AppConnectionService.getPoolList(list); Map<String, EntityManagerFactory> mapFactories = new HashMap<String, EntityManagerFactory>(); List<PlatformTransactionManager> listTransactionManagers = new ArrayList<PlatformTransactionManager>(); _log.info("JPA Startup Service : Initializing JPA objects ..."); String strDialectProperty = AppPropertiesService.getProperty(JPA_DIALECT_PROPERTY); for (ReferenceItem poolItem : list) { String strPoolname = poolItem.getCode(); DataSource ds = AppConnectionService.getPoolManager().getDataSource(strPoolname); _log.info("JPA Startup Service : DataSource retrieved for pool : " + strPoolname); _log.debug("> DS : " + ds.toString()); DefaultPersistenceUnitManager pum = new DefaultPersistenceUnitManager(); pum.setDefaultDataSource(ds); PersistenceUnitPostProcessor[] postProcessors = { new JPAPersistenceUnitPostProcessor() }; pum.setPersistenceUnitPostProcessors(postProcessors); pum.afterPropertiesSet(); _log.info("JPA Startup Service : Persistence Unit Manager for pool : " + strPoolname); _log.debug("> PUM : " + pum.toString()); LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setDataSource(ds); lcemfb.setPersistenceUnitManager(pum); lcemfb.setPersistenceUnitName("jpaLuteceUnit"); JpaDialect jpaDialect = (JpaDialect) SpringContextService.getBean("jpaDialect"); lcemfb.setJpaDialect(jpaDialect); Map mapJpaProperties = (Map) SpringContextService.getBean("jpaPropertiesMap"); lcemfb.setJpaPropertyMap(mapJpaProperties); String strDialect = AppPropertiesService.getProperty(poolItem.getName() + ".dialect"); // replace default dialect if <poolname>.dialect is specified if (StringUtils.isNotBlank(strDialect)) { mapJpaProperties.put(strDialectProperty, strDialect); } _log.debug("Using dialect " + mapJpaProperties.get(strDialectProperty) + " for pool " + poolItem.getName()); JpaVendorAdapter jpaVendorAdapter = (JpaVendorAdapter) SpringContextService.getBean("jpaVendorAdapter"); lcemfb.setJpaVendorAdapter(jpaVendorAdapter); lcemfb.afterPropertiesSet(); EntityManagerFactory emf = lcemfb.getNativeEntityManagerFactory(); _log.info("JPA Startup Service : EntityManagerFactory created for pool : " + strPoolname); _log.debug("> EMF : " + emf.toString()); JpaTransactionManager tm = new JpaTransactionManager(); tm.setEntityManagerFactory(emf); tm.setJpaDialect(jpaDialect); _log.debug("> JpaDialect " + jpaDialect); tm.afterPropertiesSet(); _log.info("JPA Startup Service : JPA TransactionManager created for pool : " + strPoolname); _log.debug("> TM : " + tm.toString()); mapFactories.put(strPoolname, emf); listTransactionManagers.add(tm); } EntityManagerService ems = (EntityManagerService) SpringContextService.getBean("entityManagerService"); ems.setMapFactories(mapFactories); ChainedTransactionManager ctm = (ChainedTransactionManager) SpringContextService .getBean("transactionManager"); ctm.setTransactionManagers(listTransactionManagers); _log.info("JPA Startup Service : completed successfully"); }
From source file:com.brienwheeler.apps.schematool.SchemaToolBean.java
@SuppressWarnings("unchecked") private PersistenceUnitManager simulateDefaultPum(NonInitializingClassPathXmlApplicationContext context, BeanDefinition emfBeanDef) {/*from w w w.ja va2 s . co m*/ // Simulate Spring's use of DefaultPersistenceUnitManager DefaultPersistenceUnitManager defpum = new DefaultPersistenceUnitManager(); // Set the location of the persistence XML -- when using the DPUM, // you can only set one persistence XML location on the EntityManagerFactory PropertyValue locationProperty = emfBeanDef.getPropertyValues().getPropertyValue("persistenceXmlLocation"); if (locationProperty == null || !(locationProperty.getValue() instanceof TypedStringValue)) { throw new RuntimeException( "no property 'persistenceXmlLocation' defined on bean: " + emfContextBeanName); } // Since PersistenceUnitPostProcessors may do things like set properties // onto the persistence unit, we need to instantiate them here so that // they get called when preparePersistenceUnitInfos() executes PropertyValue puiPostProcProperty = emfBeanDef.getPropertyValues() .getPropertyValue("persistenceUnitPostProcessors"); if (puiPostProcProperty != null && puiPostProcProperty.getValue() instanceof ManagedList) { List<PersistenceUnitPostProcessor> postProcessors = new ArrayList<PersistenceUnitPostProcessor>(); for (BeanDefinitionHolder postProcBeanDef : (ManagedList<BeanDefinitionHolder>) puiPostProcProperty .getValue()) { String beanName = postProcBeanDef.getBeanName(); BeanDefinition beanDefinition = postProcBeanDef.getBeanDefinition(); PersistenceUnitPostProcessor postProcessor = (PersistenceUnitPostProcessor) context .createBean(beanName, beanDefinition); postProcessors.add(postProcessor); } defpum.setPersistenceUnitPostProcessors( postProcessors.toArray(new PersistenceUnitPostProcessor[postProcessors.size()])); } defpum.setPersistenceXmlLocation(((TypedStringValue) locationProperty.getValue()).getValue()); defpum.preparePersistenceUnitInfos(); return defpum; }