|
1 | | -package io.quarkus.hibernate.orm.runtime.dev; |
| 1 | +package io.quarkus.hibernate.orm.dev; |
2 | 2 |
|
3 | 3 | import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE; |
4 | 4 |
|
5 | | -import java.util.Map; |
6 | | -import java.util.concurrent.ConcurrentHashMap; |
7 | | - |
8 | 5 | import org.hibernate.boot.Metadata; |
9 | 6 | import org.hibernate.boot.spi.BootstrapContext; |
10 | 7 | import org.hibernate.cfg.AvailableSettings; |
11 | 8 | import org.hibernate.engine.spi.SessionFactoryImplementor; |
12 | 9 | import org.hibernate.integrator.spi.Integrator; |
13 | 10 | import org.hibernate.service.spi.SessionFactoryServiceRegistry; |
14 | 11 |
|
| 12 | +import io.quarkus.hibernate.orm.runtime.PersistenceUnitsHolder; |
15 | 13 | import io.quarkus.hibernate.orm.runtime.boot.QuarkusPersistenceUnitDescriptor; |
16 | 14 |
|
17 | 15 | public class HibernateOrmDevIntegrator implements Integrator { |
18 | | - private static final Map<String, QuarkusPersistenceUnitDescriptor> puDescriptorMap = new ConcurrentHashMap<>(); |
19 | | - |
20 | | - public static void clearPuMap() { |
21 | | - puDescriptorMap.clear(); |
22 | | - } |
23 | | - |
24 | | - public static void mapPersistenceUnit(String pu, QuarkusPersistenceUnitDescriptor descriptor) { |
25 | | - puDescriptorMap.put(pu, descriptor); |
26 | | - } |
27 | | - |
28 | 16 | @Override |
29 | | - public void integrate(Metadata metadata, BootstrapContext bootstrapContext, |
30 | | - SessionFactoryImplementor sessionFactoryImplementor) { |
31 | | - String name = (String) sessionFactoryImplementor.getProperties() |
| 17 | + public void integrate(Metadata metadata, BootstrapContext bootstrapContext, SessionFactoryImplementor sf) { |
| 18 | + String name = (String) sf.getProperties() |
32 | 19 | .get(AvailableSettings.PERSISTENCE_UNIT_NAME); |
33 | 20 | HibernateOrmDevController.get().pushPersistenceUnit( |
34 | | - sessionFactoryImplementor, |
35 | | - puDescriptorMap.get(name), |
| 21 | + sf, |
| 22 | + getPersistenceUnitDescriptor(name, sf), |
36 | 23 | name, |
37 | 24 | metadata, |
38 | | - sessionFactoryImplementor.getServiceRegistry(), |
39 | | - (String) sessionFactoryImplementor.getProperties().get(JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE)); |
| 25 | + sf.getServiceRegistry(), |
| 26 | + (String) sf.getProperties().get(JAKARTA_HBM2DDL_LOAD_SCRIPT_SOURCE)); |
| 27 | + } |
| 28 | + |
| 29 | + private static QuarkusPersistenceUnitDescriptor getPersistenceUnitDescriptor(String name, SessionFactoryImplementor sf) { |
| 30 | + // This is not great but avoids needing to depend on reactive |
| 31 | + boolean isReactive = sf.getClass().getPackage().getName().contains("reactive"); |
| 32 | + return PersistenceUnitsHolder.getPersistenceUnitDescriptor(name, isReactive); |
40 | 33 | } |
41 | 34 |
|
42 | 35 | @Override |
|
0 commit comments