Class DataSourceConfig

java.lang.Object
io.ebean.datasource.DataSourceConfig

public class DataSourceConfig extends Object
Configuration information for a DataSource.


   DataSourceConfig config = new DataSourceConfig()
     .setUrl("jdbc:postgresql://127.0.0.1:5432/unit");
     .setUsername("foo");
     .setPassword("bar");

   DataSource pool = DataSourceFactory.create("app", config);

 
  • Constructor Details

    • DataSourceConfig

      public DataSourceConfig()
  • Method Details

    • 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.
    • getApplicationName

      public String getApplicationName()
      Return the clientInfo ApplicationName property.
    • setApplicationName

      public DataSourceConfig setApplicationName(String applicationName)
      Set the ClientInfo ApplicationName property.

      Refer to Connection.setClientInfo(String, String).

      Parameters:
      applicationName - The ApplicationName property to set as clientInfo.
    • getClientInfo

      public Properties getClientInfo()
      Return the clientInfo ApplicationName property.
    • setClientInfo

      public DataSourceConfig setClientInfo(Properties clientInfo)
      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

      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.
    • getUrl

      public String getUrl()
      Return the connection URL.
    • 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.
    • getSchema

      public String getSchema()
      Return the database username.
    • setSchema

      public DataSourceConfig setSchema(String schema)
      Set the default database schema to use.
    • getDriver

      public String getDriver()
      Return the database driver.
    • 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 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.

      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

      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 started offline (without any connections).
    • 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 a driver property.
      
      
         config.addProperty("useSSL", false);
      
       
    • addProperty

      public DataSourceConfig addProperty(String key, boolean value)
      Add a driver property.
      
      
         config.addProperty("useSSL", false);
      
       
    • addProperty

      public DataSourceConfig addProperty(String key, int value)
      Add a 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 poolName)
      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 dataSource
      poolName - the name of the specific dataSource pool (optional)