Class DatasourceConfiguration

java.lang.Object
org.apache.commons.dbcp2.BasicDataSource
io.micronaut.configuration.jdbc.dbcp.DatasourceConfiguration
All Implemented Interfaces:
BasicJdbcConfiguration, AutoCloseable, Wrapper, MBeanRegistration, CommonDataSource, DataSource, org.apache.commons.dbcp2.BasicDataSourceMXBean, org.apache.commons.dbcp2.DataSourceMXBean

@Context @EachProperty(value="datasources", primary="default") public class DatasourceConfiguration extends org.apache.commons.dbcp2.BasicDataSource implements BasicJdbcConfiguration
Allows the configuration of Apache DBCP JDBC data sources. All properties on BasicDataSource are available to be configured. If the url, driver class, username, or password are missing, sensible defaults will be provided when possible. If no configuration beyond the datasource name is provided, an in memory datastore will be configured based on the available drivers on the classpath.
Since:
1.0
Author:
James Kleeh
  • Field Summary

    Fields inherited from interface io.micronaut.jdbc.BasicJdbcConfiguration

    PREFIX
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
     
     
     
     
    Get the name of the bean.
     
     
     
     
    void
    setConnectionPropertiesString(String connectionProperties)
    A helper method to allow setting the connectionProperties via a single String.
    void
    Sets the datasource properties.

    Methods inherited from class org.apache.commons.dbcp2.BasicDataSource

    addConnectionProperty, close, createConnectionFactory, createConnectionPool, createDataSource, createDataSourceInstance, createObjectPool, createPoolableConnectionFactory, evict, getAbandonedLogWriter, getAbandonedUsageTracking, getAutoCommitOnReturn, getCacheState, getConnection, getConnection, getConnectionFactoryClassName, getConnectionInitSqls, getConnectionInitSqlsAsArray, getConnectionPool, getDefaultAutoCommit, getDefaultCatalog, getDefaultQueryTimeout, getDefaultQueryTimeoutDuration, getDefaultReadOnly, getDefaultSchema, getDefaultTransactionIsolation, getDisconnectionSqlCodes, getDisconnectionSqlCodesAsArray, getDriver, getDriverClassLoader, getDurationBetweenEvictionRuns, getEnableAutoCommitOnReturn, getEvictionPolicyClassName, getFastFailValidation, getInitialSize, getJmxName, getLifo, getLogAbandoned, getLogExpiredConnections, getLoginTimeout, getLogWriter, getMaxConnDuration, getMaxConnLifetimeMillis, getMaxIdle, getMaxOpenPreparedStatements, getMaxTotal, getMaxWaitDuration, getMaxWaitMillis, getMinEvictableIdleDuration, getMinEvictableIdleTimeMillis, getMinIdle, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getParentLogger, getRegisteredJmxName, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getRemoveAbandonedTimeoutDuration, getRollbackOnReturn, getSoftMinEvictableIdleDuration, getSoftMinEvictableIdleTimeMillis, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, getValidationQueryTimeout, getValidationQueryTimeoutDuration, invalidateConnection, isAccessToUnderlyingConnectionAllowed, isClearStatementPoolOnReturn, isClosed, isPoolPreparedStatements, isWrapperFor, log, log, postDeregister, postRegister, preDeregister, preRegister, removeConnectionProperty, restart, setAbandonedLogWriter, setAbandonedUsageTracking, setAccessToUnderlyingConnectionAllowed, setAutoCommitOnReturn, setCacheState, setClearStatementPoolOnReturn, setConnectionFactoryClassName, setConnectionInitSqls, setConnectionInitSqls, setConnectionProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultQueryTimeout, setDefaultQueryTimeout, setDefaultReadOnly, setDefaultSchema, setDefaultTransactionIsolation, setDisconnectionSqlCodes, setDriver, setDriverClassLoader, setDriverClassName, setDurationBetweenEvictionRuns, setEnableAutoCommitOnReturn, setEvictionPolicyClassName, setFastFailValidation, setInitialSize, setJmxName, setLifo, setLogAbandoned, setLogExpiredConnections, setLoginTimeout, setLogWriter, setMaxConn, setMaxConnLifetimeMillis, setMaxIdle, setMaxOpenPreparedStatements, setMaxTotal, setMaxWait, setMaxWaitMillis, setMinEvictableIdle, setMinEvictableIdleTimeMillis, setMinIdle, setNumTestsPerEvictionRun, setPassword, setPoolPreparedStatements, setRegisterConnectionMBean, setRemoveAbandonedOnBorrow, setRemoveAbandonedOnMaintenance, setRemoveAbandonedTimeout, setRemoveAbandonedTimeout, setRollbackOnReturn, setSoftMinEvictableIdle, setSoftMinEvictableIdleTimeMillis, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUsername, setValidationQuery, setValidationQueryTimeout, setValidationQueryTimeout, start, startPoolMaintenance, unwrap, validateConnectionFactory

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.micronaut.jdbc.BasicJdbcConfiguration

    setDriverClassName, setPassword, setUrl, setUsername

    Methods inherited from interface javax.sql.CommonDataSource

    createShardingKeyBuilder

    Methods inherited from interface javax.sql.DataSource

    createConnectionBuilder

    Methods inherited from interface org.apache.commons.dbcp2.DataSourceMXBean

    getUserName
  • Constructor Details

    • DatasourceConfiguration

      public DatasourceConfiguration(@Parameter String name)
      Constructor.
      Parameters:
      name - name configured from properties
  • Method Details

    • getName

      public String getName()
      Get the name of the bean.
      Specified by:
      getName in interface BasicJdbcConfiguration
      Returns:
      name
    • getDriverClassName

      public String getDriverClassName()
      Specified by:
      getDriverClassName in interface BasicJdbcConfiguration
      Specified by:
      getDriverClassName in interface org.apache.commons.dbcp2.DataSourceMXBean
      Overrides:
      getDriverClassName in class org.apache.commons.dbcp2.BasicDataSource
      Returns:
      The driver class name to be used by the data source
    • getConfiguredDriverClassName

      public String getConfiguredDriverClassName()
      Specified by:
      getConfiguredDriverClassName in interface BasicJdbcConfiguration
      Returns:
      The driver class name supplied via configuration
    • getUrl

      public String getUrl()
      Specified by:
      getUrl in interface BasicJdbcConfiguration
      Specified by:
      getUrl in interface org.apache.commons.dbcp2.DataSourceMXBean
      Overrides:
      getUrl in class org.apache.commons.dbcp2.BasicDataSource
      Returns:
      The URL to be used by the data source
    • getConfiguredUrl

      public String getConfiguredUrl()
      Specified by:
      getConfiguredUrl in interface BasicJdbcConfiguration
      Returns:
      The URL supplied via configuration
    • getUsername

      public String getUsername()
      Specified by:
      getUsername in interface BasicJdbcConfiguration
      Specified by:
      getUsername in interface org.apache.commons.dbcp2.DataSourceMXBean
      Overrides:
      getUsername in class org.apache.commons.dbcp2.BasicDataSource
      Returns:
      The username to be used by the data source
    • getConfiguredUsername

      public String getConfiguredUsername()
      Specified by:
      getConfiguredUsername in interface BasicJdbcConfiguration
      Returns:
      The username supplied via configuration
    • getPassword

      public String getPassword()
      Specified by:
      getPassword in interface org.apache.commons.dbcp2.BasicDataSourceMXBean
      Specified by:
      getPassword in interface BasicJdbcConfiguration
      Overrides:
      getPassword in class org.apache.commons.dbcp2.BasicDataSource
      Returns:
      The password to be used by the data source
    • getConfiguredPassword

      public String getConfiguredPassword()
      Specified by:
      getConfiguredPassword in interface BasicJdbcConfiguration
      Returns:
      The password supplied via configuration
    • getValidationQuery

      public String getValidationQuery()
      Specified by:
      getValidationQuery in interface BasicJdbcConfiguration
      Specified by:
      getValidationQuery in interface org.apache.commons.dbcp2.DataSourceMXBean
      Overrides:
      getValidationQuery in class org.apache.commons.dbcp2.BasicDataSource
      Returns:
      The validation query to be used by the data source
    • setConnectionPropertiesString

      public void setConnectionPropertiesString(@Property(name="datasources.*.connection-properties") String connectionProperties)
      A helper method to allow setting the connectionProperties via a single String.
      Parameters:
      connectionProperties - The connection properties
    • setDataSourceProperties

      public void setDataSourceProperties(@MapFormat(transformation=FLAT,keyFormat=RAW) Map<String,?> dsProperties)
      Description copied from interface: BasicJdbcConfiguration
      Sets the datasource properties.
      Specified by:
      setDataSourceProperties in interface BasicJdbcConfiguration
      Parameters:
      dsProperties - The properties
    • getConfiguredValidationQuery

      public String getConfiguredValidationQuery()
      Specified by:
      getConfiguredValidationQuery in interface BasicJdbcConfiguration
      Returns:
      The validation query supplied via configuration