From 1f13181a7efc204b694b895fee06d7ae1c6bbb3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 22 Jun 2023 17:19:20 +0200 Subject: [PATCH] Hibernate Search: Add support for new outbox-polling properties in 6.2 --- .../hibernate-search-orm-elasticsearch.adoc | 18 ++ ...HibernateSearchOutboxPollingProcessor.java | 5 +- .../configuration/ConfigPropertiesTest.java | 75 ++++++++ ...ateSearchOutboxPollingBuildTimeConfig.java | 30 ++++ ...PollingBuildTimeConfigPersistenceUnit.java | 167 ++++++++++++++++++ ...ibernateSearchOutboxPollingConfigUtil.java | 10 ++ .../HibernateSearchOutboxPollingRecorder.java | 73 ++++++++ 7 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfig.java create mode 100644 extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit.java diff --git a/docs/src/main/asciidoc/hibernate-search-orm-elasticsearch.adoc b/docs/src/main/asciidoc/hibernate-search-orm-elasticsearch.adoc index f13fcfed27cdc9..9d97bf49501c2b 100644 --- a/docs/src/main/asciidoc/hibernate-search-orm-elasticsearch.adoc +++ b/docs/src/main/asciidoc/hibernate-search-orm-elasticsearch.adoc @@ -894,6 +894,24 @@ then no worries: the entities required by Hibernate Search will be included in t * Otherwise, you must link:{hibernate-search-doc-prefix}#coordination-outbox-polling-schema[manually alter your schema to add the necessary tables/sequences]. +[NOTE] +==== +The database schema Hibernate Search will expect for outbox-polling coordination +may be customized through the following configuration properties: + +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.catalog[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.catalog`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.schema[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.schema`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.table[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.table`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-gen-strategy[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-gen-strategy`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-type[`quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-type`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.catalog[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.catalog`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.schema[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.schema`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.table[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.table`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-gen-strategy[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-gen-strategy`] +* link:#quarkus-hibernate-search-orm-elasticsearch-coordination-outboxpolling_quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-type[`quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-type`] + +==== + Once you are done with the above, you're ready to use Hibernate Search with an outbox. Don't change any code, and just start your application: it will automatically detect when multiple applications are connected to the same database, diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java b/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java index c98d6c8d0ea195..80d1eefb66146f 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/deployment/HibernateSearchOutboxPollingProcessor.java @@ -14,6 +14,7 @@ import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem; +import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingBuildTimeConfig; import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingRecorder; import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingRuntimeConfig; import io.quarkus.hibernate.search.orm.elasticsearch.deployment.HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem; @@ -43,6 +44,7 @@ void registerInternalModel(BuildProducer addi @BuildStep @Record(ExecutionTime.STATIC_INIT) void setStaticConfig(HibernateSearchOutboxPollingRecorder recorder, + HibernateSearchOutboxPollingBuildTimeConfig buildTimeConfig, List configuredPersistenceUnits, BuildProducer staticConfigured) { for (HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem configuredPersistenceUnit : configuredPersistenceUnits) { @@ -51,7 +53,8 @@ void setStaticConfig(HibernateSearchOutboxPollingRecorder recorder, } String puName = configuredPersistenceUnit.getPersistenceUnitName(); staticConfigured.produce(new HibernateSearchIntegrationStaticConfiguredBuildItem( - HIBERNATE_SEARCH_ORM_COORDINATION_OUTBOX_POLLING, puName, null) + HIBERNATE_SEARCH_ORM_COORDINATION_OUTBOX_POLLING, puName, + recorder.createStaticInitListener(buildTimeConfig, puName)) // Additional entities such as Agent and OutboxEvent are defined through XML // (because there's no other way). .setXmlMappingRequired(true)); diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/test/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/test/configuration/ConfigPropertiesTest.java b/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/test/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/test/configuration/ConfigPropertiesTest.java index 69bc445beff936..6e67f9581543d2 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/test/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/test/configuration/ConfigPropertiesTest.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/deployment/src/test/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/test/configuration/ConfigPropertiesTest.java @@ -9,6 +9,7 @@ import org.hibernate.SessionFactory; import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.HibernateOrmMapperOutboxPollingSettings; +import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.UuidGenerationStrategy; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.jupiter.api.Test; @@ -32,6 +33,20 @@ public class ConfigPropertiesTest { .addPackage(IndexedEntity.class.getPackage()) .addPackage(IndexedEntityForPU1.class.getPackage())) .withConfigurationResource("application-multiple-persistence-units.properties") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.catalog", "myagentcatalog") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.schema", "myagentschema") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.table", "myagenttable") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-gen-strategy", "random") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.agent.uuid-type", "uuid-char") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.catalog", + "myoutboxeventcatalog") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.schema", + "myoutboxeventschema") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.table", + "myoutboxeventtable") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-gen-strategy", + "time") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.entity.mapping.outbox-event.uuid-type", "uuid-binary") .overrideConfigKey("quarkus.hibernate-search-orm.coordination.event-processor.enabled", "false") .overrideConfigKey("quarkus.hibernate-search-orm.coordination.event-processor.shards.total-count", "10") .overrideConfigKey("quarkus.hibernate-search-orm.coordination.event-processor.shards.assigned", "1,2") @@ -44,6 +59,28 @@ public class ConfigPropertiesTest { .overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.polling-interval", "0.048S") .overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-interval", "0.049S") .overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-expiration", "50S") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-interval", "0.049S") + .overrideConfigKey("quarkus.hibernate-search-orm.coordination.mass-indexer.pulse-expiration", "50S") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.catalog", + "myagentcatalogpu1") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.schema", + "myagentschemapu1") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.table", + "myagenttablepu1") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.uuid-gen-strategy", + "time") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.agent.uuid-type", + "uuid-binary") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.catalog", + "myoutboxeventcatalogpu1") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.schema", + "myoutboxeventschemapu1") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.table", + "myoutboxeventtablepu1") + .overrideConfigKey( + "quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.uuid-gen-strategy", "random") + .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.entity.mapping.outbox-event.uuid-type", + "uuid-char") .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.event-processor.enabled", "false") .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.event-processor.shards.total-count", "110") .overrideConfigKey("quarkus.hibernate-search-orm.\"pu1\".coordination.event-processor.shards.assigned", "11,12") @@ -100,6 +137,24 @@ public class ConfigPropertiesTest { public void root() { assertThat(sessionFactory.getProperties()) .contains( + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_CATALOG, + "myagentcatalog"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_SCHEMA, + "myagentschema"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_TABLE, "myagenttable"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_GEN_STRATEGY, + UuidGenerationStrategy.RANDOM), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_TYPE, "uuid-char"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_CATALOG, + "myoutboxeventcatalog"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_SCHEMA, + "myoutboxeventschema"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_TABLE, + "myoutboxeventtable"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_GEN_STRATEGY, + UuidGenerationStrategy.TIME), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_TYPE, + "uuid-binary"), entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_ENABLED, false), entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_TOTAL_COUNT, 10), entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_ASSIGNED, @@ -119,6 +174,26 @@ public void root() { public void perNamedPersistenceUnit() { assertThat(sessionFactoryForNamedPU1.getProperties()) .contains( + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_CATALOG, + "myagentcatalogpu1"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_SCHEMA, + "myagentschemapu1"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_TABLE, + "myagenttablepu1"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_GEN_STRATEGY, + UuidGenerationStrategy.TIME), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_AGENT_UUID_TYPE, + "uuid-binary"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_CATALOG, + "myoutboxeventcatalogpu1"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_SCHEMA, + "myoutboxeventschemapu1"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_TABLE, + "myoutboxeventtablepu1"), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_GEN_STRATEGY, + UuidGenerationStrategy.RANDOM), + entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_ENTITY_MAPPING_OUTBOXEVENT_UUID_TYPE, + "uuid-char"), entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_ENABLED, false), entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_TOTAL_COUNT, 110), entry(HibernateOrmMapperOutboxPollingSettings.COORDINATION_EVENT_PROCESSOR_SHARDS_ASSIGNED, diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfig.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfig.java new file mode 100644 index 00000000000000..3df1613cce9bcb --- /dev/null +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfig.java @@ -0,0 +1,30 @@ +package io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime; + +import java.util.Map; + +import io.quarkus.runtime.annotations.ConfigDocMapKey; +import io.quarkus.runtime.annotations.ConfigDocSection; +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithParentName; + +@ConfigMapping(prefix = "quarkus.hibernate-search-orm") +@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) +public interface HibernateSearchOutboxPollingBuildTimeConfig { + + /** + * Configuration for the default persistence unit. + */ + @WithParentName + HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit defaultPersistenceUnit(); + + /** + * Configuration for additional named persistence units. + */ + @ConfigDocSection + @ConfigDocMapKey("persistence-unit-name") + @WithParentName + Map persistenceUnits(); + +} diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit.java new file mode 100644 index 00000000000000..485bc201a74b5a --- /dev/null +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit.java @@ -0,0 +1,167 @@ +package io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime; + +import java.util.Optional; + +import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.UuidGenerationStrategy; + +import io.quarkus.runtime.annotations.ConfigDocDefault; +import io.quarkus.runtime.annotations.ConfigDocSection; +import io.quarkus.runtime.annotations.ConfigGroup; +import io.smallrye.config.WithName; + +@ConfigGroup +public interface HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit { + + /** + * Configuration for coordination between threads or application instances. + */ + CoordinationConfig coordination(); + + @ConfigGroup + interface CoordinationConfig { + + /** + * Configuration for the mapping of entities used for outbox-polling coordination. + */ + @ConfigDocSection + @WithName("entity.mapping") + EntityMappingConfig entityMapping(); + + } + + @ConfigGroup + interface EntityMappingConfig { + + /** + * Configuration for the "agent" entity mapping. + */ + EntityMappingAgentConfig agent(); + + /** + * Configuration for the "outbox event" entity mapping. + */ + EntityMappingOutboxEventConfig outboxEvent(); + + } + + @ConfigGroup + interface EntityMappingAgentConfig { + + /** + * The database catalog to use for the agent table. + * + * @asciidoclet + */ + @ConfigDocDefault("Default catalog configured in Hibernate ORM") + Optional catalog(); + + /** + * The schema catalog to use for the agent table. + * + * @asciidoclet + */ + @ConfigDocDefault("Default catalog configured in Hibernate ORM") + Optional schema(); + + /** + * The name of the agent table. + * + * @asciidoclet + */ + @ConfigDocDefault("HSEARCH_AGENT") + Optional table(); + + /** + * The UUID generator strategy used for the agent table. + * + * Available strategies: + * + * * `auto` (the default) is the same as `random` which uses `UUID#randomUUID()`. + * * `time` is an IP based strategy consistent with IETF RFC 4122. + * + * @asciidoclet + */ + @ConfigDocDefault("auto") + Optional uuidGenStrategy(); + + /** + * The name of the Hibernate ORM basic type used for representing an UUID in the agent table. + * + * Refer to + * https://docs.jboss.org/hibernate/orm/6.2/userguide/html_single/Hibernate_User_Guide.html#basic-legacy-provided[this + * section of the Hibernate ORM documentation] + * to see the list of available UUID representations provided by Hibernate ORM. + * + * A user defined type can also be supplied. + * + * Defaults to the special value `default`, which will result into one of `uuid`/`uuid-binary`/`uuid-char` + * depending on the database kind. + * + * @asciidoclet + */ + @ConfigDocDefault("uuid/uuid-binary/uuid-char depending on the database kind") + Optional uuidType(); + + } + + @ConfigGroup + interface EntityMappingOutboxEventConfig { + + /** + * The database catalog to use for the outbox event table. + * + * @asciidoclet + */ + @ConfigDocDefault("Default catalog configured in Hibernate ORM") + Optional catalog(); + + /** + * The schema catalog to use for the outbox event table. + * + * @asciidoclet + */ + @ConfigDocDefault("Default schema configured in Hibernate ORM") + Optional schema(); + + /** + * The name of the outbox event table. + * + * @asciidoclet + */ + @ConfigDocDefault("HSEARCH_OUTBOX_EVENT") + Optional table(); + + /** + * The UUID generator strategy used for the outbox event table. + * + * Available strategies: + * + * * `auto` (the default) is the same as `random` which uses `UUID#randomUUID()`. + * * `time` is an IP based strategy consistent with IETF RFC 4122. + * + * @asciidoclet + */ + @ConfigDocDefault("auto") + Optional uuidGenStrategy(); + + /** + * The name of the Hibernate ORM basic type used for representing an UUID in the outbox event table. + * + * Refer to + * https://docs.jboss.org/hibernate/orm/6.2/userguide/html_single/Hibernate_User_Guide.html#basic-legacy-provided[this + * section of the Hibernate ORM documentation] + * to see the list of available UUID representations provided by Hibernate ORM. + * + * A user defined type can also be supplied. + * + * Defaults to the special value `default`, which will result into one of `uuid`/`uuid-binary`/`uuid-char` + * depending on the database kind. + * + * @asciidoclet + */ + @ConfigDocDefault("uuid/uuid-binary/uuid-char depending on the database kind") + Optional uuidType(); + + } + +} diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingConfigUtil.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingConfigUtil.java index b1eb98900b199d..db1557c01f90b7 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingConfigUtil.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingConfigUtil.java @@ -12,6 +12,16 @@ public final class HibernateSearchOutboxPollingConfigUtil { private HibernateSearchOutboxPollingConfigUtil() { } + public static void addCoordinationConfig(BiConsumer propertyCollector, + String configPath, T value) { + addCoordinationConfig(propertyCollector, null, configPath, value); + } + + public static void addCoordinationConfig(BiConsumer propertyCollector, String configPath, + Optional value) { + addCoordinationConfig(propertyCollector, null, configPath, value); + } + public static void addCoordinationConfig(BiConsumer propertyCollector, String tenantId, String configPath, T value) { String key = HibernateOrmMapperOutboxPollingSettings.coordinationKey(tenantId, configPath); diff --git a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java index c65a8566d72e5b..4bc734b9be338b 100644 --- a/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java +++ b/extensions/hibernate-search-orm-coordination-outbox-polling/runtime/src/main/java/io/quarkus/hibernate/search/orm/coordination/outboxpolling/runtime/HibernateSearchOutboxPollingRecorder.java @@ -6,16 +6,28 @@ import java.util.Optional; import java.util.function.BiConsumer; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.HibernateOrmMapperOutboxPollingSettings; import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil; import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationRuntimeInitListener; +import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationStaticInitListener; import io.quarkus.hibernate.search.orm.coordination.outboxpolling.runtime.HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit.AgentsConfig; import io.quarkus.runtime.annotations.Recorder; @Recorder public class HibernateSearchOutboxPollingRecorder { + public HibernateOrmIntegrationStaticInitListener createStaticInitListener( + HibernateSearchOutboxPollingBuildTimeConfig buildTimeConfig, String persistenceUnitName) { + HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit puConfig = PersistenceUnitUtil + .isDefaultPersistenceUnit(persistenceUnitName) + ? buildTimeConfig.defaultPersistenceUnit() + : buildTimeConfig.persistenceUnits().get(persistenceUnitName); + return new StaticInitListener(puConfig); + } + public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener( HibernateSearchOutboxPollingRuntimeConfig runtimeConfig, String persistenceUnitName) { HibernateSearchOutboxPollingRuntimeConfigPersistenceUnit puConfig = PersistenceUnitUtil @@ -25,6 +37,67 @@ public HibernateOrmIntegrationRuntimeInitListener createRuntimeInitListener( return new RuntimeInitListener(puConfig); } + private static final class StaticInitListener + implements HibernateOrmIntegrationStaticInitListener { + + private final HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit buildTimeConfig; + + private StaticInitListener(HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit buildTimeConfig) { + this.buildTimeConfig = buildTimeConfig; + } + + @Override + public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapContext, + BiConsumer propertyCollector) { + // Nothing to do + } + + @Override + public void contributeBootProperties(BiConsumer propertyCollector) { + if (buildTimeConfig == null) { + return; + } + + contributeCoordinationBuildTimeProperties(propertyCollector, buildTimeConfig.coordination()); + } + + private void contributeCoordinationBuildTimeProperties(BiConsumer propertyCollector, + HibernateSearchOutboxPollingBuildTimeConfigPersistenceUnit.CoordinationConfig config) { + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_AGENT_CATALOG, + config.entityMapping().agent().catalog()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_AGENT_SCHEMA, + config.entityMapping().agent().schema()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_AGENT_TABLE, + config.entityMapping().agent().table()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_AGENT_UUID_GEN_STRATEGY, + config.entityMapping().agent().uuidGenStrategy()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_AGENT_UUID_TYPE, + config.entityMapping().agent().uuidType()); + + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_OUTBOXEVENT_CATALOG, + config.entityMapping().outboxEvent().catalog()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_OUTBOXEVENT_SCHEMA, + config.entityMapping().outboxEvent().schema()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_OUTBOXEVENT_TABLE, + config.entityMapping().outboxEvent().table()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_OUTBOXEVENT_UUID_GEN_STRATEGY, + config.entityMapping().outboxEvent().uuidGenStrategy()); + addCoordinationConfig(propertyCollector, + HibernateOrmMapperOutboxPollingSettings.CoordinationRadicals.ENTITY_MAPPING_OUTBOXEVENT_UUID_TYPE, + config.entityMapping().outboxEvent().uuidType()); + } + + } + private static final class RuntimeInitListener implements HibernateOrmIntegrationRuntimeInitListener {