99import static io .quarkus .hibernate .orm .deployment .util .HibernateProcessorUtil .jsonMapperKind ;
1010import static io .quarkus .hibernate .orm .deployment .util .HibernateProcessorUtil .setDialectAndStorageEngine ;
1111import static io .quarkus .hibernate .orm .deployment .util .HibernateProcessorUtil .xmlMapperKind ;
12+ import static io .quarkus .hibernate .orm .runtime .PersistenceUnitUtil .DEFAULT_PERSISTENCE_UNIT_NAME ;
1213
1314import java .io .IOException ;
1415import java .net .URL ;
144145import io .quarkus .hibernate .validator .spi .BeanValidationTraversableResolverBuildItem ;
145146import io .quarkus .panache .hibernate .common .deployment .HibernateEnhancersRegisteredBuildItem ;
146147import io .quarkus .panache .hibernate .common .deployment .HibernateModelClassCandidatesForFieldAccessBuildItem ;
148+ import io .quarkus .reactive .datasource .spi .ReactiveDataSourceBuildItem ;
147149import io .quarkus .runtime .LaunchMode ;
148150import io .quarkus .runtime .configuration .ConfigurationException ;
149151import net .bytebuddy .description .type .TypeDescription ;
@@ -327,6 +329,7 @@ public void configurationDescriptorBuilding(
327329 ImpliedBlockingPersistenceUnitTypeBuildItem impliedPU ,
328330 List <PersistenceXmlDescriptorBuildItem > persistenceXmlDescriptors ,
329331 List <JdbcDataSourceBuildItem > jdbcDataSources ,
332+ List <ReactiveDataSourceBuildItem > reactiveDataSources ,
330333 ApplicationArchivesBuildItem applicationArchivesBuildItem ,
331334 LaunchModeBuildItem launchMode ,
332335 List <AdditionalJpaModelBuildItem > additionalJpaModelBuildItems ,
@@ -380,7 +383,8 @@ public void configurationDescriptorBuilding(
380383
381384 if (impliedPU .shouldGenerateImpliedBlockingPersistenceUnit ()) {
382385 handleHibernateORMWithNoPersistenceXml (hibernateOrmConfig , index , persistenceXmlDescriptors ,
383- jdbcDataSources , applicationArchivesBuildItem , launchMode .getLaunchMode (), additionalJpaModelBuildItems ,
386+ jdbcDataSources , reactiveDataSources , applicationArchivesBuildItem , launchMode .getLaunchMode (),
387+ additionalJpaModelBuildItems ,
384388 jpaModel , capabilities ,
385389 systemProperties , nativeImageResources , hotDeploymentWatchedFiles , persistenceUnitDescriptors ,
386390 reflectiveMethods , unremovableBeans , dbKindMetadataBuildItems );
@@ -842,6 +846,7 @@ private void handleHibernateORMWithNoPersistenceXml(
842846 CombinedIndexBuildItem index ,
843847 List <PersistenceXmlDescriptorBuildItem > descriptors ,
844848 List <JdbcDataSourceBuildItem > jdbcDataSources ,
849+ List <ReactiveDataSourceBuildItem > reactiveDataSources ,
845850 ApplicationArchivesBuildItem applicationArchivesBuildItem ,
846851 LaunchMode launchMode ,
847852 List <AdditionalJpaModelBuildItem > additionalJpaModelBuildItems ,
@@ -907,7 +912,7 @@ private void handleHibernateORMWithNoPersistenceXml(
907912 hibernateOrmConfig .defaultPersistenceUnit (),
908913 modelForDefaultPersistenceUnit .allModelClassAndPackageNames (),
909914 jpaModel .getXmlMappings (PersistenceUnitUtil .DEFAULT_PERSISTENCE_UNIT_NAME ),
910- jdbcDataSources , applicationArchivesBuildItem , launchMode , capabilities ,
915+ jdbcDataSources , reactiveDataSources , applicationArchivesBuildItem , launchMode , capabilities ,
911916 systemProperties , nativeImageResources , hotDeploymentWatchedFiles , persistenceUnitDescriptors ,
912917 reflectiveMethods , unremovableBeans , storageEngineCollector , dbKindMetadataBuildItems );
913918 } else if (!modelForDefaultPersistenceUnit .entityClassNames ().isEmpty ()
@@ -939,7 +944,7 @@ private void handleHibernateORMWithNoPersistenceXml(
939944 hibernateOrmConfig , jpaModel , persistenceUnitName , persistenceUnitEntry .getValue (),
940945 model == null ? Collections .emptySet () : model .allModelClassAndPackageNames (),
941946 jpaModel .getXmlMappings (persistenceUnitName ),
942- jdbcDataSources , applicationArchivesBuildItem , launchMode , capabilities ,
947+ jdbcDataSources , reactiveDataSources , applicationArchivesBuildItem , launchMode , capabilities ,
943948 systemProperties , nativeImageResources , hotDeploymentWatchedFiles , persistenceUnitDescriptors ,
944949 reflectiveMethods , unremovableBeans , storageEngineCollector , dbKindMetadataBuildItems );
945950 }
@@ -957,6 +962,7 @@ private static void producePersistenceUnitDescriptorFromConfig(
957962 Set <String > modelClassesAndPackages ,
958963 List <RecordableXmlMapping > xmlMappings ,
959964 List <JdbcDataSourceBuildItem > jdbcDataSources ,
965+ List <ReactiveDataSourceBuildItem > reactiveDataSources ,
960966 ApplicationArchivesBuildItem applicationArchivesBuildItem ,
961967 LaunchMode launchMode ,
962968 Capabilities capabilities ,
@@ -968,8 +974,32 @@ private static void producePersistenceUnitDescriptorFromConfig(
968974 BuildProducer <UnremovableBeanBuildItem > unremovableBeans ,
969975 Set <String > storageEngineCollector ,
970976 List <DatabaseKindDialectBuildItem > dbKindMetadataBuildItems ) {
971- Optional <JdbcDataSourceBuildItem > jdbcDataSource = findJdbcDataSource (persistenceUnitName , persistenceUnitConfig ,
972- jdbcDataSources );
977+
978+ Optional <JdbcDataSourceBuildItem > jdbcDataSource = HibernateDataSourceUtil .findDataSourceWithNameDefault (
979+ persistenceUnitName ,
980+ jdbcDataSources ,
981+ JdbcDataSourceBuildItem ::getName ,
982+ JdbcDataSourceBuildItem ::isDefault , persistenceUnitConfig .datasource ());
983+
984+ Optional <ReactiveDataSourceBuildItem > reactiveDataSource = HibernateDataSourceUtil .findDataSourceWithNameDefault (
985+ persistenceUnitName ,
986+ reactiveDataSources ,
987+ ReactiveDataSourceBuildItem ::getName ,
988+ ReactiveDataSourceBuildItem ::isDefault , persistenceUnitConfig .datasource ());
989+
990+ if (jdbcDataSource .isEmpty () && reactiveDataSource .isPresent ()) {
991+ LOG .debugf ("The datasource '%s' is only reactive, do not create this PU '%s' as blocking" ,
992+ persistenceUnitConfig .datasource ().orElse (DEFAULT_PERSISTENCE_UNIT_NAME ), persistenceUnitName );
993+ return ;
994+ }
995+
996+ boolean explicitDataSource = persistenceUnitConfig .datasource ().isPresent ();
997+ if (jdbcDataSource .isEmpty () && explicitDataSource ) {
998+ String dataSourceName = persistenceUnitConfig .datasource ().get ();
999+ throw PersistenceUnitUtil .unableToFindDataSource (persistenceUnitName , dataSourceName ,
1000+ DataSourceUtil .dataSourceNotConfigured (dataSourceName ));
1001+ }
1002+
9731003 Optional <String > dataSourceName = jdbcDataSource .map (JdbcDataSourceBuildItem ::getName );
9741004
9751005 QuarkusPersistenceUnitDescriptor descriptor = new QuarkusPersistenceUnitDescriptor (
@@ -1099,25 +1129,6 @@ private static void collectDialectConfigForPersistenceXml(String persistenceUnit
10991129 }
11001130 }
11011131
1102- private static Optional <JdbcDataSourceBuildItem > findJdbcDataSource (String persistenceUnitName ,
1103- HibernateOrmConfigPersistenceUnit persistenceUnitConfig , List <JdbcDataSourceBuildItem > jdbcDataSources ) {
1104- if (persistenceUnitConfig .datasource ().isPresent ()) {
1105- String dataSourceName = persistenceUnitConfig .datasource ().get ();
1106- return Optional .of (jdbcDataSources .stream ()
1107- .filter (i -> dataSourceName .equals (i .getName ()))
1108- .findFirst ()
1109- .orElseThrow (() -> PersistenceUnitUtil .unableToFindDataSource (persistenceUnitName , dataSourceName ,
1110- DataSourceUtil .dataSourceNotConfigured (dataSourceName ))));
1111- } else if (PersistenceUnitUtil .isDefaultPersistenceUnit (persistenceUnitName )) {
1112- return jdbcDataSources .stream ()
1113- .filter (i -> i .isDefault ())
1114- .findFirst ();
1115- } else {
1116- // if it's not the default persistence unit, we mandate an explicit datasource to prevent common errors
1117- return Optional .empty ();
1118- }
1119- }
1120-
11211132 @ SuppressWarnings ("deprecation" )
11221133 private void enhanceEntities (final JpaModelBuildItem jpaModel ,
11231134 BuildProducer <BytecodeTransformerBuildItem > transformers ,
0 commit comments