From 7aab5f94836afef2c127197a7eec08b8e8532f9a Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 23 Dec 2021 14:45:13 +0100 Subject: [PATCH] Properly determine tenant resolver in HibernateMultiTenantConnectionProvider 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 --- ...HibernateMultiTenantConnectionProvider.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateMultiTenantConnectionProvider.java b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateMultiTenantConnectionProvider.java index c5fef6c9cc1e9..1455be9ea3932 100644 --- a/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateMultiTenantConnectionProvider.java +++ b/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateMultiTenantConnectionProvider.java @@ -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; @@ -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; /** @@ -107,20 +105,18 @@ private static ConnectionProvider resolveConnectionProvider(String persistenceUn * @return Current tenant resolver. */ private static InstanceHandle tenantResolver(String persistenceUnitName) { - InstanceHandle 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 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(); } }