Class PostgresNotificationSchemaGenerator
SchemaGenerate.CREATE and SchemaGenerate.CREATE_DROP.
The configured notification mode selects either row-change notifications with primary keys and invalidation on truncation, or table invalidations for insert, update, delete, and truncate statements. The corresponding bundled SQL resource supplies the function definition.
The shared listener registry supplies channels and generated key mappings. For inherited listeners without generated metadata, key columns are derived from the entity mapping. Neither path instantiates listeners or repository operations during schema generation. Listeners for the same schema, table, and channel share generated triggers. Installation errors fail application startup.
-
Constructor Summary
ConstructorsConstructorDescriptionPostgresNotificationSchemaGenerator(ChangeListenerRegistry registry, io.micronaut.context.env.Environment environment, PostgresNotificationConfiguration configuration) Creates a generator using the configured notification trigger mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(Connection connection, DataJdbcConfiguration configuration, PersistentEntity[] entities) Installs the selected function and triggers for subscribed PostgreSQL tables included in this schema-generation pass.
-
Constructor Details
-
PostgresNotificationSchemaGenerator
public PostgresNotificationSchemaGenerator(ChangeListenerRegistry registry, io.micronaut.context.env.Environment environment, PostgresNotificationConfiguration configuration) Creates a generator using the configured notification trigger mode.- Parameters:
registry- the discovered listener metadata grouped by datasourceenvironment- the mapping placeholder resolverconfiguration- the notification schema-generation settings
-
-
Method Details
-
generate
public void generate(Connection connection, DataJdbcConfiguration configuration, PersistentEntity[] entities) throws SQLException Installs the selected function and triggers for subscribed PostgreSQL tables included in this schema-generation pass. Does nothing for other dialects or schema-generation modes other thanSchemaGenerate.CREATEandSchemaGenerate.CREATE_DROP.The function is installed once per subscribed schema in this pass. For each table/channel subscription, all three generated trigger names are dropped before creating the selected mode's triggers. This also replaces existing triggers under
CREATEand allows mode changes without leaving the previous mode's triggers active.Function and trigger changes in this pass are transactional. An auto-commit connection uses a new transaction; an existing transaction uses a savepoint and remains under the caller's control. Installation failure rolls back these changes. Table creation performed before this pass is outside this transaction boundary.
Unrelated triggers and triggers for subscriptions absent from this pass are left unchanged. Previously installed functions are not removed when switching modes. Functions and triggers remain installed after application shutdown.
- Parameters:
connection- the schema-generation connectionconfiguration- the datasource configurationentities- the entities included in this schema-generation pass- Throws:
SQLException- if schema resolution or SQL execution failsIllegalArgumentException- if a resolved notification channel is invalidIllegalStateException- if listener key mappings are missing or conflicting, or the SQL resource cannot be read
-