DataSourceConfig config = new DataSourceConfig()
.setUrl("jdbc:postgresql://127.0.0.1:5432/unit");
.setUsername("foo");
.setPassword("bar");
DataSource pool = DataSourceFactory.create("app", config);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddProperty(String key, boolean value) Add a driver property.addProperty(String key, int value) Add a driver property.addProperty(String key, String value) Add a driver property.copy()Return a copy of the DataSourceConfig.getAlert()Return the alert implementation to use.Return the clientInfo ApplicationName property.Return the clientInfo ApplicationName property.intReturn the size of the CallableStatement cache (per connection).Return a map of custom properties for the jdbc driver connection.Return the database driver.intReturn the heartbeat frequency in seconds.Return a SQL statement used to test the database is accessible.intReturn the heart beat timeout in seconds.Return the InitDatabase to use with ownerUsername.Return a list of init queries, that are executed after a connection is opened.intReturn the transaction isolation level.intReturn the time in minutes after which a connection could be considered to have leaked.Return the listener to use.intReturn the maximum age a connection is allowed to be before it is closed.intReturn the maximum number of connections the pool can reach.intReturn the time in seconds a connection can be idle after which it can be trimmed from the pool.intReturn the max size for reporting stack traces on busy connections.intReturn the minimum number of connections the pool should maintain.Return the database owner password.Return the database owner username.Return the database password.Return the database platform.Return the pool listener.intReturn the size of the PreparedStatement cache (per connection).Return the read-only URL to use for creating a matching read only DataSource..Return the database username.intReturn the minimum time gap between pool trim checks.getUrl()Return the connection URL.Return the database username.intReturn the time in millis to wait for a connection before timing out once the pool has reached its maximum size.booleanReturn autoCommit setting.booleanReturn true if a stack trace should be captured when obtaining a connection from the pool.booleanisEmpty()Return true if there are no values set for any of url, driver, username and password.booleanReturn true (default) if the DataSource should be fail on start.booleanReturn true if the DataSource should be left offline.booleanReturn the read only setting.loadSettings(Properties properties, String poolName) Load the settings from the properties supplied.setAlert(DataSourceAlert alert) Set the alert implementation to use.setApplicationName(String applicationName) Set the ClientInfo ApplicationName property.setAutoCommit(boolean autoCommit) Set to true to turn on autoCommit.setCaptureStackTrace(boolean captureStackTrace) Set to true if a stack trace should be captured when obtaining a connection from the pool.setClientInfo(Properties clientInfo) Set the ClientInfo as properties.setCstmtCacheSize(int cstmtCacheSize) Set the size of the CallableStatement cache (per connection).setCustomProperties(Map<String, String> customProperties) Set custom properties for the jdbc driver connection.setDefaults(DataSourceConfig other) Default the values for driver, url, username and password from another config if they have not been set.Set the database driver.setFailOnStart(boolean failOnStart) Set to false, if DataSource should not fail on start.setHeartbeatFreqSecs(int heartbeatFreqSecs) Set the expected heartbeat frequency in seconds.setHeartbeatSql(String heartbeatSql) Set a SQL statement used to test the database is accessible.setHeartbeatTimeoutSeconds(int heartbeatTimeoutSeconds) Set the heart beat timeout in seconds.setInitDatabase(InitDatabase initDatabase) Set the InitDatabase to use with ownerUsername.setInitDatabaseForPlatform(String platform) Set InitDatabase based on the database platform.setInitSql(List<String> initSql) Set custom init queries for each query.setIsolationLevel(int isolationLevel) Set the transaction isolation level.setLeakTimeMinutes(int leakTimeMinutes) Set the time in minutes after which a connection could be considered to have leaked.setListener(DataSourcePoolListener listener) Set the listener to use.setMaxAgeMinutes(int maxAgeMinutes) Set the maximum age a connection can be in minutes.setMaxConnections(int maxConnections) Set the maximum number of connections the pool can reach.setMaxInactiveTimeSecs(int maxInactiveTimeSecs) Set the time in seconds a connection can be idle after which it can be trimmed from the pool.setMaxStackTraceSize(int maxStackTraceSize) Set the max size for reporting stack traces on busy connections.setMinConnections(int minConnections) Set the minimum number of connections the pool should maintain.setOffline(boolean offline) Set to true if the DataSource should be started offline (without any connections).setOwnerPassword(String ownerPassword) Set the database owner password (used to create connection for use with InitDatabase).setOwnerUsername(String ownerUsername) Set the database owner username (used to create connection for use with InitDatabase).setPassword(String password) Set the database password.setPlatform(String platform) Set the database platform (for use with ownerUsername and InitDatabase.setPoolListener(String poolListener) Set a pool listener.setPstmtCacheSize(int pstmtCacheSize) Set the size of the PreparedStatement cache (per connection).setReadOnly(boolean readOnly) Set to true to for read only.setReadOnlyUrl(String readOnlyUrl) Set the connection URL to use for a matching read-only connection pool.Set the default database schema to use.setTrimPoolFreqSecs(int trimPoolFreqSecs) Set the minimum trim gap between pool trim checks.Set the connection URL.setUsername(String username) Set the database username.setWaitTimeoutMillis(int waitTimeoutMillis) Set the time in millis to wait for a connection before timing out once the pool has reached its maximum size.booleanReturn true if InitDatabase should be used (when the pool initialises and a connection can't be obtained).
-
Constructor Details
-
DataSourceConfig
public DataSourceConfig()
-
-
Method Details
-
copy
Return a copy of the DataSourceConfig. -
setDefaults
Default the values for driver, url, username and password from another config if they have not been set. -
isEmpty
public boolean isEmpty()Return true if there are no values set for any of url, driver, username and password. -
getApplicationName
Return the clientInfo ApplicationName property. -
setApplicationName
Set the ClientInfo ApplicationName property.Refer to
Connection.setClientInfo(String, String).- Parameters:
applicationName- The ApplicationName property to set as clientInfo.
-
getClientInfo
Return the clientInfo ApplicationName property. -
setClientInfo
Set the ClientInfo as properties.Refer to
Connection.setClientInfo(Properties)Note that for Postgres currently only the ApplicationName property is used.
- Parameters:
clientInfo- The client info properties to set on connections in the DataSource.
-
getReadOnlyUrl
Return the read-only URL to use for creating a matching read only DataSource.. -
setReadOnlyUrl
Set the connection URL to use for a matching read-only connection pool. -
getUrl
Return the connection URL. -
setUrl
Set the connection URL. -
getUsername
Return the database username. -
setUsername
Set the database username. -
getPassword
Return the database password. -
setPassword
Set the database password. -
getSchema
Return the database username. -
setSchema
Set the default database schema to use. -
getDriver
Return the database driver. -
setDriver
Set the database driver. -
getIsolationLevel
public int getIsolationLevel()Return the transaction isolation level. -
setIsolationLevel
Set the transaction isolation level. -
isAutoCommit
public boolean isAutoCommit()Return autoCommit setting. -
setAutoCommit
Set to true to turn on autoCommit. -
isReadOnly
public boolean isReadOnly()Return the read only setting. -
setReadOnly
Set to true to for read only. -
getMinConnections
public int getMinConnections()Return the minimum number of connections the pool should maintain. -
setMinConnections
Set the minimum number of connections the pool should maintain. -
getMaxConnections
public int getMaxConnections()Return the maximum number of connections the pool can reach. -
setMaxConnections
Set the maximum number of connections the pool can reach. -
getAlert
Return the alert implementation to use. -
setAlert
Set the alert implementation to use. -
getListener
Return the listener to use. -
setListener
Set the listener to use. -
getHeartbeatSql
Return a SQL statement used to test the database is accessible.Note that if this is not set then it can get defaulted from the DatabasePlatform.
-
setHeartbeatSql
Set a SQL statement used to test the database is accessible.Note that if this is not set then it can get defaulted from the DatabasePlatform.
-
getHeartbeatFreqSecs
public int getHeartbeatFreqSecs()Return the heartbeat frequency in seconds.This is the expected frequency in which the DataSource should be checked to make sure it is healthy and trim idle connections.
-
setHeartbeatFreqSecs
Set the expected heartbeat frequency in seconds. -
getHeartbeatTimeoutSeconds
public int getHeartbeatTimeoutSeconds()Return the heart beat timeout in seconds. -
setHeartbeatTimeoutSeconds
Set the heart beat timeout in seconds. -
isCaptureStackTrace
public boolean isCaptureStackTrace()Return true if a stack trace should be captured when obtaining a connection from the pool.This can be used to diagnose a suspected connection pool leak.
Obviously this has a performance overhead.
-
setCaptureStackTrace
Set to true if a stack trace should be captured when obtaining a connection from the pool.This can be used to diagnose a suspected connection pool leak.
Obviously this has a performance overhead.
-
getMaxStackTraceSize
public int getMaxStackTraceSize()Return the max size for reporting stack traces on busy connections. -
setMaxStackTraceSize
Set the max size for reporting stack traces on busy connections. -
getLeakTimeMinutes
public int getLeakTimeMinutes()Return the time in minutes after which a connection could be considered to have leaked. -
setLeakTimeMinutes
Set the time in minutes after which a connection could be considered to have leaked. -
getPstmtCacheSize
public int getPstmtCacheSize()Return the size of the PreparedStatement cache (per connection). -
setPstmtCacheSize
Set the size of the PreparedStatement cache (per connection). -
getCstmtCacheSize
public int getCstmtCacheSize()Return the size of the CallableStatement cache (per connection). -
setCstmtCacheSize
Set the size of the CallableStatement cache (per connection). -
getWaitTimeoutMillis
public int getWaitTimeoutMillis()Return the time in millis to wait for a connection before timing out once the pool has reached its maximum size. -
setWaitTimeoutMillis
Set the time in millis to wait for a connection before timing out once the pool has reached its maximum size. -
getMaxInactiveTimeSecs
public int getMaxInactiveTimeSecs()Return the time in seconds a connection can be idle after which it can be trimmed from the pool.This is so that the pool after a busy period can trend over time back towards the minimum connections.
-
getMaxAgeMinutes
public int getMaxAgeMinutes()Return the maximum age a connection is allowed to be before it is closed.This can be used to close old connections.
-
setMaxAgeMinutes
Set the maximum age a connection can be in minutes. -
setMaxInactiveTimeSecs
Set the time in seconds a connection can be idle after which it can be trimmed from the pool.This is so that the pool after a busy period can trend over time back towards the minimum connections.
-
getTrimPoolFreqSecs
public int getTrimPoolFreqSecs()Return the minimum time gap between pool trim checks.This defaults to 59 seconds meaning that the pool trim check will run every minute assuming the heart beat check runs every 30 seconds.
-
setTrimPoolFreqSecs
Set the minimum trim gap between pool trim checks. -
getPoolListener
Return the pool listener. -
setPoolListener
Set a pool listener. -
isOffline
public boolean isOffline()Return true if the DataSource should be left offline.This is to support DDL generation etc without having a real database.
-
isFailOnStart
public boolean isFailOnStart()Return true (default) if the DataSource should be fail on start.If this is disabled, it allows to create a connection pool, even if the datasource is not available. (e.g. parallel start up of docker containers). It enables to initialize the Ebean-Server if the db-server is not yet up. In this case, a (
DataSourceAlert.dataSourceUp(javax.sql.DataSource)is fired when DS gets up either immediately at start-up or later.) -
setFailOnStart
Set to false, if DataSource should not fail on start. (e.g. DataSource is not available) -
setOffline
Set to true if the DataSource should be started offline (without any connections). -
getCustomProperties
Return a map of custom properties for the jdbc driver connection. -
getInitSql
Return a list of init queries, that are executed after a connection is opened. -
setInitSql
Set custom init queries for each query. -
setCustomProperties
Set custom properties for the jdbc driver connection. -
addProperty
Add a driver property.config.addProperty("useSSL", false); -
addProperty
Add a driver property.config.addProperty("useSSL", false); -
addProperty
Add a driver property.config.addProperty("useSSL", false); -
getOwnerUsername
Return the database owner username. -
setOwnerUsername
Set the database owner username (used to create connection for use with InitDatabase). -
getOwnerPassword
Return the database owner password. -
setOwnerPassword
Set the database owner password (used to create connection for use with InitDatabase). -
getPlatform
Return the database platform. -
setPlatform
Set the database platform (for use with ownerUsername and InitDatabase. -
getInitDatabase
Return the InitDatabase to use with ownerUsername. -
setInitDatabase
Set the InitDatabase to use with ownerUsername. -
setInitDatabaseForPlatform
Set InitDatabase based on the database platform. -
useInitDatabase
public boolean useInitDatabase()Return true if InitDatabase should be used (when the pool initialises and a connection can't be obtained).- Returns:
- True to obtain a connection using ownerUsername and run InitDatabase.
-
loadSettings
Load the settings from the properties supplied.You can use this when you have your own properties to use for configuration.
- Parameters:
properties- the properties to configure the dataSourcepoolName- the name of the specific dataSource pool (optional)
-