Skip to content

Commit

Permalink
Properly determine tenant resolver in HibernateMultiTenantConnectionP…
Browse files Browse the repository at this point in the history
…rovider

When migrating to the new annotation, this was forgotten somehow so it's
still using the old annotation.
Moving to the method supporting both the new annotation and the old one.

Fixes #21265

(cherry picked from commit 7aab5f9)
  • Loading branch information
gsmet committed Dec 23, 2021
1 parent e99b74b commit 1ceaa1a
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Default;

import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
Expand All @@ -17,7 +16,6 @@
import io.quarkus.arc.InjectableInstance;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.ManagedContext;
import io.quarkus.hibernate.orm.PersistenceUnit.PersistenceUnitLiteral;
import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;

/**
Expand Down Expand Up @@ -107,20 +105,18 @@ private static ConnectionProvider resolveConnectionProvider(String persistenceUn
* @return Current tenant resolver.
*/
private static InstanceHandle<TenantResolver> tenantResolver(String persistenceUnitName) {
InstanceHandle<TenantResolver> resolverInstance;
if (PersistenceUnitUtil.isDefaultPersistenceUnit(persistenceUnitName)) {
resolverInstance = Arc.container().instance(TenantResolver.class, Default.Literal.INSTANCE);
} else {
resolverInstance = Arc.container().instance(TenantResolver.class,
new PersistenceUnitLiteral(persistenceUnitName));
}
if (!resolverInstance.isAvailable()) {
InjectableInstance<TenantResolver> instance = PersistenceUnitUtil
.legacySingleExtensionInstanceForPersistenceUnit(
TenantResolver.class, persistenceUnitName);

if (instance.isUnsatisfied()) {
throw new IllegalStateException(String.format(Locale.ROOT,
"No instance of %1$s was found for persistence unit %2$s. "
+ "You need to create an implementation for this interface to allow resolving the current tenant identifier.",
TenantResolver.class.getSimpleName(), persistenceUnitName));
}
return resolverInstance;

return instance.getHandle();
}

}

0 comments on commit 1ceaa1a

Please sign in to comment.