Example usage for org.hibernate.cfg AvailableSettings MULTI_TENANT

List of usage examples for org.hibernate.cfg AvailableSettings MULTI_TENANT

Introduction

In this page you can find the example usage for org.hibernate.cfg AvailableSettings MULTI_TENANT.

Prototype

String MULTI_TENANT

To view the source code for org.hibernate.cfg AvailableSettings MULTI_TENANT.

Click Source Link

Document

Strategy for multi-tenancy.

Usage

From source file:com.github.javarch.persistence.orm.hibernate.conf.HibernatePropertiesConfig.java

License:Apache License

/**
 * Retorna um objeto Properties com todas as configuraes de propriedades que devem
 * ser passadas ao {@link SessionFactory}. As propriedades so definidas no arquivo
 * hibernate.properties que deve estar presente no raiz do classpath.
 * /*from   w  w  w .  j  a  v  a  2 s  .  c  om*/
 * @return Properties do Hibernate.
 */
@Bean
public Properties hibernateProperties() {

    Properties props = new Properties();

    props.put(AvailableSettings.DIALECT, env.getRequiredProperty(AvailableSettings.DIALECT));

    if (env.acceptsProfiles(Profiles.TEST)) {
        props.put(AvailableSettings.HBM2DDL_AUTO, env.getProperty(AvailableSettings.HBM2DDL_AUTO, "update"));
    }

    if (env.acceptsProfiles(Profiles.MULT_TENANT)) {
        if (log.isDebugEnabled()) {
            log.debug("Profile Multi Tenancy ativado! Realizando configurao...");
        }
        if (currentIdentifierResolver == null || env.acceptsProfiles(Profiles.PRODUCTION)) {
            throw new DatabaseConfigurationException(
                    "No foi encontrado nenhum objeto CurrentIdentifierResolver.");
        }
        props.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentIdentifierResolver);
        props.put(AvailableSettings.DATASOURCE, env.getRequiredProperty(AvailableSettings.DATASOURCE));
        props.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
        props.put(AvailableSettings.MULTI_TENANT, env.getRequiredProperty(AvailableSettings.MULTI_TENANT));
    } else {

        props.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, true);
        props.put(AvailableSettings.USE_QUERY_CACHE, true);
        props.put(AvailableSettings.CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.EhCacheRegionFactory");
    }

    if (env.acceptsProfiles(Profiles.ENVERS)) {
        props.put("org.hibernate.envers.versionsTableSuffix", "_audit");
        props.put("org.hibernate.envers.revisionFieldName", "revision");
        props.put("org.hibernate.envers.default_schema", "audit");
    }

    return props;
}