Class DataSourceConfig
- java.lang.Object
-
- io.ebean.datasource.DataSourceConfig
-
public class DataSourceConfig extends Object
Configuration information for a DataSource.
-
-
Constructor Summary
Constructors Constructor Description DataSourceConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataSourceConfigaddProperty(String key, boolean value)Add an additional driver property.DataSourceConfigaddProperty(String key, int value)Add an additional driver property.DataSourceConfigaddProperty(String key, String value)Add an additional driver property.DataSourceConfigcopy()Return a copy of the DataSourceConfig.DataSourceAlertgetAlert()Return the alert implementation to use.intgetCstmtCacheSize()Return the size of the CallableStatement cache (per connection).Map<String,String>getCustomProperties()Return a map of custom properties for the jdbc driver connection.StringgetDriver()Return the database driver.intgetHeartbeatFreqSecs()Return the heartbeat frequency in seconds.StringgetHeartbeatSql()Return a SQL statement used to test the database is accessible.intgetHeartbeatTimeoutSeconds()Return the heart beat timeout in seconds.InitDatabasegetInitDatabase()Return the InitDatabase to use with ownerUsername.List<String>getInitSql()Return a list of init queries, that are executed after a connection is opened.intgetIsolationLevel()Return the transaction isolation level.intgetLeakTimeMinutes()Return the time in minutes after which a connection could be considered to have leaked.DataSourcePoolListenergetListener()Return the listener to use.intgetMaxAgeMinutes()Return the maximum age a connection is allowed to be before it is closed.intgetMaxConnections()Return the maximum number of connections the pool can reach.intgetMaxInactiveTimeSecs()Return the time in seconds a connection can be idle after which it can be trimmed from the pool.intgetMaxStackTraceSize()Return the max size for reporting stack traces on busy connections.intgetMinConnections()Return the minimum number of connections the pool should maintain.StringgetOwnerPassword()Return the database owner password.StringgetOwnerUsername()Return the database owner username.StringgetPassword()Return the database password.StringgetPlatform()Return the database platform.StringgetPoolListener()Return the pool listener.intgetPstmtCacheSize()Return the size of the PreparedStatement cache (per connection).StringgetReadOnlyUrl()Return the read-only URL to use for creating a matching read only DataSource..StringgetSchema()Return the database username.intgetTrimPoolFreqSecs()Return the minimum time gap between pool trim checks.StringgetUrl()Return the connection URL.StringgetUsername()Return the database username.intgetWaitTimeoutMillis()Return the time in millis to wait for a connection before timing out once the pool has reached its maximum size.booleanisAutoCommit()Return autoCommit setting.booleanisCaptureStackTrace()Return 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.booleanisFailOnStart()Return true (default) if the DataSource should be fail on start.booleanisOffline()Return true if the DataSource should be left offline.booleanisReadOnly()Return the read only setting.DataSourceConfigloadSettings(Properties properties, String serverName)Load the settings from the properties supplied.DataSourceConfigsetAlert(DataSourceAlert alert)Set the alert implementation to use.DataSourceConfigsetAutoCommit(boolean autoCommit)Set to true to turn on autoCommit.DataSourceConfigsetCaptureStackTrace(boolean captureStackTrace)Set to true if a stack trace should be captured when obtaining a connection from the pool.DataSourceConfigsetCstmtCacheSize(int cstmtCacheSize)Set the size of the CallableStatement cache (per connection).DataSourceConfigsetCustomProperties(Map<String,String> customProperties)Set custom properties for the jdbc driver connection.DataSourceConfigsetDefaults(DataSourceConfig other)Default the values for driver, url, username and password from another config if they have not been set.DataSourceConfigsetDriver(String driver)Set the database driver.DataSourceConfigsetFailOnStart(boolean failOnStart)Set to false, if DataSource should not fail on start.DataSourceConfigsetHeartbeatFreqSecs(int heartbeatFreqSecs)Set the expected heartbeat frequency in seconds.DataSourceConfigsetHeartbeatSql(String heartbeatSql)Set a SQL statement used to test the database is accessible.DataSourceConfigsetHeartbeatTimeoutSeconds(int heartbeatTimeoutSeconds)Set the heart beat timeout in seconds.DataSourceConfigsetInitDatabase(InitDatabase initDatabase)Set the InitDatabase to use with ownerUsername.DataSourceConfigsetInitDatabaseForPlatform(String platform)Set InitDatabase based on the database platform.DataSourceConfigsetInitSql(List<String> initSql)Set custom init queries for each query.DataSourceConfigsetIsolationLevel(int isolationLevel)Set the transaction isolation level.DataSourceConfigsetLeakTimeMinutes(int leakTimeMinutes)Set the time in minutes after which a connection could be considered to have leaked.DataSourceConfigsetListener(DataSourcePoolListener listener)Set the listener to use.DataSourceConfigsetMaxAgeMinutes(int maxAgeMinutes)Set the maximum age a connection can be in minutes.DataSourceConfigsetMaxConnections(int maxConnections)Set the maximum number of connections the pool can reach.DataSourceConfigsetMaxInactiveTimeSecs(int maxInactiveTimeSecs)Set the time in seconds a connection can be idle after which it can be trimmed from the pool.DataSourceConfigsetMaxStackTraceSize(int maxStackTraceSize)Set the max size for reporting stack traces on busy connections.DataSourceConfigsetMinConnections(int minConnections)Set the minimum number of connections the pool should maintain.DataSourceConfigsetOffline(boolean offline)Set to true if the DataSource should be left offline.DataSourceConfigsetOwnerPassword(String ownerPassword)Set the database owner password (used to create connection for use with InitDatabase).DataSourceConfigsetOwnerUsername(String ownerUsername)Set the database owner username (used to create connection for use with InitDatabase).DataSourceConfigsetPassword(String password)Set the database password.DataSourceConfigsetPlatform(String platform)Set the database platform (for use with ownerUsername and InitDatabase.DataSourceConfigsetPoolListener(String poolListener)Set a pool listener.DataSourceConfigsetPstmtCacheSize(int pstmtCacheSize)Set the size of the PreparedStatement cache (per connection).DataSourceConfigsetReadOnly(boolean readOnly)Set to true to for read only.DataSourceConfigsetReadOnlyUrl(String readOnlyUrl)Set the connection URL to use for a matching read-only connection pool.DataSourceConfigsetSchema(String schema)Set the default database schema to use.DataSourceConfigsetTrimPoolFreqSecs(int trimPoolFreqSecs)Set the minimum trim gap between pool trim checks.DataSourceConfigsetUrl(String url)Set the connection URL.DataSourceConfigsetUsername(String username)Set the database username.DataSourceConfigsetWaitTimeoutMillis(int waitTimeoutMillis)Set the time in millis to wait for a connection before timing out once the pool has reached its maximum size.booleanuseInitDatabase()Return true if InitDatabase should be used (when the pool initialises and a connection can't be obtained).
-
-
-
Constructor Detail
-
DataSourceConfig
public DataSourceConfig()
-
-
Method Detail
-
copy
public DataSourceConfig copy()
Return a copy of the DataSourceConfig.
-
setDefaults
public DataSourceConfig setDefaults(DataSourceConfig other)
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.
-
getReadOnlyUrl
public String getReadOnlyUrl()
Return the read-only URL to use for creating a matching read only DataSource..
-
setReadOnlyUrl
public DataSourceConfig setReadOnlyUrl(String readOnlyUrl)
Set the connection URL to use for a matching read-only connection pool.
-
setUrl
public DataSourceConfig setUrl(String url)
Set the connection URL.
-
getUsername
public String getUsername()
Return the database username.
-
setUsername
public DataSourceConfig setUsername(String username)
Set the database username.
-
getPassword
public String getPassword()
Return the database password.
-
setPassword
public DataSourceConfig setPassword(String password)
Set the database password.
-
setSchema
public DataSourceConfig setSchema(String schema)
Set the default database schema to use.
-
setDriver
public DataSourceConfig setDriver(String driver)
Set the database driver.
-
getIsolationLevel
public int getIsolationLevel()
Return the transaction isolation level.
-
setIsolationLevel
public DataSourceConfig setIsolationLevel(int isolationLevel)
Set the transaction isolation level.
-
isAutoCommit
public boolean isAutoCommit()
Return autoCommit setting.
-
setAutoCommit
public DataSourceConfig setAutoCommit(boolean autoCommit)
Set to true to turn on autoCommit.
-
isReadOnly
public boolean isReadOnly()
Return the read only setting.
-
setReadOnly
public DataSourceConfig setReadOnly(boolean readOnly)
Set to true to for read only.
-
getMinConnections
public int getMinConnections()
Return the minimum number of connections the pool should maintain.
-
setMinConnections
public DataSourceConfig setMinConnections(int minConnections)
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
public DataSourceConfig setMaxConnections(int maxConnections)
Set the maximum number of connections the pool can reach.
-
getAlert
public DataSourceAlert getAlert()
Return the alert implementation to use.
-
setAlert
public DataSourceConfig setAlert(DataSourceAlert alert)
Set the alert implementation to use.
-
getListener
public DataSourcePoolListener getListener()
Return the listener to use.
-
setListener
public DataSourceConfig setListener(DataSourcePoolListener listener)
Set the listener to use.
-
getHeartbeatSql
public String 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
public DataSourceConfig setHeartbeatSql(String heartbeatSql)
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
public DataSourceConfig setHeartbeatFreqSecs(int heartbeatFreqSecs)
Set the expected heartbeat frequency in seconds.
-
getHeartbeatTimeoutSeconds
public int getHeartbeatTimeoutSeconds()
Return the heart beat timeout in seconds.
-
setHeartbeatTimeoutSeconds
public DataSourceConfig setHeartbeatTimeoutSeconds(int heartbeatTimeoutSeconds)
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
public DataSourceConfig setCaptureStackTrace(boolean captureStackTrace)
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
public DataSourceConfig setMaxStackTraceSize(int maxStackTraceSize)
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
public DataSourceConfig setLeakTimeMinutes(int leakTimeMinutes)
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
public DataSourceConfig setPstmtCacheSize(int pstmtCacheSize)
Set the size of the PreparedStatement cache (per connection).
-
getCstmtCacheSize
public int getCstmtCacheSize()
Return the size of the CallableStatement cache (per connection).
-
setCstmtCacheSize
public DataSourceConfig setCstmtCacheSize(int cstmtCacheSize)
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
public DataSourceConfig setWaitTimeoutMillis(int waitTimeoutMillis)
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 really old connections.
-
setMaxAgeMinutes
public DataSourceConfig setMaxAgeMinutes(int maxAgeMinutes)
Set the maximum age a connection can be in minutes.
-
setMaxInactiveTimeSecs
public DataSourceConfig setMaxInactiveTimeSecs(int maxInactiveTimeSecs)
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
public DataSourceConfig setTrimPoolFreqSecs(int trimPoolFreqSecs)
Set the minimum trim gap between pool trim checks.
-
getPoolListener
public String getPoolListener()
Return the pool listener.
-
setPoolListener
public DataSourceConfig setPoolListener(String poolListener)
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.This enables to initialize the Ebean-Server if the db-server is not yet up. (
DataSourceAlert.dataSourceUp(javax.sql.DataSource)is fired when DS gets up later.)
-
setFailOnStart
public DataSourceConfig setFailOnStart(boolean failOnStart)
Set to false, if DataSource should not fail on start. (e.g. DataSource is not available)
-
setOffline
public DataSourceConfig setOffline(boolean offline)
Set to true if the DataSource should be left offline.
-
getCustomProperties
public Map<String,String> getCustomProperties()
Return a map of custom properties for the jdbc driver connection.
-
getInitSql
public List<String> getInitSql()
Return a list of init queries, that are executed after a connection is opened.
-
setInitSql
public DataSourceConfig setInitSql(List<String> initSql)
Set custom init queries for each query.
-
setCustomProperties
public DataSourceConfig setCustomProperties(Map<String,String> customProperties)
Set custom properties for the jdbc driver connection.
-
addProperty
public DataSourceConfig addProperty(String key, String value)
Add an additional driver property.config.addProperty("useSSL", false);
-
addProperty
public DataSourceConfig addProperty(String key, boolean value)
Add an additional driver property.config.addProperty("useSSL", false);
-
addProperty
public DataSourceConfig addProperty(String key, int value)
Add an additional driver property.config.addProperty("useSSL", false);
-
getOwnerUsername
public String getOwnerUsername()
Return the database owner username.
-
setOwnerUsername
public DataSourceConfig setOwnerUsername(String ownerUsername)
Set the database owner username (used to create connection for use with InitDatabase).
-
getOwnerPassword
public String getOwnerPassword()
Return the database owner password.
-
setOwnerPassword
public DataSourceConfig setOwnerPassword(String ownerPassword)
Set the database owner password (used to create connection for use with InitDatabase).
-
getPlatform
public String getPlatform()
Return the database platform.
-
setPlatform
public DataSourceConfig setPlatform(String platform)
Set the database platform (for use with ownerUsername and InitDatabase.
-
getInitDatabase
public InitDatabase getInitDatabase()
Return the InitDatabase to use with ownerUsername.
-
setInitDatabase
public DataSourceConfig setInitDatabase(InitDatabase initDatabase)
Set the InitDatabase to use with ownerUsername.
-
setInitDatabaseForPlatform
public DataSourceConfig setInitDatabaseForPlatform(String platform)
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
public DataSourceConfig loadSettings(Properties properties, String serverName)
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 dataSourceserverName- the name of the specific dataSource (optional)
-
-