Skip to content

Commit

Permalink
[quarkusio#28576] Allow assigning entities to the Hibernate Reactive …
Browse files Browse the repository at this point in the history
…PU explicitly
  • Loading branch information
yrodiere authored and tmihalac committed Oct 27, 2022
1 parent 242d688 commit 7ff7fb5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ private void enhanceEntities(final JpaModelBuildItem jpaModel,
}
}

private static Map<String, Set<String>> getModelClassesAndPackagesPerPersistenceUnits(HibernateOrmConfig hibernateOrmConfig,
public static Map<String, Set<String>> getModelClassesAndPackagesPerPersistenceUnits(HibernateOrmConfig hibernateOrmConfig,
JpaModelBuildItem jpaModel, IndexView index, boolean enableDefaultPersistenceUnit) {
Map<String, Set<String>> modelClassesAndPackagesPerPersistenceUnits = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.SharedCacheMode;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void build(RecorderContext recorderContext,

@BuildStep
public void buildReactivePersistenceUnit(
HibernateOrmConfig hibernateOrmConfig,
HibernateOrmConfig hibernateOrmConfig, CombinedIndexBuildItem index,
DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig,
List<PersistenceXmlDescriptorBuildItem> persistenceXmlDescriptors,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
Expand Down Expand Up @@ -154,7 +155,7 @@ public void buildReactivePersistenceUnit(
final String dbKind = dbKindOptional.get();
HibernateOrmConfigPersistenceUnit persistenceUnitConfig = hibernateOrmConfig.defaultPersistenceUnit;
ParsedPersistenceXmlDescriptor reactivePU = generateReactivePersistenceUnit(
hibernateOrmConfig, persistenceUnitConfig, jpaModel,
hibernateOrmConfig, index, persistenceUnitConfig, jpaModel,
dbKind, applicationArchivesBuildItem, launchMode.getLaunchMode(),
systemProperties, nativeImageResources, hotDeploymentWatchedFiles, dbKindDialectBuildItems);

Expand Down Expand Up @@ -202,8 +203,16 @@ PersistenceProviderSetUpBuildItem setUpPersistenceProviderAndWaitForVertxPool(Hi
* - Any JDBC-only configuration settings are removed
* - If we ever add any Reactive-only config settings, they can be set here
*/
// TODO this whole method is really just a hack that duplicates
// io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor.handleHibernateORMWithNoPersistenceXml
// and customizes it for Hibernate Reactive.
// we should work on a way to merge the two methods while still having some behavior specific to
// HR/ORM, because it's likely the HR implementation is missing some features,
// and we've seen in the past that features we add to handleHibernateORMWithNoPersistenceXml
// tend not to be added here.
// See https://github.com/quarkusio/quarkus/issues/28629.
private static ParsedPersistenceXmlDescriptor generateReactivePersistenceUnit(
HibernateOrmConfig hibernateOrmConfig,
HibernateOrmConfig hibernateOrmConfig, CombinedIndexBuildItem index,
HibernateOrmConfigPersistenceUnit persistenceUnitConfig,
JpaModelBuildItem jpaModel,
String dbKind,
Expand All @@ -230,7 +239,26 @@ private static ParsedPersistenceXmlDescriptor generateReactivePersistenceUnit(
desc.setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL);
desc.getProperties().setProperty(AvailableSettings.DIALECT, dialect);
desc.setExcludeUnlistedClasses(true);
desc.addClasses(new ArrayList<>(jpaModel.getAllModelClassNames()));

Map<String, Set<String>> modelClassesAndPackagesPerPersistencesUnits = HibernateOrmProcessor
.getModelClassesAndPackagesPerPersistenceUnits(hibernateOrmConfig, jpaModel, index.getIndex(), true);
Set<String> nonDefaultPUWithModelClassesOrPackages = modelClassesAndPackagesPerPersistencesUnits.entrySet().stream()
.filter(e -> !PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME.equals(e.getKey()) && !e.getValue().isEmpty())
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
if (!nonDefaultPUWithModelClassesOrPackages.isEmpty()) {
// Not supported yet; see https://github.com/quarkusio/quarkus/issues/21110
LOG.warnf("Entities are affected to non-default Hibernate Reactive persistence units %s."
+ " Since Hibernate Reactive only works with the default persistence unit, those entities will be ignored.",
nonDefaultPUWithModelClassesOrPackages);
}
Set<String> modelClassesAndPackages = modelClassesAndPackagesPerPersistencesUnits
.getOrDefault(PersistenceUnitUtil.DEFAULT_PERSISTENCE_UNIT_NAME, Collections.emptySet());
if (modelClassesAndPackages.isEmpty()) {
LOG.warnf("Could not find any entities affected to the Hibernate Reactive persistence unit.");
} else {
desc.addClasses(new ArrayList<>(modelClassesAndPackages));
}

// The storage engine has to be set as a system property.
if (persistenceUnitConfig.dialect.storageEngine.isPresent()) {
Expand Down

0 comments on commit 7ff7fb5

Please sign in to comment.