public abstract class AbstractDbmsBean extends Object implements DbmsBean
DbmsBean.ColumnDefinition, DbmsBean.ConstraintDefinition, DbmsBean.IndexDefinition
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.
|
String |
clobEquals(String columnName)
Comparison string for CLOB column.
|
void |
createColumn(Connection connection,
String tableName,
String columnName,
int columnType) |
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... columns)
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 indexName)
Tries to find index by name ignoring case and removes it if found.
|
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,
Function<String,String> nullableNameProcessor)
Finds all constraints affecting given column.
|
protected DbmsBean.ConstraintDefinition.ConstraintType |
getConstraintType(String typeName) |
Set<String> |
getIndexNames(Connection c,
String table,
String column)
Returns indices set up on a given table, optionally narrowed down to a column.
|
Collection<DbmsBean.IndexDefinition> |
getIndices(Connection c,
String table) |
String |
getSchema(Connection c)
Schema name, retrieved from connection or cache
|
protected String |
getSchemaUncached(Connection c) |
protected String |
getSqlTypeName(int type) |
List<String> |
getTables(Connection c)
Retrieves the list of table names in the current schema.
|
boolean |
isColumnPresent(Connection connection,
String tableName,
String columnName)
Checks whether given table contains the specified column.
|
protected boolean |
isColumnPresent(Statement statement,
String tableName,
Predicate<String> columnNamePredicate) |
boolean |
isColumnPresent(Statement statement,
String tableName,
String columnName)
Checks whether given table contains the specified column.
|
boolean |
isH2() |
boolean |
isHsqldb() |
boolean |
isMsSqlServer() |
boolean |
isMySql() |
boolean |
isOracle() |
boolean |
isPostgreSql() |
protected boolean |
isTable(List<String> definitionColumns) |
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) |
String |
quote(String name)
Quotes the supplied name according to the quoting rules of the underlying DBMS.
|
protected String |
quoteIfNeeded(String name)
Some tables in db can be stored in a case sensitive manner.
|
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, 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
protected boolean isColumnPresent(Statement statement, String tableName, Predicate<String> columnNamePredicate) throws SQLException
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
@NotNull protected String getSqlTypeName(int type)
protected DbmsBean.ConstraintDefinition.ConstraintType getConstraintType(String typeName)
protected List<DbmsBean.ConstraintDefinition> getConstraintDefinitions(Connection connection, String query, @Nullable String column, @Nullable Function<String,String> nullableNameProcessor) throws SQLException
connection
- query
- column
- 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
public void createColumn(@NotNull Connection connection, @NotNull String tableName, @NotNull String columnName, @NotNull int columnType) throws SQLException
createColumn
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, @NotNull String indexName) throws SQLException
DbmsBean
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... columns) 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 List<String> getTables(@NotNull Connection c) throws SQLException
DbmsBean
getTables
in interface DbmsBean
SQLException
public 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 String quote(String name)
DbmsBean
@NotNull public String clobEquals(@NotNull String columnName)
DbmsBean
clobEquals
in interface DbmsBean
columnName
- column nameprotected String quoteIfNeeded(String name)
public Set<String> getIndexNames(@NotNull Connection c, @NotNull String table, @Nullable String column) throws SQLException
DbmsBean
getIndexNames
in interface DbmsBean
SQLException
public Collection<DbmsBean.IndexDefinition> getIndices(@NotNull Connection c, @NotNull String table) throws SQLException
getIndices
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 isH2()
public boolean isMsSqlServer()
isMsSqlServer
in interface DbmsBean
public boolean isMySql()
public boolean isOracle()
public boolean isPostgreSql()
isPostgreSql
in interface DbmsBean
Copyright © 2020 Atlassian Software Systems Pty Ltd. All rights reserved.