Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public static Annotation qualifier(String persistenceUnitName) {
}
}

public static <T> InjectableInstance<T> singleExtensionInstanceForPersistenceUnit(Class<T> beanType,
public static <T> InjectableInstance<T> singleExtensionInstanceForPersistenceUnit(
Class<T> beanType,
String persistenceUnitName,
Annotation... additionalQualifiers) {
InjectableInstance<T> instance = extensionInstanceForPersistenceUnit(beanType, persistenceUnitName,
Annotation... additionalQualifiers
) {
InjectableInstance<T> instance = extensionInstancesForPersistenceUnit(beanType, persistenceUnitName,
additionalQualifiers);
if (instance.isAmbiguous()) {
List<String> ambiguousClassNames = instance.handlesStream().map(h -> h.getBean().getBeanClass().getCanonicalName())
Expand All @@ -52,8 +54,11 @@ public static <T> InjectableInstance<T> singleExtensionInstanceForPersistenceUni
return instance;
}

public static <T> InjectableInstance<T> extensionInstanceForPersistenceUnit(Class<T> beanType, String persistenceUnitName,
Annotation... additionalQualifiers) {
public static <T> InjectableInstance<T> extensionInstancesForPersistenceUnit(
Class<T> beanType,
String persistenceUnitName,
Annotation... additionalQualifiers
) {
if (additionalQualifiers.length == 0) {
return Arc.container().select(beanType, new PersistenceUnitExtension.Literal(persistenceUnitName));
} else {
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note you'll need to update docs as well, to mention the new component types in that list:

==== Plugging in other custom components
The Quarkus extension for Hibernate ORM will automatically
inject components annotated with `@PersistenceUnitExtension` into Hibernate Search.
The annotation can optionally target a specific persistence unit with `@PersistenceUnitExtension(name = "nameOfYourPU")`.
This feature is available for the following component types:
`org.hibernate.Interceptor`::
See <<interceptors>>.
`org.hibernate.resource.jdbc.spi.StatementInspector`::
See <<statement_inspectors>>.
`org.hibernate.type.format.FormatMapper`::
See <<json_xml_serialization_deserialization>>.
`io.quarkus.hibernate.orm.runtime.tenant.TenantResolver`::
See <<multitenancy>>.
`io.quarkus.hibernate.orm.runtime.tenant.TenantConnectionResolver`::
See <<programmatically-resolving-tenants-connections>>.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.PersistenceUnitTransactionType;

Expand All @@ -39,6 +40,8 @@
import org.hibernate.boot.archive.scan.spi.Scanner;
import org.hibernate.boot.beanvalidation.BeanValidationIntegrator;
import org.hibernate.boot.internal.MetadataImpl;
import org.hibernate.boot.model.FunctionContributor;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.model.process.spi.ManagedResources;
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
import org.hibernate.boot.registry.StandardServiceRegistry;
Expand Down Expand Up @@ -162,19 +165,23 @@ public FastBootMetadataBuilder(final QuarkusPersistenceUnitDefinition puDefiniti
* of the destroyed service registry in PreconfiguredServiceRegistryBuilder.
*
*/
for (Class<? extends Service> postBuildProvidedService : ssrBuilder.getPostBuildProvidedServices()) {
providedServices.add(new ProvidedService(postBuildProvidedService,
standardServiceRegistry.getService(postBuildProvidedService)));
}
ssrBuilder.getPostBuildProvidedServices()
.forEach(serviceClass -> providedServices.add(
new ProvidedService(
serviceClass,
standardServiceRegistry.getService(serviceClass)
)));

final MetadataSources metadataSources = new MetadataSources(ssrBuilder.getBootstrapServiceRegistry());

applyMappingContributors(metadataSources);

// No need to populate annotatedClassNames/annotatedPackages: they are populated through scanning
// XML mappings, however, cannot be contributed through the scanner,
// which only allows specifying mappings as files/resources,
// and we really don't want any XML parsing here...
for (RecordableXmlMapping mapping : puDefinition.getXmlMappings()) {
metadataSources.addXmlBinding(mapping.toHibernateOrmBinding());
}
puDefinition.getXmlMappings()
.forEach(mapping -> metadataSources.addXmlBinding(mapping.toHibernateOrmBinding()));

this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources
.getMetadataBuilder(standardServiceRegistry);
Expand All @@ -188,6 +195,9 @@ public FastBootMetadataBuilder(final QuarkusPersistenceUnitDefinition puDefiniti

applyMetadataBuilderContributor();

applyTypeContributors();
applyFunctionContributors();

// Unable to automatically handle:
// AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING,
// AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION,
Expand Down Expand Up @@ -645,6 +655,10 @@ protected void populate(MetadataBuilder metamodelBuilder, List<CacheRegionDefini
}
}

private void applyMappingContributors(MetadataSources metadataSources) {

}

private void applyMetadataBuilderContributor() {
Object metadataBuilderContributorSetting = buildTimeSettings
.get(JpaSettings.METADATA_BUILDER_CONTRIBUTOR);
Comment on lines 654 to 656
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remember to deprecate the metadata build contributor, now that you're introducing an alternative.

A @Deprecated annotation + @deprecated javadoc tag there would do the trick:

Optional<@WithConverter(TrimmedStringConverter.class) String> metadataBuilderContributor();

Expand All @@ -663,6 +677,16 @@ private void applyMetadataBuilderContributor() {
}
}

private void applyTypeContributors() {
PersistenceUnitUtil.extensionInstancesForPersistenceUnit(TypeContributor.class, persistenceUnit.getName())
.stream().forEach(metamodelBuilder::applyTypes);
}

private void applyFunctionContributors() {
PersistenceUnitUtil.extensionInstancesForPersistenceUnit(FunctionContributor.class, persistenceUnit.getName())
.stream().forEach(metamodelBuilder::applyFunctions);
}

@SuppressWarnings("unchecked")
private <T> T loadSettingInstance(String settingName, Object settingValue, Class<T> clazz) {
T instance = null;
Expand Down