Java Code Examples for org.hibernate.context.spi.CurrentTenantIdentifierResolver

The following examples show how to use org.hibernate.context.spi.CurrentTenantIdentifierResolver. These examples are extracted from open source projects. 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 Project: multitenancy   Source File: MultiTenancyJpaConfiguration.java    License: 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 2
Source Project: cloud-s4-sdk-examples   Source File: HibernateConfig.java    License: 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 Project: spring-boot-multitenant   Source File: HibernateConfig.java    License: 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 4
Source Project: spring-analysis-note   Source File: LocalSessionFactoryBuilder.java    License: 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 5
Source Project: java-technology-stack   Source File: LocalSessionFactoryBuilder.java    License: 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 6
/**
 * 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 7
Source Project: lams   Source File: Configuration.java    License: GNU General Public License v2.0 4 votes vote down vote up
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return currentTenantIdentifierResolver;
}
 
Example 8
Source Project: lams   Source File: Configuration.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example 9
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return delegate.getCurrentTenantIdentifierResolver();
}
 
Example 10
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return getSessionFactoryOptions().getCurrentTenantIdentifierResolver();
}
 
Example 11
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return delegate.getCurrentTenantIdentifierResolver();
}
 
Example 12
@Override
public T applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
	delegate.applyCurrentTenantIdentifierResolver( resolver );
	return getThis();
}
 
Example 13
@Override
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
	return currentTenantIdentifierResolver;
}
 
Example 14
public void applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
	this.currentTenantIdentifierResolver = resolver;
}
 
Example 15
@Override
public SessionFactoryBuilder applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
	this.optionsBuilder.applyCurrentTenantIdentifierResolver( resolver );
	return this;
}
 
Example 16
Source Project: lemon   Source File: SessionFactoryWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver() {
    return sessionFactoryImplementor.getCurrentTenantIdentifierResolver();
}
 
Example 17
Source Project: spring-analysis-note   Source File: LocalSessionFactoryBean.java    License: 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 18
Source Project: java-technology-stack   Source File: LocalSessionFactoryBean.java    License: 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 Project: multitenancy   Source File: MultiTenancyJpaConfiguration.java    License: 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 20
Source Project: lams   Source File: LocalSessionFactoryBean.java    License: 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
/**
 * @todo make a Service ?
 */
CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
 
Example 22
Source Project: lams   Source File: SessionFactoryBuilder.java    License: 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 23
/**
 * Set a {@link CurrentTenantIdentifierResolver} to be passed on to the SessionFactory.
 * @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
 */
public void setCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
	this.currentTenantIdentifierResolver = currentTenantIdentifierResolver;
}
 
Example 24
CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();