HHH-10964 : Fix missing currentTenantIdentifierResolver
1. Add missing sessionFactoryBuilder.applyCurrentTenantIdentifierResolver() .
2. Use getter instead of field for consistency .
(cherry picked from commit 5ea8997ca7
)
This commit is contained in:
parent
906341349b
commit
ed2c353717
|
@ -698,11 +698,14 @@ public class Configuration {
|
||||||
if ( getSessionFactoryObserver() != null ) {
|
if ( getSessionFactoryObserver() != null ) {
|
||||||
sessionFactoryBuilder.addSessionFactoryObservers( getSessionFactoryObserver() );
|
sessionFactoryBuilder.addSessionFactoryObservers( getSessionFactoryObserver() );
|
||||||
}
|
}
|
||||||
if ( entityNotFoundDelegate != null ) {
|
if ( getEntityNotFoundDelegate() != null ) {
|
||||||
sessionFactoryBuilder.applyEntityNotFoundDelegate( entityNotFoundDelegate );
|
sessionFactoryBuilder.applyEntityNotFoundDelegate( getEntityNotFoundDelegate() );
|
||||||
}
|
}
|
||||||
if ( entityTuplizerFactory != null ) {
|
if ( getEntityTuplizerFactory() != null ) {
|
||||||
sessionFactoryBuilder.applyEntityTuplizerFactory( entityTuplizerFactory );
|
sessionFactoryBuilder.applyEntityTuplizerFactory( getEntityTuplizerFactory() );
|
||||||
|
}
|
||||||
|
if ( getCurrentTenantIdentifierResolver() != null ) {
|
||||||
|
sessionFactoryBuilder.applyCurrentTenantIdentifierResolver( getCurrentTenantIdentifierResolver() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionFactoryBuilder.build();
|
return sessionFactoryBuilder.build();
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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.test.multitenancy.schema;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
|
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Vlad Mihalcea
|
||||||
|
*/
|
||||||
|
@TestForIssue(jiraKey = "HHH-10964")
|
||||||
|
public class TenantResolverConfigurationTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
|
private TestCurrentTenantIdentifierResolver currentTenantResolver = new TestCurrentTenantIdentifierResolver();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Configuration constructAndConfigureConfiguration() {
|
||||||
|
Configuration configuration = super.constructAndConfigureConfiguration();
|
||||||
|
configuration.setCurrentTenantIdentifierResolver( currentTenantResolver );
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfiguration() throws Exception {
|
||||||
|
assertSame(currentTenantResolver, sessionFactory().getCurrentTenantIdentifierResolver());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestCurrentTenantIdentifierResolver implements CurrentTenantIdentifierResolver {
|
||||||
|
private String currentTenantIdentifier;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validateExistingCurrentSessions() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resolveCurrentTenantIdentifier() {
|
||||||
|
return currentTenantIdentifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue