public abstract class AbstractDbmsBean extends Object implements DbmsBean
DbmsBean.ColumnDefinition, DbmsBean.ConstraintDefinition
Modifier and Type | Field and Description |
---|---|
static int |
LARGE_STRING_TYPE |
Constructor and Description |
---|
AbstractDbmsBean() |
Modifier and Type | Method and Description |
---|---|
protected void |
actuallyChangeColumnToNotNull(Connection c,
String tableName,
String columnName) |
void |
addColumn(Connection c,
String tableName,
String columnName,
int columnType,
Integer columnSize)
Add a column to a table.
|
protected void |
changeColumnDefinition(Connection c,
String table,
String column,
String sqlType,
boolean isNullable) |
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,
Integer columnSize,
boolean isNullable)
Changes column type to the new type (see
Types . |
void |
changeTableNameToUpperCase(Connection connection,
String oldName)
Rename table from lower case to upper case.
|
void |
createIndex(Connection c,
String index,
String table,
String column) |
protected void |
createPrimaryKey(Connection c,
String table,
String pkName,
Collection<String> columns) |
void |
createUniqueConstraint(Connection c,
String uniqueKey,
String table,
String column)
Create unique key
|
boolean |
dropColumn(Connection connection,
String tableName,
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 constraint
|
protected void |
dropConstraints(Connection connection,
String tableName,
String columnName) |
void |
dropForeignKeyConstraint(Connection c,
String tableName,
String foreignKey) |
void |
dropIndex(Connection c,
String table,
String index) |
boolean |
dropIndexIfExists(Connection c,
String table,
String index) |
void |
dropTable(Connection c,
String tableName)
Drop table.
|
protected DbmsBean.ColumnDefinition |
getColumnDefinition(Connection connection,
String tableName,
String columnName) |
List<DbmsBean.ColumnDefinition> |
getColumns(Connection c,
String table,
String column) |
protected List<DbmsBean.ConstraintDefinition> |
getConstraintDefinitions(Connection connection,
String query,
String column) |
protected DbmsBean.ConstraintDefinition.ConstraintType |
getConstraintType(String typeName) |
List<String> |
getIndexNames(Connection c,
String table,
String column)
Returns indices set up on a given table, optionally narrowed down to a column.
|
String |
getSchema(Connection c)
Schema name, retrieved from connection or cache
|
protected String |
getSchemaUncached(Connection c) |
boolean |
isColumnPresent(Connection connection,
String tableName,
String columnName)
Checks whether given table contains the specified column.
|
boolean |
isColumnPresent(Statement statement,
String tableName,
String columnName)
Checks whether given table contains the specified column.
|
boolean |
isHsqldb() |
boolean |
isMsSqlServer() |
boolean |
isMySql() |
boolean |
isOracle() |
boolean |
isPostgreSql() |
boolean |
isTablePresent(Connection c,
String tableName)
Checks whether given table is present in the database
|
void |
migrateColumnType(Connection c,
String table,
String column,
int columnType,
Integer columnSize)
Changes column type to the new type (see
Types . |
protected DbmsBean.ColumnDefinition |
newColumnDefinition(String columnName,
int dataType,
String dataTypeName,
OptionalInt columnSize,
Optional<Boolean> isNullable) |
abstract void |
renameColumn(Connection c,
String tableName,
String oldName,
String newName)
Rename columns.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dropPrimaryKey, getCatalog, getConcat, getConstraints, getDatabaseType, getQuery, prepareStatement, resizeVarcharColumn
public static final int LARGE_STRING_TYPE
public boolean isColumnPresent(@NotNull Connection connection, @NotNull String tableName, @NotNull String columnName) throws SQLException
DbmsBean
isColumnPresent
in interface DbmsBean
SQLException
public boolean isColumnPresent(@NotNull Statement statement, @NotNull String tableName, @NotNull String columnName) throws SQLException
DbmsBean
isColumnPresent
in interface DbmsBean
SQLException
public void changeColumnType(Connection c, String table, String column, int type, @Nullable Integer columnSize, boolean isNullable) throws SQLException
DbmsBean
Types
. Uses alter table, so won't cope with all type conversions.changeColumnType
in interface DbmsBean
SQLException
protected DbmsBean.ConstraintDefinition.ConstraintType getConstraintType(String typeName)
protected List<DbmsBean.ConstraintDefinition> getConstraintDefinitions(Connection connection, String query, @Nullable String column) throws SQLException
SQLException
protected void changeColumnDefinition(Connection c, String table, String column, String sqlType, boolean isNullable) throws SQLException
SQLException
public void migrateColumnType(Connection c, String table, String column, int columnType, @Nullable Integer columnSize) throws SQLException
DbmsBean
Types
. Uses rename + add + copy + drop for maximum compatibility.migrateColumnType
in interface DbmsBean
SQLException
public boolean dropColumn(@NotNull Connection connection, @NotNull String tableName, @NotNull String columnName) throws SQLException
DbmsBean
dropColumn
in interface DbmsBean
SQLException
protected void dropConstraints(Connection connection, String tableName, String columnName)
public void dropIndex(Connection c, String table, String index) throws SQLException
dropIndex
in interface DbmsBean
SQLException
public boolean dropIndexIfExists(Connection c, String table, String index) throws SQLException
dropIndexIfExists
in interface DbmsBean
SQLException
public void createIndex(Connection c, String index, String table, String column) throws SQLException
createIndex
in interface DbmsBean
SQLException
public void createUniqueConstraint(Connection c, String uniqueKey, String table, String column) throws SQLException
DbmsBean
createUniqueConstraint
in interface DbmsBean
SQLException
- if the operation fails (ie. key exists or data in the column is not unique)public boolean isTablePresent(@NotNull Connection c, @NotNull String tableName) throws SQLException
DbmsBean
isTablePresent
in interface DbmsBean
c
- connection used to verify DB table existencetableName
- name of DB tableSQLException
- if a database error occurs or connection is closedpublic void changeTableNameToUpperCase(Connection connection, String oldName) throws SQLException
DbmsBean
changeTableNameToUpperCase
in interface DbmsBean
SQLException
public abstract void renameColumn(Connection c, String tableName, String oldName, String newName) throws SQLException
DbmsBean
renameColumn
in interface DbmsBean
SQLException
public void addColumn(Connection c, String tableName, String columnName, int columnType, Integer columnSize) throws SQLException
DbmsBean
addColumn
in interface DbmsBean
SQLException
public void dropConstraint(Connection c, String tableName, String constraint) throws SQLException
DbmsBean
dropConstraint
in interface DbmsBean
SQLException
- if constraint does not existpublic void dropForeignKeyConstraint(Connection c, String tableName, String foreignKey) throws SQLException
dropForeignKeyConstraint
in interface DbmsBean
SQLException
public void dropTable(Connection c, String tableName) throws SQLException
DbmsBean
dropTable
in interface DbmsBean
SQLException
public void changeColumnToNotNull(Connection c, String tableName, String columnName) throws SQLException
DbmsBean
changeColumnToNotNull
in interface DbmsBean
SQLException
protected void actuallyChangeColumnToNotNull(Connection c, String tableName, String columnName) throws SQLException
SQLException
public List<String> getIndexNames(Connection c, String table, String column) throws SQLException
DbmsBean
getIndexNames
in interface DbmsBean
SQLException
public List<DbmsBean.ColumnDefinition> getColumns(Connection c, @NotNull String table, @Nullable String column) throws SQLException
getColumns
in interface DbmsBean
SQLException
protected void createPrimaryKey(Connection c, String table, String pkName, Collection<String> columns) throws SQLException
SQLException
protected DbmsBean.ColumnDefinition newColumnDefinition(String columnName, int dataType, String dataTypeName, OptionalInt columnSize, Optional<Boolean> isNullable)
@Nullable protected DbmsBean.ColumnDefinition getColumnDefinition(Connection connection, String tableName, @Nullable String columnName) throws SQLException
SQLException
@Nullable public String getSchema(Connection c) throws SQLException
DbmsBean
getSchema
in interface DbmsBean
SQLException
@Nullable protected String getSchemaUncached(Connection c) throws SQLException
SQLException
public boolean isHsqldb()
public boolean isMsSqlServer()
isMsSqlServer
in interface DbmsBean
public boolean isMySql()
public boolean isOracle()
public boolean isPostgreSql()
isPostgreSql
in interface DbmsBean
Copyright © 2017 Atlassian Software Systems Pty Ltd. All rights reserved.