org.hibernate.context.spi.CurrentTenantIdentifierResolver Java Examples

The following examples show how to use org.hibernate.context.spi.CurrentTenantIdentifierResolver. 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: HibernateConfig.java    From spring-boot-multitenant with Apache License 2.0 6 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
    MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
    CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
  Map<String, Object> properties = new HashMap<>();
  properties.putAll(jpaProperties.getHibernateProperties(dataSource));
  properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
  properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
  properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);

  LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  em.setDataSource(dataSource);
  em.setPackagesToScan("com.srai");
  em.setJpaVendorAdapter(jpaVendorAdapter());
  em.setJpaPropertyMap(properties);
  return em;
}
 
Example #2
Source File: HibernateConfig.java    From cloud-s4-sdk-examples with Apache License 2.0 6 votes vote down vote up
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, MultiTenantConnectionProvider multiTenantConnectionProvider,
                                                                   CurrentTenantIdentifierResolver tenantIdentifierResolver) {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan("com.mycompany.models");

    em.setJpaVendorAdapter(this.jpaVendorAdapter());

    final Map<String, Object> jpaProperties = new HashMap<>();
    jpaProperties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    jpaProperties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
    jpaProperties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantIdentifierResolver);
    jpaProperties.put(Environment.FORMAT_SQL, true);

    em.setJpaPropertyMap(jpaProperties);
    return em;
}
 
Example #3
Source File: MultiTenancyJpaConfiguration.java    From multitenancy with Apache License 2.0 6 votes vote down vote up
/**
 * org.springframework.beans.factory.FactoryBean that creates a JPA
 * {@link javax.persistence.EntityManagerFactory} according to JPA's standard
 * container bootstrap contract. This is the most powerful way to set up a
 * shared JPA EntityManagerFactory in a Spring application context; the
 * EntityManagerFactory can then be passed to JPA-based DAOs via dependency
 * injection. Note that switching to a JNDI lookup or to a
 * {@link org.springframework.orm.jpa.LocalEntityManagerFactoryBean} definition
 * is just a matter of configuration!
 * 
 * @param multiTenantConnectionProvider
 * @param currentTenantIdentifierResolver
 * @return
 */
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(
        MultiTenantConnectionProvider multiTenantConnectionProvider,
        CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {

    Map<String, Object> hibernateProps = new LinkedHashMap<>();
    hibernateProps.putAll(this.jpaProperties.getProperties());
    hibernateProps.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
    hibernateProps.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
    hibernateProps.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);

    // No dataSource is set to resulting entityManagerFactoryBean
    LocalContainerEntityManagerFactoryBean result = new LocalContainerEntityManagerFactoryBean();
    result.setPackagesToScan(new String[] { Employee.class.getPackage().getName() });
    result.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    result.setJpaPropertyMap(hibernateProps);

    return result;
}
 
Example #4
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return getSessionFactoryOptions().getCurrentTenantIdentifierResolver();
}
 
Example #5
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
    return sessionFactoryImplementor.getCurrentTenantIdentifierResolver();
}
 
Example #6
Source File: SessionFactoryBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
	this.optionsBuilder.applyCurrentTenantIdentifierResolver( resolver );
	return this;
}
 
Example #7
Source File: SessionFactoryOptionsBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
	this.currentTenantIdentifierResolver = resolver;
}
 
Example #8
Source File: SessionFactoryOptionsBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return currentTenantIdentifierResolver;
}
 
Example #9
Source File: AbstractDelegatingSessionFactoryBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public T applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
	delegate.applyCurrentTenantIdentifierResolver( resolver );
	return getThis();
}
 
Example #10
Source File: AbstractDelegatingSessionFactoryOptions.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return delegate.getCurrentTenantIdentifierResolver();
}
 
Example #11
Source File: SessionFactoryDelegatingImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return delegate.getCurrentTenantIdentifierResolver();
}
 
Example #12
Source File: Configuration.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example #13
Source File: Configuration.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return currentTenantIdentifierResolver;
}
 
Example #14
Source File: LocalSessionFactoryBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Overridden to reliably pass a {@link CurrentTenantIdentifierResolver} to the SessionFactory.
 * @since 4.3.2
 * @see AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER
 */
@Override
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	getProperties().put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);
	super.setCurrentTenantIdentifierResolver(currentTenantIdentifierResolver);
}
 
Example #15
Source File: LocalSessionFactoryBuilder.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Overridden to reliably pass a {@link CurrentTenantIdentifierResolver} to the SessionFactory.
 * @since 4.3.2
 * @see AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER
 */
@Override
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	getProperties().put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);
	super.setCurrentTenantIdentifierResolver(currentTenantIdentifierResolver);
}
 
Example #16
Source File: LocalSessionFactoryBuilder.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Overridden to reliably pass a {@link CurrentTenantIdentifierResolver} to the SessionFactory.
 * @since 4.3.2
 * @see AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER
 */
@Override
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	getProperties().put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);
	super.setCurrentTenantIdentifierResolver(currentTenantIdentifierResolver);
}
 
Example #17
Source File: SessionFactoryImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @todo make a Service ?
 */
CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
 
Example #18
Source File: LocalSessionFactoryBean.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set a {@link CurrentTenantIdentifierResolver} to be passed on to the SessionFactory.
 * @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
 */
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example #19
Source File: SessionFactoryBuilder.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Specifies a strategy for resolving the notion of a "current" tenant-identifier when using multi-tenancy
 * together with current sessions
 *
 * @param resolver The resolution strategy to use.
 *
 * @return {@code this}, for method chaining
 *
 * @see org.hibernate.cfg.AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER
 */
SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver);
 
Example #20
Source File: LocalSessionFactoryBean.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set a {@link CurrentTenantIdentifierResolver} to be passed on to the SessionFactory.
 * @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
 */
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example #21
Source File: MultiTenancyJpaConfiguration.java    From multitenancy with Apache License 2.0 2 votes vote down vote up
/**
 * Since this is a multi-tenant application, Hibernate requires that the current
 * tenant identifier is resolved for use with
 * {@link org.hibernate.context.spi.CurrentSessionContext} and
 * {@link org.hibernate.SessionFactory#getCurrentSession()}
 * 
 * @return
 */
@Bean
public CurrentTenantIdentifierResolver currentTenantIdentifierResolver() {
    return new CurrentTenantIdentifierResolverImpl();
}
 
Example #22
Source File: LocalSessionFactoryBean.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Set a {@link CurrentTenantIdentifierResolver} to be passed on to the SessionFactory.
 * @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
 */
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example #23
Source File: LocalSessionFactoryBean.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Set a {@link CurrentTenantIdentifierResolver} to be passed on to the SessionFactory.
 * @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
 */
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example #24
Source File: SessionFactoryOptions.java    From lams with GNU General Public License v2.0 votes vote down vote up
CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();