@Bean(name="quikdoPU")
public LocalContainerEntityManagerFactoryBean quikdoPU() throws PropertyVetoException {
SoluvasMultiTenantConnectionProviderImpl.dataSource = dataSource();
SoluvasTenantIdentifierResolver.appCtx = appCtx;
/**
* So the list of possible options are,
*
* validate: validate the schema, makes no changes to the database.
* update: update the schema.
* create: creates the schema, destroying previous data.
* create-drop: drop the schema at the end of the session.
*/
final String jpaHbm2DdlAuto = env.getRequiredProperty("jpaHbm2DdlAuto");
log.info("JPA schema configuration: hbm2ddlauto={}", jpaHbm2DdlAuto);
final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setPersistenceUnitName("quikdoPU"); factoryBean.setDataSource(dataSource());
factoryBean.setJpaVendorAdapter(jpaVendorAdapter());
factoryBean.setPackagesToScan(
"com.quikdo.schema.core.jpa"
);
final ImmutableMap.Builder<String, Object> propb = ImmutableMap.builder();
propb.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, jpaHbm2DdlAuto);
propb.put(org.hibernate.cfg.Environment.DIALECT, PostgreSQL82Dialect.class.getName());
propb.put(org.hibernate.cfg.Environment.SHOW_SQL, false);
propb.put(org.hibernate.cfg.Environment.FORMAT_SQL, true);
propb.put(org.hibernate.cfg.Environment.USE_SQL_COMMENTS, true);
propb.put(org.hibernate.ejb.HibernatePersistence.NAMING_STRATEGY, DefaultComponentSafeNamingStrategy.class.getName());
propb.put(org.hibernate.cfg.Environment.MULTI_TENANT,
MultiTenancyStrategy.SCHEMA);
propb.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER,
SoluvasMultiTenantConnectionProviderImpl.class);
propb.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER,
SoluvasTenantIdentifierResolver.class);
final Map<String, Object> propertyMap = propb.build();
factoryBean.setJpaPropertyMap(propertyMap);
return factoryBean;
}