Class DatasourceFactory
java.lang.Object
io.micronaut.jdbc.BaseDatasourceFactory
io.micronaut.configuration.jdbc.ucp.DatasourceFactory
- All Implemented Interfaces:
io.micronaut.context.event.ApplicationEventListener<io.micronaut.runtime.context.scope.refresh.RefreshEvent>, io.micronaut.context.event.BeanDestroyedEventListener<DataSource>, io.micronaut.core.order.Ordered, io.micronaut.runtime.context.scope.refresh.RefreshEventListener, AutoCloseable, EventListener
@Factory
public class DatasourceFactory
extends BaseDatasourceFactory
implements AutoCloseable, io.micronaut.context.event.BeanDestroyedEventListener<DataSource>
Creates an ucp data source for each configuration bean.
- Since:
- 2.0.1
- Author:
- toddsharp
-
Nested Class Summary
Nested classes/interfaces inherited from class BaseDatasourceFactory
BaseDatasourceFactory.DataSourceCredentials -
Field Summary
Fields inherited from class BaseDatasourceFactory
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
ConstructorsConstructorDescriptionDatasourceFactory(@Nullable DataSourceResolver dataSourceResolver, io.micronaut.context.ApplicationContext applicationContext) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()oracle.ucp.jdbc.PoolDataSourcedataSource(DatasourceConfiguration datasourceConfiguration) Deprecated, for removal: This API element is subject to removal in a future version.oracle.ucp.jdbc.PoolDataSourcedataSource(DatasourceConfiguration datasourceConfiguration, List<PoolDataSourceCustomizer> customizers) Method to get a PoolDataSource from theDatasourceConfiguration.protected voiddataSourceCredentialsChanged(String dataSourceName, BaseDatasourceFactory.DataSourceCredentials dataSourceCredentials) Called when the datasource credentials have changed.voidonDestroyed(io.micronaut.context.event.BeanDestroyedEvent<DataSource> event) Closes the pool of a data source once its bean is destroyed, after the beans that depend on it, such as a JPASessionFactorythat drops the schema on close.@Nullable OracleUcpDataSourcePoolMetadataucpDataSourcePoolMetadata(DataSource dataSource) Method to create a metadata object that allows pool value lookup for each datasource object.xaDataSource(DatasourceConfiguration datasourceConfiguration, DataSource dataSource) Exposes the pool of a data source withxaenabled as anXADataSourcefor transaction managers that enlist XA connections.Methods inherited from class BaseDatasourceFactory
findDataSourceName, getObservedConfigurationPrefixes, onApplicationEventMethods 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
-
Constructor Details
-
DatasourceFactory
public DatasourceFactory(@Nullable DataSourceResolver dataSourceResolver, io.micronaut.context.ApplicationContext applicationContext) Default constructor.- Parameters:
dataSourceResolver- The data source resolverapplicationContext- The application context
-
-
Method Details
-
dataSource
@Deprecated(since="7.3.0", forRemoval=true) public oracle.ucp.jdbc.PoolDataSource dataSource(DatasourceConfiguration datasourceConfiguration) Deprecated, for removal: This API element is subject to removal in a future version.UsedataSource(DatasourceConfiguration, List)instead.Method to get a PoolDataSource from theDatasourceConfiguration.- Parameters:
datasourceConfiguration- ADatasourceConfiguration- Returns:
- A
PoolDataSource
-
dataSource
@Context @EachBean(DatasourceConfiguration.class) @Requires(condition=JdbcDataSourceEnabled.class) public oracle.ucp.jdbc.PoolDataSource dataSource(DatasourceConfiguration datasourceConfiguration, List<PoolDataSourceCustomizer> customizers) Method to get a PoolDataSource from theDatasourceConfiguration.- Parameters:
datasourceConfiguration- ADatasourceConfigurationcustomizers- The pool data source customizers, applied in order before the pool starts- Returns:
- A
PoolDataSource
-
ucpDataSourcePoolMetadata
@EachBean(DataSource.class) @Requires(beans=DatasourceConfiguration.class) public @Nullable OracleUcpDataSourcePoolMetadata ucpDataSourcePoolMetadata(DataSource dataSource) Method to create a metadata object that allows pool value lookup for each datasource object.- Parameters:
dataSource- The actual datasource- Returns:
- a
OracleUcpDataSourcePoolMetadata
-
xaDataSource
@EachBean(DatasourceConfiguration.class) @Requires(condition=JdbcDataSourceEnabled.class) public XADataSource xaDataSource(DatasourceConfiguration datasourceConfiguration, @Parameter DataSource dataSource) Exposes the pool of a data source withxaenabled as anXADataSourcefor transaction managers that enlist XA connections. The bean delegates to thePoolXADataSourceof theconfigurationand is not itself aDataSource, so the pool remains the onlyDataSourcebean of its name. That bean still opens connections for local transactions, from XA connections of the same pool.- Parameters:
datasourceConfiguration- ADatasourceConfigurationdataSource- The data source bean of the configuration, required so that the pool is created, customized and started first- Returns:
- The XA data source; the bean is disabled when xa is not enabled
- Since:
- 7.3.0
-
onDestroyed
Closes the pool of a data source once its bean is destroyed, after the beans that depend on it, such as a JPASessionFactorythat drops the schema on close. The remaining pools are closed byclose().- Specified by:
onDestroyedin interfaceio.micronaut.context.event.BeanDestroyedEventListener<DataSource>- Parameters:
event- The bean destroyed event
-
close
@PreDestroy public void close()- Specified by:
closein interfaceAutoCloseable
-
dataSourceCredentialsChanged
protected void dataSourceCredentialsChanged(String dataSourceName, BaseDatasourceFactory.DataSourceCredentials dataSourceCredentials) throws SQLException Description copied from class:BaseDatasourceFactoryCalled 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.
- Specified by:
dataSourceCredentialsChangedin classBaseDatasourceFactory- Parameters:
dataSourceName- the name of the datasourcedataSourceCredentials- the updated datasource credentials- Throws:
SQLException- if the pool could not be updated
-
dataSource(DatasourceConfiguration, List)instead.