Package com.atlassian.bamboo.utils.db
Interface DbmsBean
-
- All Superinterfaces:
BambooDatabaseTypeProvider
- All Known Implementing Classes:
AbstractDbmsBean
,H2DbmsBean
,MsSqlDbmsBean
,MySqlDbmsBean
,OracleDbmsBean
,PostgreSqlDbmsBean
@Internal public interface DbmsBean extends BambooDatabaseTypeProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
DbmsBean.ColumnDefinition
static class
DbmsBean.ConstraintDefinition
static class
DbmsBean.IndexDefinition
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
addColumn(Connection c, String tableName, String columnName, int columnType, @Nullable Integer columnSize)
Add a column to a table.void
changeColumnToNotNull(Connection c, String tableName, String columnName)
Changes column to not null, unless it's already not null.void
changeColumnType(Connection c, String table, String column, int type, @Nullable Integer columnSize, boolean isNullable)
Changes column type to the new type (seeTypes
.void
changeTableNameToUpperCase(Connection connection, String oldName)
Rename table from lower case to upper case.@NotNull String
clobEquals(@NotNull String columnName)
Comparison string for CLOB column.void
createColumn(@NotNull Connection connection, @NotNull String tableName, @NotNull String columnName, int columnType)
void
createIndex(Connection c, String index, String table, String column)
void
createUniqueConstraint(Connection c, String uniqueKey, String table, String... columns)
Create unique keyboolean
dropColumn(@NotNull Connection connection, @NotNull String tableName, @NotNull String columnName)
Checks whether given table contains the specified column and drops it Checks whether given table contains the specified column and drops it, as well as foreign key constraints and index on the column.void
dropConstraint(Connection c, String tableName, String constraint)
Drop constraintvoid
dropForeignKeyConstraint(Connection c, String tableName, String foreignKey)
void
dropIndex(Connection c, String table, String index)
boolean
dropIndexIfExists(Connection c, String table, @NotNull String indexName)
Tries to find index by name ignoring case and removes it if found.void
dropPrimaryKey(Connection connection, String tableName)
Drops the primary key on a table.void
dropTable(Connection c, String tableName)
Drop table.default @Nullable String
getCatalog(Connection c)
String
getColumnDefinitionString(int columnType)
List<DbmsBean.ColumnDefinition>
getColumns(Connection c, @NotNull String table, @Nullable String column)
@NotNull String
getConcat(String... values)
Provide a different SQL concatenation operator depending on SQL engine used.@NotNull Collection<DbmsBean.ConstraintDefinition>
getConstraints(Connection connection, @NotNull String table, @Nullable String column)
Fetch information about constraintsSet<String>
getIndexNames(@NotNull Connection c, @NotNull String table, @Nullable String column)
Returns indices set up on a given table, optionally narrowed down to a column.Collection<DbmsBean.IndexDefinition>
getIndices(@NotNull Connection c, @NotNull String table)
@NotNull String
getLargeTextTypeName()
@NotNull String
getQuery(@NotNull SqlQueryProvider sqlQueryProvider)
Provide a different SQL query depending on SQL engine used.@Nullable String
getSchema(Connection c)
Schema name, retrieved from connection or cacheList<String>
getTables(@NotNull Connection c)
Retrieves the list of table names in the current schema.boolean
isColumnPresent(@NotNull Connection connection, @NotNull String tableName, @NotNull String columnName)
Checks whether given table contains the specified column.boolean
isColumnPresent(@NotNull Statement statement, @NotNull String tableName, @NotNull String columnName)
Checks whether given table contains the specified column.boolean
isH2()
boolean
isHsqldb()
Deprecated.since 6.3 HSQL is no longer supported, method will always return falseboolean
isMsSqlServer()
boolean
isMySql()
boolean
isOracle()
boolean
isPostgreSql()
boolean
isTablePresent(@NotNull Connection connection, @NotNull String tableName)
Checks whether given table is present in the databasevoid
migrateColumnType(Connection c, String table, String column, int columnType, @Nullable Integer columnSize)
Changes column type to the new type (seeTypes
.String
quote(String name)
Quotes the supplied name according to the quoting rules of the underlying DBMS.void
renameColumn(Connection c, String tableName, String oldName, String newName)
Rename columns.void
resizeVarcharColumn(@NotNull Connection connection, String tableName, String columnName, int newSize, boolean isNullable, @Nullable String defaultValue)
String
toLowerCase(String columnName)
-
Methods inherited from interface com.atlassian.bamboo.persistence3.BambooDatabaseTypeProvider
getDatabaseType
-
-
-
-
Method Detail
-
getQuery
@NotNull @NotNull String getQuery(@NotNull @NotNull SqlQueryProvider sqlQueryProvider)
Provide a different SQL query depending on SQL engine used.- Parameters:
sqlQueryProvider
-- Returns:
-
getConcat
@NotNull @NotNull String getConcat(String... values)
Provide a different SQL concatenation operator depending on SQL engine used.- Parameters:
values
- the values to concatenate.- Returns:
- the concatenation SQL to append to a query.
-
getConstraints
@NotNull @NotNull Collection<DbmsBean.ConstraintDefinition> getConstraints(Connection connection, @NotNull @NotNull String table, @Nullable @Nullable String column) throws SQLException
Fetch information about constraints- Throws:
SQLException
-
getIndexNames
Set<String> getIndexNames(@NotNull @NotNull Connection c, @NotNull @NotNull String table, @Nullable @Nullable String column) throws SQLException
Returns indices set up on a given table, optionally narrowed down to a column. For H2, it will also return implicit indices set up to support FK relationships. For SQL Server, it will return implicit PK indices. Case of returned index names is database specific - all comparisons should be case-independent.- Throws:
SQLException
-
isColumnPresent
boolean isColumnPresent(@NotNull @NotNull Connection connection, @NotNull @NotNull String tableName, @NotNull @NotNull String columnName) throws SQLException
Checks whether given table contains the specified column.- Returns:
- true if given table contains the specified column or false when either column or table doesn't exist
- Throws:
SQLException
-
isColumnPresent
boolean isColumnPresent(@NotNull @NotNull Statement statement, @NotNull @NotNull String tableName, @NotNull @NotNull String columnName) throws SQLException
Checks whether given table contains the specified column.- Returns:
- true if given table contains the specified column or false when either column or table doesn't exist
- Throws:
SQLException
-
dropColumn
boolean dropColumn(@NotNull @NotNull Connection connection, @NotNull @NotNull String tableName, @NotNull @NotNull String columnName) throws SQLException
Checks whether given table contains the specified column and drops it Checks whether given table contains the specified column and drops it, as well as foreign key constraints and index on the column. The method will automatically detect constraint names on DBMS that supports it or use provided names on DBMS that don't.- Parameters:
connection
-tableName
-columnName
-- Returns:
- Throws:
SQLException
-
migrateColumnType
void migrateColumnType(Connection c, String table, String column, int columnType, @Nullable @Nullable Integer columnSize) throws SQLException
Changes column type to the new type (seeTypes
. Uses rename + add + copy + drop for maximum compatibility.- Throws:
SQLException
-
changeColumnType
void changeColumnType(Connection c, String table, String column, int type, @Nullable @Nullable Integer columnSize, boolean isNullable) throws SQLException
Changes column type to the new type (seeTypes
. Uses alter table, so won't cope with all type conversions.- Throws:
SQLException
-
createColumn
void createColumn(@NotNull @NotNull Connection connection, @NotNull @NotNull String tableName, @NotNull @NotNull String columnName, int columnType) throws SQLException
- Throws:
SQLException
-
dropIndex
void dropIndex(Connection c, String table, String index) throws SQLException
- Throws:
SQLException
-
dropIndexIfExists
boolean dropIndexIfExists(Connection c, String table, @NotNull @NotNull String indexName) throws SQLException
Tries to find index by name ignoring case and removes it if found.- Parameters:
indexName
-- Returns:
- true if index was found
- Throws:
SQLException
-
createIndex
void createIndex(Connection c, String index, String table, String column) throws SQLException
- Throws:
SQLException
-
createUniqueConstraint
void createUniqueConstraint(Connection c, String uniqueKey, String table, String... columns) throws SQLException
Create unique key- Throws:
SQLException
- if the operation fails (ie. key exists or data in the column is not unique)
-
isTablePresent
boolean isTablePresent(@NotNull @NotNull Connection connection, @NotNull @NotNull String tableName) throws SQLException
Checks whether given table is present in the database- Parameters:
connection
- connection used to verify DB table existencetableName
- name of DB table- Returns:
- true if database is accessible and table exists, false otherwise
- Throws:
SQLException
- if a database error occurs or connection is closed
-
resizeVarcharColumn
void resizeVarcharColumn(@NotNull @NotNull Connection connection, String tableName, String columnName, int newSize, boolean isNullable, @Nullable @Nullable String defaultValue) throws SQLException
- Throws:
SQLException
-
isMySql
boolean isMySql()
- Returns:
- true if db configured in Hibernate is MySQL
-
isOracle
boolean isOracle()
- Returns:
- true if db configured in Hibernate is Oracle
-
getSchema
@Nullable @Nullable String getSchema(Connection c) throws SQLException
Schema name, retrieved from connection or cache- Returns:
- schema name
- Throws:
SQLException
-
getCatalog
@Nullable default @Nullable String getCatalog(Connection c) throws SQLException
- Throws:
SQLException
-
getColumnDefinitionString
String getColumnDefinitionString(int columnType)
-
isHsqldb
@Deprecated boolean isHsqldb()
Deprecated.since 6.3 HSQL is no longer supported, method will always return false- Returns:
- true if db configured in Hibernate is HSQLDB
-
isH2
boolean isH2()
- Returns:
- true if db configured in Hibernate is H2
-
isPostgreSql
boolean isPostgreSql()
- Returns:
- true if db configured in Hibernate is PostgreSQL
-
isMsSqlServer
boolean isMsSqlServer()
- Returns:
- true if db configured in Hibernate is Microsoft SQL Server
-
dropPrimaryKey
void dropPrimaryKey(Connection connection, String tableName) throws SQLException
Drops the primary key on a table.- Throws:
SQLException
-
changeTableNameToUpperCase
void changeTableNameToUpperCase(Connection connection, String oldName) throws SQLException
Rename table from lower case to upper case. No-op if database is table names are case insensitive.- Throws:
SQLException
-
renameColumn
void renameColumn(Connection c, String tableName, String oldName, String newName) throws SQLException
Rename columns.- Throws:
SQLException
-
addColumn
void addColumn(Connection c, String tableName, String columnName, int columnType, @Nullable @Nullable Integer columnSize) throws SQLException
Add a column to a table.- Throws:
SQLException
-
dropConstraint
void dropConstraint(Connection c, String tableName, String constraint) throws SQLException
Drop constraint- Throws:
SQLException
- if constraint does not exist
-
dropForeignKeyConstraint
void dropForeignKeyConstraint(Connection c, String tableName, String foreignKey) throws SQLException
- Throws:
SQLException
-
changeColumnToNotNull
void changeColumnToNotNull(Connection c, String tableName, String columnName) throws SQLException
Changes column to not null, unless it's already not null.- Throws:
SQLException
-
getIndices
Collection<DbmsBean.IndexDefinition> getIndices(@NotNull @NotNull Connection c, @NotNull @NotNull String table) throws SQLException
- Throws:
SQLException
-
getColumns
List<DbmsBean.ColumnDefinition> getColumns(Connection c, @NotNull @NotNull String table, @Nullable @Nullable String column) throws SQLException
- Throws:
SQLException
-
dropTable
void dropTable(Connection c, String tableName) throws SQLException
Drop table.- Throws:
SQLException
-
getTables
List<String> getTables(@NotNull @NotNull Connection c) throws SQLException
Retrieves the list of table names in the current schema.- Throws:
SQLException
-
quote
String quote(String name)
Quotes the supplied name according to the quoting rules of the underlying DBMS.
-
clobEquals
@NotNull @NotNull String clobEquals(@NotNull @NotNull String columnName)
Comparison string for CLOB column.- Parameters:
columnName
- column name- Returns:
- string for prepared statement
-
getLargeTextTypeName
@NotNull @NotNull String getLargeTextTypeName()
-
-