Class JdbcDatasource
java.lang.Object
com.atlassian.jira.config.database.JdbcDatasource
- All Implemented Interfaces:
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().-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis is a builder class for constructing a JdbcDatasource manually. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJdbcDatasource(DatabaseType databaseType, String hostname, String port, String instance, String username, String password, Integer poolMaxSize, String validationQuery, Long minEvictableTimeMillis, Long timeBetweenEvictionRunsMillis) Deprecated.JdbcDatasource(String jdbcUrl, String driverClassName, String username, String password, int poolMaxSize, String validationQuery, Long minEvictableTimeMillis, Long timeBetweenEvictionRunsMillis) Deprecated.JdbcDatasource(String jdbcUrl, String driverClassName, String username, String password, Properties connectionProperties, int poolMaxSize, String validationQuery, Long minEvictableTimeMillis, Long timeBetweenEvictionRunsMillis) Deprecated.JdbcDatasource(org.ofbiz.core.entity.config.JdbcDatasourceInfo jdbc) -
Method Summary
Modifier and TypeMethodDescriptionstatic JdbcDatasource.Builderbuilder()Factory method to create a newJdbcDatasource.Builderfor constructing a JdbcDatasource using a chain of named setters rather than a long list of parameters in a specific order.booleangetConnection(com.atlassian.config.bootstrap.AtlassianBootstrapManager bootstrapManager) Uses the givenlink AtlassianBootstrapManagerto acquire aConnectionto the database defined by thisDatasource.org.ofbiz.core.entity.config.ConnectionPoolInfoorg.ofbiz.core.entity.config.DatasourceInfogetDatasource(String datasourceName, String fieldType, String schemaName) Get the equivalent Ofbiz DatasourceInfo config class for this Datasource.Provides the name of the datasource field that this datasource represents.getDescriptorValue(String databaseType) Provides a text description suitable for an administrator that identifies the datasource.The class name for the driverThe JDBC URLDeprecated.The password for the database connectionintDeprecated.Deprecated.The username for the database connectionDeprecated.inthashCode()static JdbcDatasourceparse(org.dom4j.Element datasourceElement, com.atlassian.secrets.api.SecretStoreProvider secretStoreProvider, com.atlassian.secrets.api.SecretService secretService, boolean isSecretServiceDisabled) Parses JDBC Datasource settings that have been serialized to XML.static voidregisterDriver(String className) static voidsetRegisterDriverOnConstruct(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.toString()voidwriteTo(org.dom4j.Element element, com.atlassian.secrets.api.SecretStoreProvider secretStoreProvider, com.atlassian.secrets.api.SecretService secretService, boolean isSecretServiceDisabled) Serializes this JDBC to an XML element.
-
Field Details
-
TCP_KEEP_ALIVE_PROPERTY
- See Also:
-
SOCKET_TIMEOUT_PROPERTY
- See Also:
-
NULL_DATABASE_MEANS_CURRENT
- See Also:
-
-
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
-
builder
Factory method to create a newJdbcDatasource.Builderfor 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
-
getConnection
public Connection getConnection(com.atlassian.config.bootstrap.AtlassianBootstrapManager bootstrapManager) throws com.atlassian.config.bootstrap.BootstrapException Description copied from interface:DatasourceUses the givenlink AtlassianBootstrapManagerto acquire aConnectionto the database defined by thisDatasource.- Specified by:
getConnectionin interfaceDatasource- 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:DatasourceGet the equivalent Ofbiz DatasourceInfo config class for this Datasource. This effectively translates between this datasource and the ofbiz entityengine.xml of yore.- Specified by:
getDatasourcein interfaceDatasource- Parameters:
datasourceName- the ofbiz name of the datasource.fieldType- the field-type for the datasource as defined in ofbiz field-types.xmlschemaName- the name of the schema for the database (may be empty)- Returns:
- an instance of a
DatasourceInfosuitable for configuring Ofbiz.
-
getDescriptorValue
Description copied from interface:DatasourceProvides a text description suitable for an administrator that identifies the datasource.- Specified by:
getDescriptorValuein interfaceDatasource- Parameters:
databaseType- the field-type for the datasource as defined in ofbiz field-types.xml- Returns:
- the description.
-
getDescriptorLabel
Description copied from interface:DatasourceProvides 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:
getDescriptorLabelin interfaceDatasource- Returns:
- the label.
-
getJdbcUrl
The JDBC URL- Returns:
- The JDBC URL
-
getDriverClassName
The class name for the driver- Returns:
- The class name. May or may not be valid.
-
getUsername
The username for the database connection- Returns:
- The username
-
getPassword
The password for the database connection- Returns:
- The password
-
getConnectionProperties
-
getConnectionPoolInfo
public org.ofbiz.core.entity.config.ConnectionPoolInfo getConnectionPoolInfo() -
getSecretStoreProviderClassName
-
getPoolSize
Deprecated. -
getValidationQuery
Deprecated. -
getMinEvictableTimeMillis
Deprecated. -
getTimeBetweenEvictionRunsMillis
Deprecated. -
toString
-
equals
-
hashCode
public int hashCode() -
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 parsesecretStoreProvider- the legacy factory used to build the secret store provider which is then used to decrypt passwordsecretService- 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 passwordsecretService- since v10.2 used to encrypt the password- Throws:
IllegalArgumentException- ifgetSecretStoreProviderClassName()is not empty, but class couldn't be initialized
-