remove MultiTenancyStrategy
Use the existence of a MultiTenantConnectionProvider to infer that multitenancy is enabled.
This commit is contained in:
parent
915da5228d
commit
b2e6965577
|
@ -73,26 +73,6 @@ include::{sourcedir}/AbstractMultiTenancyTest.java[tags=multitenacy-hibernate-se
|
|||
----
|
||||
====
|
||||
|
||||
Additionally, when specifying the configuration, an `org.hibernate.MultiTenancyStrategy` should be named using the `hibernate.multiTenancy` setting.
|
||||
Hibernate will perform validations based on the type of strategy you specify.
|
||||
The strategy here correlates with the isolation approach discussed above.
|
||||
|
||||
NONE::
|
||||
(the default) No multitenancy is expected.
|
||||
In fact, it is considered an error if a tenant identifier is specified when opening a session using this strategy.
|
||||
SCHEMA::
|
||||
Correlates to the separate schema approach.
|
||||
It is an error to attempt to open a session without a tenant identifier using this strategy.
|
||||
Additionally, a `MultiTenantConnectionProvider` must be specified.
|
||||
DATABASE::
|
||||
Correlates to the separate database approach.
|
||||
It is an error to attempt to open a session without a tenant identifier using this strategy.
|
||||
Additionally, a `MultiTenantConnectionProvider` must be specified.
|
||||
DISCRIMINATOR::
|
||||
Correlates to the partitioned (discriminator) approach.
|
||||
It is an error to attempt to open a session without a tenant identifier using this strategy.
|
||||
This strategy is not yet implemented and you can follow its progress via the https://hibernate.atlassian.net/browse/HHH-6054[HHH-6054 Jira issue].
|
||||
|
||||
[[multitenacy-hibernate-MultiTenantConnectionProvider]]
|
||||
==== MultiTenantConnectionProvider
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.util.function.Consumer;
|
|||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
|
@ -63,7 +62,6 @@ public abstract class AbstractMultiTenancyTest extends BaseUnitTestCase {
|
|||
|
||||
Map<String, Object> settings = new HashMap<>( );
|
||||
|
||||
settings.put( AvailableSettings.MULTI_TENANT, multiTenancyStrategy() );
|
||||
settings.put( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER,
|
||||
new ConfigurableMultiTenantConnectionProvider( connectionProviderMap ) );
|
||||
|
||||
|
@ -115,8 +113,6 @@ public abstract class AbstractMultiTenancyTest extends BaseUnitTestCase {
|
|||
//end::multitenacy-multitenacy-hibernate-same-entity-example[]
|
||||
}
|
||||
|
||||
protected abstract MultiTenancyStrategy multiTenancyStrategy();
|
||||
|
||||
protected Properties properties() {
|
||||
Properties properties = new Properties( );
|
||||
URL propertiesURL = Thread.currentThread().getContextClassLoader().getResource( "hibernate.properties" );
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.userguide.multitenancy;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
@ -17,11 +16,6 @@ import org.hibernate.testing.RequiresDialect;
|
|||
@RequiresDialect(H2Dialect.class)
|
||||
public class DatabaseMultiTenancyTest extends AbstractMultiTenancyTest {
|
||||
|
||||
@Override
|
||||
protected MultiTenancyStrategy multiTenancyStrategy() {
|
||||
return MultiTenancyStrategy.DATABASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String tenantUrl(String originalUrl, String tenantIdentifier) {
|
||||
return originalUrl.replace( "db1", tenantIdentifier );
|
||||
|
|
|
@ -21,7 +21,6 @@ import jakarta.persistence.Column;
|
|||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionBuilder;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
@ -79,7 +78,6 @@ public class DatabaseTimeZoneMultiTenancyTest extends BaseUnitTestCase {
|
|||
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
|
||||
settings.put( AvailableSettings.MULTI_TENANT, MultiTenancyStrategy.DATABASE );
|
||||
settings.put(
|
||||
AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER,
|
||||
new ConfigurableMultiTenantConnectionProvider( connectionProviderMap )
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.userguide.multitenancy;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
@ -19,11 +18,6 @@ public class SchemaMultiTenancyTest extends AbstractMultiTenancyTest {
|
|||
|
||||
public static final String SCHEMA_TOKEN = ";INIT=CREATE SCHEMA IF NOT EXISTS %1$s\\;SET SCHEMA %1$s";
|
||||
|
||||
@Override
|
||||
protected MultiTenancyStrategy multiTenancyStrategy() {
|
||||
return MultiTenancyStrategy.SCHEMA;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String tenantUrl(String originalUrl, String tenantIdentifier) {
|
||||
return originalUrl + String.format( SCHEMA_TOKEN, tenantIdentifier );
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Describes the methods for multi-tenancy understood by Hibernate.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public enum MultiTenancyStrategy {
|
||||
/**
|
||||
* Multi-tenancy implemented by use of discriminator columns.
|
||||
*/
|
||||
DISCRIMINATOR,
|
||||
/**
|
||||
* Multi-tenancy implemented as separate schemas.
|
||||
*/
|
||||
SCHEMA,
|
||||
/**
|
||||
* Multi-tenancy implemented as separate databases.
|
||||
*/
|
||||
DATABASE,
|
||||
/**
|
||||
* No multi-tenancy.
|
||||
*/
|
||||
NONE;
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
MultiTenancyStrategy.class.getName()
|
||||
);
|
||||
|
||||
/**
|
||||
* Does this strategy indicate a requirement for the specialized
|
||||
* {@link org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider}, rather than the
|
||||
* traditional {@link org.hibernate.engine.jdbc.connections.spi.ConnectionProvider}?
|
||||
*
|
||||
* @return {@code true} indicates a MultiTenantConnectionProvider is required; {@code false} indicates it is not.
|
||||
*/
|
||||
public boolean requiresMultiTenantConnectionProvider() {
|
||||
return this == DATABASE || this == SCHEMA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the MultiTenancyStrategy from the setting map.
|
||||
*
|
||||
* @param properties The map of settings.
|
||||
*
|
||||
* @return The selected strategy. {@link #NONE} is always the default.
|
||||
*/
|
||||
public static MultiTenancyStrategy determineMultiTenancyStrategy(Map properties) {
|
||||
final Object strategy = properties.get( Environment.MULTI_TENANT );
|
||||
if ( strategy == null ) {
|
||||
return MultiTenancyStrategy.NONE;
|
||||
}
|
||||
|
||||
if ( MultiTenancyStrategy.class.isInstance( strategy ) ) {
|
||||
return (MultiTenancyStrategy) strategy;
|
||||
}
|
||||
|
||||
final String strategyName = strategy.toString();
|
||||
try {
|
||||
return MultiTenancyStrategy.valueOf( strategyName.toUpperCase(Locale.ROOT) );
|
||||
}
|
||||
catch ( RuntimeException e ) {
|
||||
LOG.warn( "Unknown multi tenancy strategy [ " +strategyName +" ], using MultiTenancyStrategy.NONE." );
|
||||
return MultiTenancyStrategy.NONE;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,6 @@ import org.hibernate.ConnectionReleaseMode;
|
|||
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.cache.spi.TimestampsCacheFactory;
|
||||
|
@ -354,13 +353,11 @@ public interface SessionFactoryBuilder {
|
|||
/**
|
||||
* Apply the form of multi-tenancy used by the application
|
||||
*
|
||||
* @param strategy The form of multi-tenancy in use.
|
||||
* @param enabled True if multi-tenancy in use.
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see org.hibernate.cfg.AvailableSettings#MULTI_TENANT
|
||||
*/
|
||||
SessionFactoryBuilder applyMultiTenancyStrategy(MultiTenancyStrategy strategy);
|
||||
SessionFactoryBuilder applyMultiTenancy(boolean enabled);
|
||||
|
||||
/**
|
||||
* Specifies a strategy for resolving the notion of a "current" tenant-identifier when using multi-tenancy
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.TimeZoneStorageStrategy;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.TimeZoneStorageType;
|
||||
|
@ -533,7 +532,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
|
||||
private SharedCacheMode sharedCacheMode;
|
||||
private AccessType defaultCacheAccessType;
|
||||
private MultiTenancyStrategy multiTenancyStrategy;
|
||||
private boolean multiTenancyEnabled;
|
||||
private boolean explicitDiscriminatorsForJoinedInheritanceSupported;
|
||||
private boolean implicitDiscriminatorsForJoinedInheritanceSupported;
|
||||
private boolean implicitlyForceDiscriminatorInSelect;
|
||||
|
@ -556,7 +555,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
this.mappingDefaults = new MappingDefaultsImpl( serviceRegistry );
|
||||
|
||||
this.defaultTimezoneStorage = resolveTimeZoneStorageStrategy( serviceRegistry, configService );
|
||||
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );
|
||||
this.multiTenancyEnabled = configService.getSettings().containsKey( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER );
|
||||
|
||||
this.xmlMappingEnabled = configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
|
@ -794,8 +793,8 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
}
|
||||
|
||||
@Override
|
||||
public MultiTenancyStrategy getMultiTenancyStrategy() {
|
||||
return multiTenancyStrategy;
|
||||
public boolean isMultiTenancyEnabled() {
|
||||
return multiTenancyEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.hibernate.ConnectionReleaseMode;
|
|||
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
|
@ -251,8 +250,8 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
|
|||
}
|
||||
|
||||
@Override
|
||||
public SessionFactoryBuilder applyMultiTenancyStrategy(MultiTenancyStrategy strategy) {
|
||||
this.optionsBuilder.applyMultiTenancyStrategy( strategy );
|
||||
public SessionFactoryBuilder applyMultiTenancy(boolean enabled) {
|
||||
this.optionsBuilder.applyMultiTenancy(enabled);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.hibernate.EmptyInterceptor;
|
|||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionEventListener;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.TimeZoneStorageStrategy;
|
||||
|
@ -110,6 +109,7 @@ import static org.hibernate.cfg.AvailableSettings.JPA_CALLBACKS_ENABLED;
|
|||
import static org.hibernate.cfg.AvailableSettings.JTA_TRACK_BY_THREAD;
|
||||
import static org.hibernate.cfg.AvailableSettings.LOG_SESSION_METRICS;
|
||||
import static org.hibernate.cfg.AvailableSettings.MAX_FETCH_DEPTH;
|
||||
import static org.hibernate.cfg.AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER;
|
||||
import static org.hibernate.cfg.AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER;
|
||||
import static org.hibernate.cfg.AvailableSettings.NATIVE_EXCEPTION_HANDLING_51_COMPLIANCE;
|
||||
import static org.hibernate.cfg.AvailableSettings.OMIT_JOIN_OF_SUPERCLASS_TABLES;
|
||||
|
@ -212,7 +212,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
private boolean callbacksEnabled;
|
||||
|
||||
// multi-tenancy
|
||||
private MultiTenancyStrategy multiTenancyStrategy;
|
||||
private boolean multiTenancyEnabled;
|
||||
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
|
||||
|
||||
// Queries
|
||||
|
@ -367,7 +367,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
this.checkNullability = cfgService.getSetting( CHECK_NULLABILITY, BOOLEAN, true );
|
||||
this.initializeLazyStateOutsideTransactions = cfgService.getSetting( ENABLE_LAZY_LOAD_NO_TRANS, BOOLEAN, false );
|
||||
|
||||
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configurationSettings );
|
||||
this.multiTenancyEnabled = configurationSettings.containsKey( MULTI_TENANT_CONNECTION_PROVIDER );
|
||||
this.currentTenantIdentifierResolver = strategySelector.resolveStrategy(
|
||||
CurrentTenantIdentifierResolver.class,
|
||||
configurationSettings.get( MULTI_TENANT_IDENTIFIER_RESOLVER )
|
||||
|
@ -1051,8 +1051,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public MultiTenancyStrategy getMultiTenancyStrategy() {
|
||||
return multiTenancyStrategy;
|
||||
public boolean isMultiTenancyEnabled() {
|
||||
return multiTenancyEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1424,8 +1424,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
this.postInsertIdentifierDelayed = enabled;
|
||||
}
|
||||
|
||||
public void applyMultiTenancyStrategy(MultiTenancyStrategy strategy) {
|
||||
this.multiTenancyStrategy = strategy;
|
||||
public void applyMultiTenancy(boolean enabled) {
|
||||
this.multiTenancyEnabled = enabled;
|
||||
}
|
||||
|
||||
public void applyCurrentTenantIdentifierResolver(CurrentTenantIdentifierResolver resolver) {
|
||||
|
|
|
@ -8,9 +8,7 @@ package org.hibernate.boot.spi;
|
|||
|
||||
import java.util.List;
|
||||
import jakarta.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.TimeZoneStorageStrategy;
|
||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||
import org.hibernate.boot.CacheRegionDefinition;
|
||||
|
@ -24,7 +22,6 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
|||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.MetadataSourceType;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
||||
/**
|
||||
|
@ -127,8 +124,8 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
|
|||
}
|
||||
|
||||
@Override
|
||||
public MultiTenancyStrategy getMultiTenancyStrategy() {
|
||||
return delegate.getMultiTenancyStrategy();
|
||||
public boolean isMultiTenancyEnabled() {
|
||||
return delegate.isMultiTenancyEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.hibernate.ConnectionReleaseMode;
|
|||
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
|
@ -216,8 +215,8 @@ public abstract class AbstractDelegatingSessionFactoryBuilder<T extends SessionF
|
|||
}
|
||||
|
||||
@Override
|
||||
public T applyMultiTenancyStrategy(MultiTenancyStrategy strategy) {
|
||||
delegate.applyMultiTenancyStrategy( strategy );
|
||||
public T applyMultiTenancy(boolean enabled) {
|
||||
delegate.applyMultiTenancy(enabled);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.hibernate.ConnectionReleaseMode;
|
|||
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.TimeZoneStorageStrategy;
|
||||
import org.hibernate.boot.SchemaAutoTooling;
|
||||
|
@ -211,8 +210,8 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
|
|||
}
|
||||
|
||||
@Override
|
||||
public MultiTenancyStrategy getMultiTenancyStrategy() {
|
||||
return delegate.getMultiTenancyStrategy();
|
||||
public boolean isMultiTenancyEnabled() {
|
||||
return delegate.isMultiTenancyEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,8 +8,6 @@ package org.hibernate.boot.spi;
|
|||
|
||||
import java.util.List;
|
||||
import jakarta.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.TimeZoneStorageStrategy;
|
||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||
import org.hibernate.boot.CacheRegionDefinition;
|
||||
|
@ -27,7 +25,6 @@ import org.hibernate.collection.spi.CollectionSemanticsResolver;
|
|||
import org.hibernate.metamodel.internal.ManagedTypeRepresentationResolverStandard;
|
||||
import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
||||
/**
|
||||
|
@ -182,7 +179,7 @@ public interface MetadataBuildingOptions {
|
|||
*
|
||||
* @return The MultiTenancyStrategy
|
||||
*/
|
||||
MultiTenancyStrategy getMultiTenancyStrategy();
|
||||
boolean isMultiTenancyEnabled();
|
||||
|
||||
IdGeneratorStrategyInterpreter getIdGenerationTypeInterpreter();
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.hibernate.CustomEntityDirtinessStrategy;
|
|||
import org.hibernate.EntityNameResolver;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.TimeZoneStorageStrategy;
|
||||
import org.hibernate.boot.SchemaAutoTooling;
|
||||
|
@ -174,7 +173,7 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
|
|||
|
||||
boolean isOrderInsertsEnabled();
|
||||
|
||||
MultiTenancyStrategy getMultiTenancyStrategy();
|
||||
boolean isMultiTenancyEnabled();
|
||||
|
||||
CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
|
||||
|
||||
|
|
|
@ -1732,14 +1732,6 @@ public interface AvailableSettings {
|
|||
*/
|
||||
String USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS = "hibernate.use_entity_where_clause_for_collections";
|
||||
|
||||
/**
|
||||
* Strategy for multi-tenancy.
|
||||
|
||||
* @see org.hibernate.MultiTenancyStrategy
|
||||
* @since 4.0
|
||||
*/
|
||||
String MULTI_TENANT = "hibernate.multiTenancy";
|
||||
|
||||
/**
|
||||
* Names a {@link org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider} implementation to
|
||||
* use. As MultiTenantConnectionProvider is also a service, can be configured directly through the
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.hibernate.cfg;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.SchemaAutoTooling;
|
||||
import org.hibernate.boot.model.naming.Identifier;
|
||||
|
@ -79,7 +78,7 @@ public final class Settings {
|
|||
LOG.debugf( "Order SQL updates by primary key: %s", enabledDisabled( sessionFactoryOptions.isOrderUpdatesEnabled() ) );
|
||||
LOG.debugf( "Order SQL inserts for batching: %s", enabledDisabled( sessionFactoryOptions.isOrderInsertsEnabled() ) );
|
||||
|
||||
LOG.debugf( "multi-tenancy strategy : %s", sessionFactoryOptions.getMultiTenancyStrategy() );
|
||||
LOG.debugf( "multi-tenancy enabled : %s", sessionFactoryOptions.isMultiTenancyEnabled() );
|
||||
|
||||
LOG.debugf( "JTA Track by Thread: %s", enabledDisabled( sessionFactoryOptions.isJtaTrackByThread() ) );
|
||||
|
||||
|
@ -191,8 +190,8 @@ public final class Settings {
|
|||
return sessionFactoryOptions.isOrderInsertsEnabled();
|
||||
}
|
||||
|
||||
public MultiTenancyStrategy getMultiTenancyStrategy() {
|
||||
return sessionFactoryOptions.getMultiTenancyStrategy();
|
||||
public boolean isMultiTenancyEnabled() {
|
||||
return sessionFactoryOptions.isMultiTenancyEnabled();
|
||||
}
|
||||
public boolean isJtaTrackByThread() {
|
||||
return sessionFactoryOptions.isJtaTrackByThread();
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -105,8 +104,7 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
|
||||
@Override
|
||||
public ConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
final MultiTenancyStrategy strategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configurationValues );
|
||||
if ( strategy == MultiTenancyStrategy.DATABASE || strategy == MultiTenancyStrategy.SCHEMA ) {
|
||||
if ( configurationValues.containsKey( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER ) ) {
|
||||
// nothing to do, but given the separate hierarchies have to handle this here.
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.engine.jdbc.connections.internal;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
|
@ -41,8 +40,7 @@ public class MultiTenantConnectionProviderInitiator implements StandardServiceIn
|
|||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public MultiTenantConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
final MultiTenancyStrategy strategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configurationValues );
|
||||
if ( !strategy.requiresMultiTenantConnectionProvider() ) {
|
||||
if ( !configurationValues.containsKey( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER ) ) {
|
||||
// nothing to do, but given the separate hierarchies have to handle this here.
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.sql.SQLException;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
@ -246,10 +245,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
|
|||
}
|
||||
|
||||
private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues, ServiceRegistryImplementor registry) {
|
||||
final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy(
|
||||
configValues
|
||||
);
|
||||
if ( !multiTenancyStrategy.requiresMultiTenantConnectionProvider() ) {
|
||||
if ( !configValues.containsKey( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER ) ) {
|
||||
ConnectionProvider connectionProvider = registry.getService( ConnectionProvider.class );
|
||||
return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
|
||||
}
|
||||
|
@ -260,9 +256,9 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
|
|||
}
|
||||
|
||||
public static JdbcConnectionAccess buildBootstrapJdbcConnectionAccess(
|
||||
MultiTenancyStrategy multiTenancyStrategy,
|
||||
boolean multiTenancyEnabled,
|
||||
ServiceRegistryImplementor registry) {
|
||||
if ( !multiTenancyStrategy.requiresMultiTenantConnectionProvider() ) {
|
||||
if ( !multiTenancyEnabled ) {
|
||||
ConnectionProvider connectionProvider = registry.getService( ConnectionProvider.class );
|
||||
return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.engine.jdbc.internal;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.jdbc.LobCreationContext;
|
||||
|
@ -34,7 +34,7 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi
|
|||
private ServiceRegistryImplementor serviceRegistry;
|
||||
private JdbcEnvironment jdbcEnvironment;
|
||||
|
||||
private MultiTenancyStrategy multiTenancyStrategy;
|
||||
private boolean multiTenancyEnabled;
|
||||
|
||||
private SqlStatementLogger sqlStatementLogger;
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi
|
|||
this.jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
|
||||
assert jdbcEnvironment != null : "JdbcEnvironment was not found!";
|
||||
|
||||
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configValues );
|
||||
this.multiTenancyEnabled = configValues.containsKey( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER );
|
||||
|
||||
final boolean showSQL = ConfigurationHelper.getBoolean( Environment.SHOW_SQL, configValues, false );
|
||||
final boolean formatSQL = ConfigurationHelper.getBoolean( Environment.FORMAT_SQL, configValues, false );
|
||||
|
@ -65,7 +65,7 @@ public class JdbcServicesImpl implements JdbcServices, ServiceRegistryAwareServi
|
|||
|
||||
@Override
|
||||
public JdbcConnectionAccess getBootstrapJdbcConnectionAccess() {
|
||||
return JdbcEnvironmentInitiator.buildBootstrapJdbcConnectionAccess( multiTenancyStrategy, serviceRegistry );
|
||||
return JdbcEnvironmentInitiator.buildBootstrapJdbcConnectionAccess( multiTenancyEnabled, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.hibernate.Hibernate;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.SessionEventListener;
|
||||
import org.hibernate.SessionException;
|
||||
import org.hibernate.Transaction;
|
||||
|
@ -149,7 +148,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
|||
this.flushMode = options.getInitialSessionFlushMode();
|
||||
|
||||
this.tenantIdentifier = options.getTenantIdentifier();
|
||||
if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) {
|
||||
if ( !factory.getSettings().isMultiTenancyEnabled() ) {
|
||||
if ( tenantIdentifier != null ) {
|
||||
throw new HibernateException( "SessionFactory was not configured for multi-tenancy" );
|
||||
}
|
||||
|
|
|
@ -221,8 +221,8 @@ public final class FastSessionServices {
|
|||
this.useStreamForLobBinding = Environment.useStreamsForBinary() || dialect.useInputStreamToInsertBlob();
|
||||
this.preferredSqlTypeCodeForBoolean = sessionFactoryOptions.getPreferredSqlTypeCodeForBoolean();
|
||||
this.defaultTimeZoneStorageStrategy = sessionFactoryOptions.getDefaultTimeZoneStorageStrategy();
|
||||
this.requiresMultiTenantConnectionProvider = sf.getSettings().getMultiTenancyStrategy().requiresMultiTenantConnectionProvider();
|
||||
this.defaultJdbcBatchSize = sessionFactoryOptions.getJdbcBatchSize();
|
||||
this.requiresMultiTenantConnectionProvider = sf.getSettings().isMultiTenancyEnabled();
|
||||
|
||||
//Some "hot" services:
|
||||
this.connectionProvider = requiresMultiTenantConnectionProvider ? null : sr.getService( ConnectionProvider.class );
|
||||
|
|
|
@ -70,16 +70,12 @@ import org.hibernate.context.internal.ThreadLocalSessionContext;
|
|||
import org.hibernate.context.spi.CurrentSessionContext;
|
||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
|
||||
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.jndi.spi.JndiService;
|
||||
import org.hibernate.engine.profile.Association;
|
||||
import org.hibernate.engine.profile.Fetch;
|
||||
import org.hibernate.engine.profile.FetchProfile;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.FilterDefinition;
|
||||
import org.hibernate.engine.spi.SessionBuilderImplementor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -101,7 +97,6 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.RuntimeMetamodels;
|
||||
import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl;
|
||||
import org.hibernate.metamodel.model.domain.AllowableParameterType;
|
||||
|
@ -498,26 +493,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
getCache().prime( regionConfigs );
|
||||
}
|
||||
|
||||
private Object instantiate(String listenerImpl, ClassLoaderService classLoaderService) {
|
||||
try {
|
||||
return classLoaderService.classForName( listenerImpl ).newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new HibernateException( "Could not instantiate requested listener [" + listenerImpl + "]", e );
|
||||
}
|
||||
}
|
||||
|
||||
private JdbcConnectionAccess buildLocalConnectionAccess() {
|
||||
if ( settings.getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ) {
|
||||
final MultiTenantConnectionProvider mTenantConnectionProvider = serviceRegistry.getService( MultiTenantConnectionProvider.class );
|
||||
return new JdbcEnvironmentInitiator.MultiTenantConnectionProviderJdbcConnectionAccess( mTenantConnectionProvider );
|
||||
}
|
||||
else {
|
||||
final ConnectionProvider connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
|
||||
return new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess( connectionProvider );
|
||||
}
|
||||
}
|
||||
|
||||
public Session openSession() throws HibernateException {
|
||||
//The defaultSessionOpenOptions can't be used in some cases; for example when using a TenantIdentifierResolver.
|
||||
if ( this.defaultSessionOpenOptions != null ) {
|
||||
|
@ -627,7 +602,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
|
||||
@Override
|
||||
public DeserializationResolver getDeserializationResolver() {
|
||||
return (DeserializationResolver) () -> (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.findSessionFactory(
|
||||
return () -> (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.findSessionFactory(
|
||||
uuid,
|
||||
name
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue