Skip to content

Commit

Permalink
Don't even try to resolve @SearchExtension for runtime configuration …
Browse files Browse the repository at this point in the history
…when Hibernate Search is disabled
  • Loading branch information
yrodiere committed Jul 20, 2022
1 parent 060c61d commit 4b69107
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void buildForPersistenceUnit(HibernateSearchElasticsearchRecorder record
// we need a runtime listener even when Hibernate Search is disabled,
// just to let Hibernate Search boot up until the point where it checks whether it's enabled or not
runtimeIntegrations.produce(new HibernateOrmIntegrationRuntimeConfiguredBuildItem(HIBERNATE_SEARCH_ELASTICSEARCH,
persistenceUnitName).setInitListener(recorder.createDisabledRuntimeInitListener(persistenceUnitName)));
persistenceUnitName).setInitListener(recorder.createDisabledRuntimeInitListener()));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener(
backendAndIndexNamesForSearchExtensions, integrationRuntimeInitListeners);
}

public HibernateOrmIntegrationRuntimeInitListener createDisabledRuntimeInitListener(String persistenceUnitName) {
return new HibernateSearchIntegrationRuntimeInitListener(persistenceUnitName, null, Collections.emptyMap(),
Collections.emptyList());
public HibernateOrmIntegrationRuntimeInitListener createDisabledRuntimeInitListener() {
return new HibernateSearchIntegrationRuntimeInitDisabledListener();
}

public Supplier<SearchMapping> searchMappingSupplier(HibernateSearchElasticsearchRuntimeConfig runtimeConfig,
Expand Down Expand Up @@ -261,6 +260,28 @@ private void contributeBackendIndexBuildTimeProperties(BiConsumer<String, Object
}
}

private static final class HibernateSearchIntegrationRuntimeInitDisabledListener
implements HibernateOrmIntegrationRuntimeInitListener {

private HibernateSearchIntegrationRuntimeInitDisabledListener() {
}

@Override
public void contributeRuntimeProperties(BiConsumer<String, Object> propertyCollector) {
// Not strictly necessary since this should be set during static init,
// but let's be on the safe side.
propertyCollector.accept(HibernateOrmMapperSettings.ENABLED, false);
}

@Override
public List<StandardServiceInitiator<?>> contributeServiceInitiators() {
return List.of(
// The service must be initiated even if Hibernate Search is disabled,
// because it's also responsible for determining that Hibernate Search is disabled.
new HibernateSearchPreIntegrationService.Initiator());
}
}

private static final class HibernateSearchIntegrationRuntimeInitListener
implements HibernateOrmIntegrationRuntimeInitListener {

Expand Down

0 comments on commit 4b69107

Please sign in to comment.