- All Implemented Interfaces:
DataSourceBuilder,DataSourceBuilder.Settings
DataSourcePool pool = new DataSourceConfig()
.setName("test")
.setUrl("jdbc:h2:mem:tests")
.setUsername("sa")
.setPassword("")
.build();
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.ebean.datasource.DataSourceBuilder
DataSourceBuilder.Settings -
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.apply(Consumer<DataSourceBuilder.Settings> apply) Apply configuration to the builder via a lambda.build()Build and return the DataSourcePool.Return the connection properties including credentials and custom parameters.copy()Return a copy of the DataSourceBuilder.Return a DataSource that will be used to provide new connections or null.dataSource(DataSource dataSource) Set a DataSource that will be used to provide new connections.driver()Return the driver instance to use.Set the driver class to use.Set the driver to use.Return the driver class to use (if an instance is not provided).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.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 alternate password2.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, username, password or driver.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.booleanShut down pool on JVM exit.load(Properties properties) Load the settings from the properties with no prefix on the property names.load(Properties properties, String prefix) Load the settings from the properties with the given prefix on the property names.loadSettings(Properties properties, String poolName) Load the settings from the properties with "datasource" prefix on the property names.setAlert(DataSourceAlert alert) setApplicationName(String applicationName) setAutoCommit(boolean autoCommit) setCaptureStackTrace(boolean captureStackTrace) setClientInfo(Properties clientInfo) setCstmtCacheSize(int cstmtCacheSize) setCustomProperties(Map<String, String> customProperties) setDefaults(DataSourceBuilder builder) Default the values for driver, url, username, password and minConnections from another builder if these properties not already been set.setFailOnStart(boolean failOnStart) setHeartbeatFreqSecs(int heartbeatFreqSecs) setHeartbeatSql(String heartbeatSql) setHeartbeatTimeoutSeconds(int heartbeatTimeoutSeconds) setInitDatabase(InitDatabase initDatabase) setInitDatabaseForPlatform(String platform) setInitSql(List<String> initSql) setIsolationLevel(int isolationLevel) setLeakTimeMinutes(int leakTimeMinutes) setListener(DataSourcePoolListener listener) setMaxAgeMinutes(int maxAgeMinutes) setMaxConnections(int maxConnections) setMaxInactiveTimeSecs(int maxInactiveTimeSecs) setMaxStackTraceSize(int maxStackTraceSize) setMinConnections(int minConnections) setOffline(boolean offline) setOwnerPassword(String ownerPassword) setOwnerUsername(String ownerUsername) setPassword(String password) setPassword2(String password2) setPlatform(String platform) setPoolListener(String poolListener) setPstmtCacheSize(int pstmtCacheSize) setReadOnly(boolean readOnly) setReadOnlyUrl(String readOnlyUrl) settings()Return the builder with access to the settings.setTrimPoolFreqSecs(int trimPoolFreqSecs) setUsername(String username) setWaitTimeoutMillis(int waitTimeoutMillis) shutdownOnJvmExit(boolean shutdownOnJvmExit) When set true a JVM shutdown hook is registered that will shutdown the connection pool on JVM exit if it has not already been shutdown.booleanReturn true if InitDatabase should be used (when the pool initialises and a connection can't be obtained).booleanReturn true to enable the additional Lambda check (for old idle connections due to Lambda suspension).useLambdaCheck(boolean useLambda) EXPERIMENTAL feature - Set to true when using in Lambda to enable an extra check to detect when the function has been restored from suspension.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.ebean.datasource.DataSourceBuilder
alert, alsoIf, applicationName, autoCommit, captureStackTrace, clientInfo, cstmtCacheSize, customProperties, driver, failOnStart, heartbeatFreqSecs, heartbeatSql, heartbeatTimeoutSeconds, initDatabase, initDatabaseForPlatform, initSql, isolationLevel, leakTimeMinutes, listener, maxAgeMinutes, maxConnections, maxInactiveTimeSecs, maxStackTraceSize, minConnections, name, offline, ownerPassword, ownerUsername, password, password2, platform, poolListener, pstmtCacheSize, readOnly, readOnlyUrl, schema, trimPoolFreqSecs, url, username, waitTimeoutMillisMethods inherited from interface io.ebean.datasource.DataSourceBuilder.Settings
driverClassName
-
Constructor Details
-
DataSourceConfig
public DataSourceConfig()
-
-
Method Details
-
settings
Description copied from interface:DataSourceBuilderReturn the builder with access to the settings. Provides getters/accessors to read the configured properties of this DataSourceBuilder.- Specified by:
settingsin interfaceDataSourceBuilder
-
apply
Description copied from interface:DataSourceBuilderApply configuration to the builder via a lambda.- Specified by:
applyin interfaceDataSourceBuilder
-
copy
Description copied from interface:DataSourceBuilderReturn a copy of the DataSourceBuilder.- Specified by:
copyin interfaceDataSourceBuilder
-
setDefaults
Description copied from interface:DataSourceBuilderDefault the values for driver, url, username, password and minConnections from another builder if these properties not already been set.- Specified by:
setDefaultsin interfaceDataSourceBuilder
-
isEmpty
public boolean isEmpty()Description copied from interface:DataSourceBuilder.SettingsReturn true if there are no values set for any of url, username, password or driver.- Specified by:
isEmptyin interfaceDataSourceBuilder.Settings
-
build
Description copied from interface:DataSourceBuilderBuild and return the DataSourcePool.DataSourcePool pool = DataSourcePool.builder() .setName("test") .setUrl("jdbc:h2:mem:tests") .setUsername("sa") .setPassword("") .build();- Specified by:
buildin interfaceDataSourceBuilder
-
setName
- Specified by:
setNamein interfaceDataSourceBuilder
-
dataSource
Description copied from interface:DataSourceBuilder.SettingsReturn a DataSource that will be used to provide new connections or null.- Specified by:
dataSourcein interfaceDataSourceBuilder.Settings
-
dataSource
Description copied from interface:DataSourceBuilderSet a DataSource that will be used to provide new connections.When provided, then it needs to implement
DataSource.getConnection()andDataSource.getConnection(String, String)returning new connections that will be pooled.- Specified by:
dataSourcein interfaceDataSourceBuilder
-
getApplicationName
Description copied from interface:DataSourceBuilder.SettingsReturn the clientInfo ApplicationName property.- Specified by:
getApplicationNamein interfaceDataSourceBuilder.Settings
-
setApplicationName
- Specified by:
setApplicationNamein interfaceDataSourceBuilder
-
getClientInfo
Description copied from interface:DataSourceBuilder.SettingsReturn the clientInfo ApplicationName property.- Specified by:
getClientInfoin interfaceDataSourceBuilder.Settings
-
setClientInfo
- Specified by:
setClientInfoin interfaceDataSourceBuilder
-
getReadOnlyUrl
Description copied from interface:DataSourceBuilder.SettingsReturn the read-only URL to use for creating a matching read only DataSource.- Specified by:
getReadOnlyUrlin interfaceDataSourceBuilder.Settings
-
setReadOnlyUrl
- Specified by:
setReadOnlyUrlin interfaceDataSourceBuilder
-
getUrl
Description copied from interface:DataSourceBuilder.SettingsReturn the connection URL.- Specified by:
getUrlin interfaceDataSourceBuilder.Settings
-
setUrl
- Specified by:
setUrlin interfaceDataSourceBuilder
-
getUsername
Description copied from interface:DataSourceBuilder.SettingsReturn the database username.- Specified by:
getUsernamein interfaceDataSourceBuilder.Settings
-
setUsername
- Specified by:
setUsernamein interfaceDataSourceBuilder
-
getPassword
Description copied from interface:DataSourceBuilder.SettingsReturn the database password.- Specified by:
getPasswordin interfaceDataSourceBuilder.Settings
-
setPassword
- Specified by:
setPasswordin interfaceDataSourceBuilder
-
getPassword2
Description copied from interface:DataSourceBuilder.SettingsReturn the database alternate password2.- Specified by:
getPassword2in interfaceDataSourceBuilder.Settings
-
setPassword2
- Specified by:
setPassword2in interfaceDataSourceBuilder
-
getSchema
Description copied from interface:DataSourceBuilder.SettingsReturn the database username.- Specified by:
getSchemain interfaceDataSourceBuilder.Settings
-
setSchema
- Specified by:
setSchemain interfaceDataSourceBuilder
-
getDriver
- Specified by:
getDriverin interfaceDataSourceBuilder.Settings
-
setDriver
- Specified by:
setDriverin interfaceDataSourceBuilder
-
driver
Description copied from interface:DataSourceBuilderSet the driver class to use.- Specified by:
driverin interfaceDataSourceBuilder
-
driver
Description copied from interface:DataSourceBuilderSet the driver to use.- Specified by:
driverin interfaceDataSourceBuilder
-
driverClass
Description copied from interface:DataSourceBuilder.SettingsReturn the driver class to use (if an instance is not provided).- Specified by:
driverClassin interfaceDataSourceBuilder.Settings
-
driver
Description copied from interface:DataSourceBuilder.SettingsReturn the driver instance to use.- Specified by:
driverin interfaceDataSourceBuilder.Settings
-
getIsolationLevel
public int getIsolationLevel()Description copied from interface:DataSourceBuilder.SettingsReturn the transaction isolation level.- Specified by:
getIsolationLevelin interfaceDataSourceBuilder.Settings
-
setIsolationLevel
- Specified by:
setIsolationLevelin interfaceDataSourceBuilder
-
isAutoCommit
public boolean isAutoCommit()Description copied from interface:DataSourceBuilder.SettingsReturn autoCommit setting.- Specified by:
isAutoCommitin interfaceDataSourceBuilder.Settings
-
setAutoCommit
- Specified by:
setAutoCommitin interfaceDataSourceBuilder
-
isReadOnly
public boolean isReadOnly()Description copied from interface:DataSourceBuilder.SettingsReturn the read only setting.- Specified by:
isReadOnlyin interfaceDataSourceBuilder.Settings
-
setReadOnly
- Specified by:
setReadOnlyin interfaceDataSourceBuilder
-
getMinConnections
public int getMinConnections()Description copied from interface:DataSourceBuilder.SettingsReturn the minimum number of connections the pool should maintain.- Specified by:
getMinConnectionsin interfaceDataSourceBuilder.Settings
-
setMinConnections
- Specified by:
setMinConnectionsin interfaceDataSourceBuilder
-
getMaxConnections
public int getMaxConnections()Description copied from interface:DataSourceBuilder.SettingsReturn the maximum number of connections the pool can reach.- Specified by:
getMaxConnectionsin interfaceDataSourceBuilder.Settings
-
setMaxConnections
- Specified by:
setMaxConnectionsin interfaceDataSourceBuilder
-
getAlert
Description copied from interface:DataSourceBuilder.SettingsReturn the alert implementation to use.- Specified by:
getAlertin interfaceDataSourceBuilder.Settings
-
setAlert
- Specified by:
setAlertin interfaceDataSourceBuilder
-
getListener
Description copied from interface:DataSourceBuilder.SettingsReturn the listener to use.- Specified by:
getListenerin interfaceDataSourceBuilder.Settings
-
setListener
- Specified by:
setListenerin interfaceDataSourceBuilder
-
getHeartbeatSql
Description copied from interface:DataSourceBuilder.SettingsReturn 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.
- Specified by:
getHeartbeatSqlin interfaceDataSourceBuilder.Settings
-
setHeartbeatSql
- Specified by:
setHeartbeatSqlin interfaceDataSourceBuilder
-
getHeartbeatFreqSecs
public int getHeartbeatFreqSecs()Description copied from interface:DataSourceBuilder.SettingsReturn 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.
- Specified by:
getHeartbeatFreqSecsin interfaceDataSourceBuilder.Settings
-
setHeartbeatFreqSecs
- Specified by:
setHeartbeatFreqSecsin interfaceDataSourceBuilder
-
getHeartbeatTimeoutSeconds
public int getHeartbeatTimeoutSeconds()Description copied from interface:DataSourceBuilder.SettingsReturn the heart beat timeout in seconds.- Specified by:
getHeartbeatTimeoutSecondsin interfaceDataSourceBuilder.Settings
-
setHeartbeatTimeoutSeconds
- Specified by:
setHeartbeatTimeoutSecondsin interfaceDataSourceBuilder
-
isCaptureStackTrace
public boolean isCaptureStackTrace()Description copied from interface:DataSourceBuilder.SettingsReturn 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.
- Specified by:
isCaptureStackTracein interfaceDataSourceBuilder.Settings
-
setCaptureStackTrace
- Specified by:
setCaptureStackTracein interfaceDataSourceBuilder
-
getMaxStackTraceSize
public int getMaxStackTraceSize()Description copied from interface:DataSourceBuilder.SettingsReturn the max size for reporting stack traces on busy connections.- Specified by:
getMaxStackTraceSizein interfaceDataSourceBuilder.Settings
-
setMaxStackTraceSize
- Specified by:
setMaxStackTraceSizein interfaceDataSourceBuilder
-
getLeakTimeMinutes
public int getLeakTimeMinutes()Description copied from interface:DataSourceBuilder.SettingsReturn the time in minutes after which a connection could be considered to have leaked.- Specified by:
getLeakTimeMinutesin interfaceDataSourceBuilder.Settings
-
setLeakTimeMinutes
- Specified by:
setLeakTimeMinutesin interfaceDataSourceBuilder
-
getPstmtCacheSize
public int getPstmtCacheSize()Description copied from interface:DataSourceBuilder.SettingsReturn the size of the PreparedStatement cache (per connection).- Specified by:
getPstmtCacheSizein interfaceDataSourceBuilder.Settings
-
setPstmtCacheSize
- Specified by:
setPstmtCacheSizein interfaceDataSourceBuilder
-
getCstmtCacheSize
public int getCstmtCacheSize()Description copied from interface:DataSourceBuilder.SettingsReturn the size of the CallableStatement cache (per connection).- Specified by:
getCstmtCacheSizein interfaceDataSourceBuilder.Settings
-
setCstmtCacheSize
- Specified by:
setCstmtCacheSizein interfaceDataSourceBuilder
-
getWaitTimeoutMillis
public int getWaitTimeoutMillis()Description copied from interface:DataSourceBuilder.SettingsReturn the time in millis to wait for a connection before timing out once the pool has reached its maximum size.- Specified by:
getWaitTimeoutMillisin interfaceDataSourceBuilder.Settings
-
setWaitTimeoutMillis
- Specified by:
setWaitTimeoutMillisin interfaceDataSourceBuilder
-
getMaxInactiveTimeSecs
public int getMaxInactiveTimeSecs()Description copied from interface:DataSourceBuilder.SettingsReturn 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.
- Specified by:
getMaxInactiveTimeSecsin interfaceDataSourceBuilder.Settings
-
getMaxAgeMinutes
public int getMaxAgeMinutes()Description copied from interface:DataSourceBuilder.SettingsReturn the maximum age a connection is allowed to be before it is closed.This can be used to close old connections.
- Specified by:
getMaxAgeMinutesin interfaceDataSourceBuilder.Settings
-
setMaxAgeMinutes
- Specified by:
setMaxAgeMinutesin interfaceDataSourceBuilder
-
setMaxInactiveTimeSecs
- Specified by:
setMaxInactiveTimeSecsin interfaceDataSourceBuilder
-
getTrimPoolFreqSecs
public int getTrimPoolFreqSecs()Description copied from interface:DataSourceBuilder.SettingsReturn 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.
- Specified by:
getTrimPoolFreqSecsin interfaceDataSourceBuilder.Settings
-
setTrimPoolFreqSecs
- Specified by:
setTrimPoolFreqSecsin interfaceDataSourceBuilder
-
getPoolListener
Description copied from interface:DataSourceBuilder.SettingsReturn the pool listener.- Specified by:
getPoolListenerin interfaceDataSourceBuilder.Settings
-
setPoolListener
- Specified by:
setPoolListenerin interfaceDataSourceBuilder
-
isOffline
public boolean isOffline()Description copied from interface:DataSourceBuilder.SettingsReturn true if the DataSource should be left offline.This is to support DDL generation etc without having a real database.
- Specified by:
isOfflinein interfaceDataSourceBuilder.Settings
-
isFailOnStart
public boolean isFailOnStart()Description copied from interface:DataSourceBuilder.SettingsReturn 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.)- Specified by:
isFailOnStartin interfaceDataSourceBuilder.Settings
-
setFailOnStart
- Specified by:
setFailOnStartin interfaceDataSourceBuilder
-
setOffline
- Specified by:
setOfflinein interfaceDataSourceBuilder
-
getCustomProperties
Description copied from interface:DataSourceBuilder.SettingsReturn a map of custom properties for the jdbc driver connection.- Specified by:
getCustomPropertiesin interfaceDataSourceBuilder.Settings
-
getInitSql
Description copied from interface:DataSourceBuilder.SettingsReturn a list of init queries, that are executed after a connection is opened.- Specified by:
getInitSqlin interfaceDataSourceBuilder.Settings
-
setInitSql
- Specified by:
setInitSqlin interfaceDataSourceBuilder
-
setCustomProperties
- Specified by:
setCustomPropertiesin interfaceDataSourceBuilder
-
addProperty
Description copied from interface:DataSourceBuilderAdd a driver property.config.addProperty("useSSL", false);- Specified by:
addPropertyin interfaceDataSourceBuilder
-
addProperty
Description copied from interface:DataSourceBuilderAdd a driver property.config.addProperty("useSSL", false);- Specified by:
addPropertyin interfaceDataSourceBuilder
-
addProperty
Description copied from interface:DataSourceBuilderAdd a driver property.config.addProperty("useSSL", false);- Specified by:
addPropertyin interfaceDataSourceBuilder
-
getOwnerUsername
Description copied from interface:DataSourceBuilder.SettingsReturn the database owner username.- Specified by:
getOwnerUsernamein interfaceDataSourceBuilder.Settings
-
setOwnerUsername
- Specified by:
setOwnerUsernamein interfaceDataSourceBuilder
-
getOwnerPassword
Description copied from interface:DataSourceBuilder.SettingsReturn the database owner password.- Specified by:
getOwnerPasswordin interfaceDataSourceBuilder.Settings
-
setOwnerPassword
- Specified by:
setOwnerPasswordin interfaceDataSourceBuilder
-
getPlatform
Description copied from interface:DataSourceBuilder.SettingsReturn the database platform.- Specified by:
getPlatformin interfaceDataSourceBuilder.Settings
-
setPlatform
- Specified by:
setPlatformin interfaceDataSourceBuilder
-
getInitDatabase
Description copied from interface:DataSourceBuilder.SettingsReturn the InitDatabase to use with ownerUsername.- Specified by:
getInitDatabasein interfaceDataSourceBuilder.Settings
-
setInitDatabase
- Specified by:
setInitDatabasein interfaceDataSourceBuilder
-
setInitDatabaseForPlatform
- Specified by:
setInitDatabaseForPlatformin interfaceDataSourceBuilder
-
useInitDatabase
public boolean useInitDatabase()Description copied from interface:DataSourceBuilder.SettingsReturn true if InitDatabase should be used (when the pool initialises and a connection can't be obtained).- Specified by:
useInitDatabasein interfaceDataSourceBuilder.Settings- Returns:
- True to obtain a connection using ownerUsername and run InitDatabase.
-
isShutdownOnJvmExit
public boolean isShutdownOnJvmExit()Description copied from interface:DataSourceBuilder.SettingsShut down pool on JVM exit.- Specified by:
isShutdownOnJvmExitin interfaceDataSourceBuilder.Settings
-
shutdownOnJvmExit
Description copied from interface:DataSourceBuilderWhen set true a JVM shutdown hook is registered that will shutdown the connection pool on JVM exit if it has not already been shutdown.- Specified by:
shutdownOnJvmExitin interfaceDataSourceBuilder
-
useLambdaCheck
Description copied from interface:DataSourceBuilderEXPERIMENTAL feature - Set to true when using in Lambda to enable an extra check to detect when the function has been restored from suspension.- Specified by:
useLambdaCheckin interfaceDataSourceBuilder
-
useLambdaCheck
public boolean useLambdaCheck()Description copied from interface:DataSourceBuilder.SettingsReturn true to enable the additional Lambda check (for old idle connections due to Lambda suspension).- Specified by:
useLambdaCheckin interfaceDataSourceBuilder.Settings
-
load
Description copied from interface:DataSourceBuilderLoad the settings from the properties with no prefix on the property names.- Specified by:
loadin interfaceDataSourceBuilder- Parameters:
properties- the properties to configure the dataSource
-
load
Description copied from interface:DataSourceBuilderLoad the settings from the properties with the given prefix on the property names.For example, using a prefix of "my-db" then the username property key would be "my-db.username".
- Specified by:
loadin interfaceDataSourceBuilder- Parameters:
properties- the properties to configure the dataSourceprefix- the prefix of the property names.
-
loadSettings
Description copied from interface:DataSourceBuilderLoad the settings from the properties with "datasource" prefix on the property names.For example, if the poolName is "hr" then the username property key would be: "datasource.hr.username".
- Specified by:
loadSettingsin interfaceDataSourceBuilder- Parameters:
properties- the properties to configure the dataSourcepoolName- the name of the specific dataSource pool (optional)
-
connectionProperties
Description copied from interface:DataSourceBuilder.SettingsReturn the connection properties including credentials and custom parameters.- Specified by:
connectionPropertiesin interfaceDataSourceBuilder.Settings
-