DataSourceBuilder

Convenience class for building a DataSource. Provides a limited subset of the properties supported by a typical DataSource as well as detection logic to pick the most suitable pooling DataSource implementation.

The following pooling DataSource implementations are supported by this builder. When no type has been explicitly set, the first available pool implementation will be picked:

  • Hikari (com.zaxxer.hikari.HikariDataSource)
  • Tomcat JDBC Pool (org.apache.tomcat.jdbc.pool.DataSource)
  • Apache DBCP2 (org.apache.commons.dbcp2.BasicDataSource)
  • Oracle UCP (oracle.ucp.jdbc.PoolDataSourceImpl)
  • C3P0 (com.mchange.v2.c3p0.ComboPooledDataSource)

The following non-pooling DataSource implementations can be used when explicitly set as a type:

  • Spring's SimpleDriverDataSource (org.springframework.jdbc.datasource.SimpleDriverDataSource)
  • Oracle (oracle.jdbc.datasource.OracleDataSource)
  • H2 (org.h2.jdbcx.JdbcDataSource)
  • Postgres (org.postgresql.ds.PGSimpleDataSource)
  • Any DataSource implementation with appropriately named methods

This class is commonly used in an @Bean method and often combined with @ConfigurationProperties.

Author

Dave Syer

Madhura Bhave

Fabio Grassi

Phillip Webb

Since

2.0.0

Parameters

<T>

the DataSource type being built

See also

Functions

Link copied to clipboard
open fun build(): T
Return a newly built DataSource instance.
Link copied to clipboard
open fun create(): DataSourceBuilder<out Any>
open fun create(classLoader: ClassLoader): DataSourceBuilder<out Any>
Create a new DataSourceBuilder instance.
Link copied to clipboard
open fun derivedFrom(dataSource: DataSource): DataSourceBuilder<out Any>
Create a new DataSourceBuilder instance derived from the specified data source.
Link copied to clipboard
open fun driverClassName(driverClassName: String): DataSourceBuilder<T>
Set the driver class name that should be used when building the datasource.
Link copied to clipboard
open fun findType(classLoader: ClassLoader): Class<out DataSource>
Find the DataSource type preferred for the given classloader.
Link copied to clipboard
open fun password(password: String): DataSourceBuilder<T>
Set the password that should be used when building the datasource.
Link copied to clipboard
open fun <D : DataSource?> type(type: Class<D>): DataSourceBuilder<D>
Set the DataSource type that should be built.
Link copied to clipboard
open fun url(url: String): DataSourceBuilder<T>
Set the URL that should be used when building the datasource.
Link copied to clipboard
open fun username(username: String): DataSourceBuilder<T>
Set the username that should be used when building the datasource.