Java Code Examples for org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setBeanName()

The following examples show how to use org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setBeanName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityManagerFactoryServiceImpl.java    From multitenant with Apache License 2.0 6 votes vote down vote up
@Override
public EntityManagerFactory createEntityManagerFactory(Organization organization) {
	DataSource dataSource = dataSourceService.getOrCreateDataSource(organization);
	Map<String, Object> vendorProperties = getVendorProperties(dataSource);
	customizeVendorProperties(vendorProperties);
	LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = getEntityManagerFactoryBuilder(dataSource).dataSource(dataSource).packages(mergePackagesToScan())
			.properties(vendorProperties).jta(isJta()).build();
	entityManagerFactoryBean.setBeanClassLoader(classLoader);
	entityManagerFactoryBean.setBeanFactory(beanFactory);
	entityManagerFactoryBean.setBeanName(beanName);
	entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
	entityManagerFactoryBean.setResourceLoader(resourceLoader);
	entityManagerFactoryBean.setPersistenceUnitName(organization.getId());
	entityManagerFactoryBean.afterPropertiesSet();
	scriptService.runScripts(organization.getId(), dataSource, dataScript, "multitenant-data");
	return entityManagerFactoryBean.getObject();
}
 
Example 2
Source File: EntityManagerFactoryServiceImpl.java    From multitenant with Apache License 2.0 6 votes vote down vote up
@Override
public void generateTables(Organization organization) {
	SingleConnectionDataSource dataSource = dataSourceService.createSingleConnectionDataSource(organization);
	if (dataSource != null) {
		Map<String, Object> vendorProperties = getVendorProperties(dataSource);
		customizeVendorProperties(vendorProperties);
		Builder builder = getEntityManagerFactoryBuilder(dataSource).dataSource(dataSource).packages(packagesToScan.split(","))
				.properties(vendorProperties).jta(isJta());
		LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = builder.build();

	    publishEvent(organization, builder);

		entityManagerFactoryBean.setBeanClassLoader(classLoader);
		entityManagerFactoryBean.setBeanFactory(beanFactory);
		entityManagerFactoryBean.setBeanName(beanName);
		entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
		entityManagerFactoryBean.setResourceLoader(resourceLoader);
		entityManagerFactoryBean.afterPropertiesSet();
		entityManagerFactoryBean.destroy();
		dataSource.destroy();
	}
}
 
Example 3
Source File: EntityManagerFactoryServiceImpl.java    From multitenant with Apache License 2.0 6 votes vote down vote up
@Override
public EntityManagerFactory createTempEntityManagerFactory(
		Organization organization) {
	SingleConnectionDataSource dataSource = dataSourceService.createSingleConnectionDataSource(organization);
	if (dataSource != null) {
		Map<String, Object> vendorProperties = getVendorProperties(dataSource);
		customizeVendorProperties(vendorProperties);
	    Builder builder = getEntityManagerFactoryBuilder(dataSource).dataSource(dataSource).packages(mergePackagesToScan())
				.properties(vendorProperties).jta(isJta());
		LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = builder.build();
		entityManagerFactoryBean.setBeanClassLoader(classLoader);
		entityManagerFactoryBean.setBeanFactory(beanFactory);
		entityManagerFactoryBean.setBeanName(beanName);
		entityManagerFactoryBean.setLoadTimeWeaver(loadTimeWeaver);
		entityManagerFactoryBean.setResourceLoader(resourceLoader);
		entityManagerFactoryBean.afterPropertiesSet();
		return entityManagerFactoryBean.getObject();
	}
	return null;
}
 
Example 4
Source File: DatabaseConfiguration.java    From patient-batch-loader with GNU General Public License v3.0 5 votes vote down vote up
@Bean(name = "batchEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean batchEntityManagerFactory() {
    LocalContainerEntityManagerFactoryBean emfBean =
        new LocalContainerEntityManagerFactoryBean();
    emfBean.setDataSource(batchDataSource());
    emfBean.setPackagesToScan("com.pluralsight.springbatch.patientbatchloader");
    emfBean.setBeanName("batchEntityManagerFactory");
    emfBean.setJpaVendorAdapter(batchJpaVendorAdapter());

    Properties jpaProps = new Properties();
    jpaProps.put("hibernate.physical_naming_strategy",
        env.getProperty("spring.jpa.hibernate.naming.physical-strategy"));
    jpaProps.put("hibernate.hbm2ddl.auto", env.getProperty(
        "spring.jpa.hibernate.ddl-auto", "none"));
    jpaProps.put("hibernate.jdbc.fetch_size", env.getProperty(
        "spring.jpa.properties.hibernate.jdbc.fetch_size",
        "200"));

    Integer batchSize = env.getProperty(
        "spring.jpa.properties.hibernate.jdbc.batch_size",
        Integer.class, 100);
    if (batchSize > 0) {
        jpaProps.put("hibernate.jdbc.batch_size", batchSize);
        jpaProps.put("hibernate.order_inserts", "true");
        jpaProps.put("hibernate.order_updates", "true");
    }

    jpaProps.put("hibernate.show_sql", env.getProperty(
        "spring.jpa.properties.hibernate.show_sql", "false"));
    jpaProps.put("hibernate.format_sql",env.getProperty(
        "spring.jpa.properties.hibernate.format_sql", "false"));

    emfBean.setJpaProperties(jpaProps);
    return emfBean;
}