Class JdbcDatasource

java.lang.Object
com.atlassian.jira.config.database.JdbcDatasource
All Implemented Interfaces:
Datasource

public final class JdbcDatasource extends Object implements Datasource
A JDBC datasource. Note: The direct constructors for this class are all deprecated. Use the JdbcDatasource.Builder instead. Several getters are also deprecated because the same data can be obtained indirectly through getConnectionPoolInfo().
  • Field Details

  • Constructor Details

    • JdbcDatasource

      @Deprecated public JdbcDatasource(String jdbcUrl, String driverClassName, String username, String password, int poolMaxSize, String validationQuery, Long minEvictableTimeMillis, Long timeBetweenEvictionRunsMillis)
      Deprecated.
    • JdbcDatasource

      @Deprecated public JdbcDatasource(String jdbcUrl, String driverClassName, String username, String password, Properties connectionProperties, int poolMaxSize, String validationQuery, Long minEvictableTimeMillis, Long timeBetweenEvictionRunsMillis)
      Deprecated.
    • JdbcDatasource

      @Deprecated public JdbcDatasource(DatabaseType databaseType, String hostname, String port, String instance, String username, String password, Integer poolMaxSize, String validationQuery, Long minEvictableTimeMillis, Long timeBetweenEvictionRunsMillis)
      Deprecated.
    • JdbcDatasource

      public JdbcDatasource(org.ofbiz.core.entity.config.JdbcDatasourceInfo jdbc)
  • Method Details

    • setRegisterDriverOnConstruct

      public static void setRegisterDriverOnConstruct(boolean registerDriverOnConstruct)
      This setting is soley so the config tool can avoid the fatal side effect of registering the JDBC driver in this class's constructor.
      Parameters:
      registerDriverOnConstruct - If true we do "Class.forName(driverClassName);" in the Constructor.
    • registerDriver

      public static void registerDriver(String className)
    • builder

      public static JdbcDatasource.Builder builder()
      Factory method to create a new JdbcDatasource.Builder for constructing a JdbcDatasource using a chain of named setters rather than a long list of parameters in a specific order.
      Returns:
      a new JdbcDatasource.Builder
    • toBuilder

      public JdbcDatasource.Builder toBuilder()
    • getConnection

      public Connection getConnection(com.atlassian.config.bootstrap.AtlassianBootstrapManager bootstrapManager) throws com.atlassian.config.bootstrap.BootstrapException
      Description copied from interface: Datasource
      Uses the given link AtlassianBootstrapManager to acquire a Connection to the database defined by this Datasource.
      Specified by:
      getConnection in interface Datasource
      Parameters:
      bootstrapManager - the bootstrapManager to use to get the connection.
      Returns:
      the connection.
      Throws:
      com.atlassian.config.bootstrap.BootstrapException - if the connection cannot be established.
    • getDatasource

      public org.ofbiz.core.entity.config.DatasourceInfo getDatasource(String datasourceName, String fieldType, String schemaName)
      Description copied from interface: Datasource
      Get the equivalent Ofbiz DatasourceInfo config class for this Datasource. This effectively translates between this datasource and the ofbiz entityengine.xml of yore.
      Specified by:
      getDatasource in interface Datasource
      Parameters:
      datasourceName - the ofbiz name of the datasource.
      fieldType - the field-type for the datasource as defined in ofbiz field-types.xml
      schemaName - the name of the schema for the database (may be empty)
      Returns:
      an instance of a DatasourceInfo suitable for configuring Ofbiz.
    • getDescriptorValue

      public String getDescriptorValue(String databaseType)
      Description copied from interface: Datasource
      Provides a text description suitable for an administrator that identifies the datasource.
      Specified by:
      getDescriptorValue in interface Datasource
      Parameters:
      databaseType - the field-type for the datasource as defined in ofbiz field-types.xml
      Returns:
      the description.
    • getDescriptorLabel

      public String getDescriptorLabel()
      Description copied from interface: Datasource
      Provides the name of the datasource field that this datasource represents. Effectively, it delegates the name of the datasource field when the configuration is being described to an administrator and will say "JDBC Config" or "JNDI Name" as appropriate.
      Specified by:
      getDescriptorLabel in interface Datasource
      Returns:
      the label.
    • getJdbcUrl

      public String getJdbcUrl()
      The JDBC URL
      Returns:
      The JDBC URL
    • getDriverClassName

      public String getDriverClassName()
      The class name for the driver
      Returns:
      The class name. May or may not be valid.
    • getUsername

      public String getUsername()
      The username for the database connection
      Returns:
      The username
    • getPassword

      public String getPassword()
      The password for the database connection
      Returns:
      The password
    • getConnectionProperties

      public Properties getConnectionProperties()
    • getConnectionPoolInfo

      public org.ofbiz.core.entity.config.ConnectionPoolInfo getConnectionPoolInfo()
    • getSecretStoreProviderClassName

      public String getSecretStoreProviderClassName()
    • getPoolSize

      @Deprecated public int getPoolSize()
      Deprecated.
    • getValidationQuery

      @Deprecated public String getValidationQuery()
      Deprecated.
    • getMinEvictableTimeMillis

      @Deprecated public Long getMinEvictableTimeMillis()
      Deprecated.
    • getTimeBetweenEvictionRunsMillis

      @Deprecated public Long getTimeBetweenEvictionRunsMillis()
      Deprecated.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • parse

      public static JdbcDatasource parse(org.dom4j.Element datasourceElement, @Nonnull com.atlassian.secrets.api.SecretStoreProvider secretStoreProvider, @Nullable com.atlassian.secrets.api.SecretService secretService, boolean isSecretServiceDisabled)
      Parses JDBC Datasource settings that have been serialized to XML.
      Parameters:
      datasourceElement - the jdbc-datasource element to parse
      secretStoreProvider - the legacy factory used to build the secret store provider which is then used to decrypt password
      secretService - since v10.2 used to encrypt the password
      Returns:
      the parsed JDBC datasource
      Throws:
      IllegalArgumentException - if secret store provider class is present in the dbconfig.xml, but class couldn't be initialized
    • writeTo

      public void writeTo(org.dom4j.Element element, @Nonnull com.atlassian.secrets.api.SecretStoreProvider secretStoreProvider, @Nullable com.atlassian.secrets.api.SecretService secretService, boolean isSecretServiceDisabled)
      Serializes this JDBC to an XML element. This creates a child element called jdbc-datasource which contains the settings.

      Since Jira 10.2 by default we are using Secret Service to encrypt password. The encrypted password will be stored only in the Secret Storage, and here we will use a placeholder instead. Secret Service can be disabled by setting property "atlassian.secret.service.state" to `disabled`. In that case we will save the password in plain text or encrypt it using the legacy secretStoreProvider, depending on the configuration.

      Parameters:
      element - the parent element within which to write the JDBC Datasource.
      secretStoreProvider - the legacy factory used to build the secret store provider which is then used to encrypt password
      secretService - since v10.2 used to encrypt the password
      Throws:
      IllegalArgumentException - if getSecretStoreProviderClassName() is not empty, but class couldn't be initialized