Class BaseDatasourceFactory
- All Implemented Interfaces:
io.micronaut.context.event.ApplicationEventListener<io.micronaut.runtime.context.scope.refresh.RefreshEvent>, io.micronaut.core.order.Ordered, io.micronaut.runtime.context.scope.refresh.RefreshEventListener, EventListener
- Direct Known Subclasses:
DatasourceFactory, DatasourceFactory, DatasourceFactory, DatasourceFactory, DatasourceFactory
This class provides a basic implementation for handling refresh events and updating datasource credentials.
Subclasses are expected to implement the dataSourceCredentialsChanged(String, DataSourceCredentials) method to handle the updated credentials.
On a refresh event, the configured credentials of each affected datasource (the datasources named by the changed keys,
or all of them for new RefreshEvent()) are compared with the last applied ones, so only credentials that
actually changed are propagated.
The credentials the pools are created with are recorded when the factory is created, so the factory must be created
at startup together with its datasources, for example through a @Context datasource factory method.
- Since:
- 6.2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordA record representing datasource credentials. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.micronaut.context.ApplicationContextFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
DEFAULT_POSITION -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseDatasourceFactory(io.micronaut.context.ApplicationContext applicationContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voiddataSourceCredentialsChanged(String dataSourceName, BaseDatasourceFactory.DataSourceCredentials dataSourceCredentials) Called when the datasource credentials have changed.voidonApplicationEvent(io.micronaut.runtime.context.scope.refresh.RefreshEvent event) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
getOrder, supports
-
Field Details
-
applicationContext
protected final io.micronaut.context.ApplicationContext applicationContext
-
-
Constructor Details
-
BaseDatasourceFactory
protected BaseDatasourceFactory(io.micronaut.context.ApplicationContext applicationContext)
-
-
Method Details
-
getObservedConfigurationPrefixes
-
onApplicationEvent
public void onApplicationEvent(io.micronaut.runtime.context.scope.refresh.RefreshEvent event) - Specified by:
onApplicationEventin interfaceio.micronaut.context.event.ApplicationEventListener<io.micronaut.runtime.context.scope.refresh.RefreshEvent>
-
dataSourceCredentialsChanged
protected abstract void dataSourceCredentialsChanged(String dataSourceName, BaseDatasourceFactory.DataSourceCredentials dataSourceCredentials) throws SQLException Called when the datasource credentials have changed.Subclasses must implement this method to handle the updated credentials. If the pool can not be updated, the method must throw, so the change is not recorded as applied and a later refresh event retries it.
- Parameters:
dataSourceName- the name of the datasourcedataSourceCredentials- the updated datasource credentials- Throws:
SQLException- if the pool could not be updated
-