Class OldDatabaseUtil
- java.lang.Object
-
- jetbrains.buildServer.serverSide.versioning.converters.OldDatabaseUtil
-
public class OldDatabaseUtil extends Object
This class provides utility methods to perform DDL operations in database-agnostic way. Currently supported databases: HSQL(default diualect), MySQL (4+), PostgreSQL (8+), Oracle (10g+). TODO: Refactor: method are inconsistend some are only construct SQL DDL and some execute it.
-
-
Field Summary
Fields Modifier and Type Field Description static String
TABLE_NAME
Metadata constant
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addColumn(Connection connection, String tableName, String columnName, String columnDefinition)
static void
addColumn(DBFunctions dbf, String tableName, String columnName, String columnDefinition)
Add column.static void
changeColumn(Connection connection, String tableName, String columnName, String columnDefinition)
Deprecated.static void
changeColumn(DBFunctions dbf, String tableName, String columnName, String columnDefinition)
Change column type.static void
close(Object... args)
Close anything closablestatic Integer
countTableRows(DBFunctions dbf, String tableName, String condition)
static SQLDialect
createSQLFunctionsByConnection(Connection conn)
Deprecated.static void
dropColumn(Connection connection, String tableName, String columnName)
Drop column.static void
dropColumnDefault(String columnName, String tableName, Connection connection)
Deprecated.this method is highly unportable, please avoid explicit default expectations.static void
dropColumnDefault(String columnName, String tableName, DBFunctions dbf)
Deprecated.this method is highly unportable, please avoid explicit default expectations.static void
dropIndex(String indexName, String tableName, Connection connection)
Deprecated.static void
dropIndex(String indexName, String tableName, DBFunctions dbf)
Drop table index by namestatic void
execute(Connection conn, String sqlText)
static void
execute(Statement stmt, String sqlText)
Executes statement gathering as many error detail as possiblestatic void
execute(DBFunctions dbf, String sqlText)
static DBColumnTypes
getColumnTypes(Connection con)
Deprecated.usegetColumnTypes(DBFunctions)
instead.static DBColumnTypes
getColumnTypes(DatabaseType databaseType)
static DBColumnTypes
getColumnTypes(DBFunctions dbf)
Provides with old-style column types.static DatabaseType
getDatabaseType(Connection connection)
Deprecated.use theSQLDialect.getDbType()
instead.static DatabaseType
getDatabaseType(DBFunctions dbf)
Only to compatibility with legacy converters.static long
getNextId(Connection connection, String tableName, String idColumnName)
static long
getNextId(DBFunctions dbf, String tableName, String idColumnName)
Get next id by finding max value for given column.static String
insertRow(String tableName, String columns, Object... values)
static String
INT(Connection connection)
static String
INT(DBFunctions dbf)
Integer column typestatic String
LONG(Connection connection)
static String
LONG(DBFunctions dbf)
Long (BIGINT) column typestatic String
LONG_STRING(int length, Connection connection)
static String
LONG_STRING(int length, DBFunctions dbf)
Text column type string depending on sizestatic void
renameColumn(Connection connection, String tableName, String columnName, String newColumnName, String definition)
Deprecated.static void
renameColumn(DBFunctions dbf, String tableName, String columnName, String newColumnName, String definition)
Deprecated.use #RENAME_COLUMN and use dbf.DBFunctions.executeDdls(java.lang.String...)
static void
renameTable(Connection connection, String oldName, String newName)
static void
renameTable(DBFunctions dbf, String oldName, String newName)
Rename database table.static void
setColumnNullable(DBFunctions dbf, String tableName, String columnName, String columnDefinition, boolean nullable)
Change nullability of given column.static String
SHORT_STRING(int length, Connection c)
static String
SHORT_STRING(int length, DBFunctions dbf)
Short string (up to 2048 characters) column typestatic boolean
tableExists(DBFunctions dbf, String tableName)
Check table existence via database metadata.static String
TIMESTAMP(Connection connection)
static String
TIMESTAMP(DBFunctions dbf)
Long (BIGINT) column type
-
-
-
Field Detail
-
TABLE_NAME
@NotNull public static final String TABLE_NAME
Metadata constant- See Also:
- Constant Field Values
-
-
Method Detail
-
getDatabaseType
@Deprecated public static DatabaseType getDatabaseType(Connection connection)
Deprecated.use theSQLDialect.getDbType()
instead.Detect database type.- Parameters:
connection
- connection- Returns:
- type
-
getDatabaseType
public static DatabaseType getDatabaseType(DBFunctions dbf)
Only to compatibility with legacy converters.
-
getColumnTypes
@NotNull public static DBColumnTypes getColumnTypes(DBFunctions dbf)
Provides with old-style column types.- Parameters:
dbf
- db fucntions.- Returns:
- column types.
-
getColumnTypes
@Deprecated @NotNull public static DBColumnTypes getColumnTypes(Connection con)
Deprecated.usegetColumnTypes(DBFunctions)
instead.
-
getColumnTypes
@NotNull public static DBColumnTypes getColumnTypes(DatabaseType databaseType)
-
LONG_STRING
public static String LONG_STRING(int length, DBFunctions dbf)
Text column type string depending on size- Parameters:
length
- desired lenghtconnection
- connection- Returns:
- database-specific type
-
LONG_STRING
public static String LONG_STRING(int length, Connection connection)
-
SHORT_STRING
public static String SHORT_STRING(int length, DBFunctions dbf)
Short string (up to 2048 characters) column type- Parameters:
length
- desired lenght - should be less than or equal 2048c
-- Returns:
- database-specific type
-
SHORT_STRING
public static String SHORT_STRING(int length, Connection c)
-
INT
public static String INT(DBFunctions dbf)
Integer column type- Parameters:
connection
- connection- Returns:
- database-specific type
-
INT
public static String INT(Connection connection)
-
LONG
public static String LONG(DBFunctions dbf)
Long (BIGINT) column type- Parameters:
connection
- connection- Returns:
- database-specific type
-
LONG
public static String LONG(Connection connection)
-
TIMESTAMP
public static String TIMESTAMP(DBFunctions dbf)
Long (BIGINT) column type- Parameters:
connection
- connection- Returns:
- database-specific type
-
TIMESTAMP
public static String TIMESTAMP(Connection connection)
-
tableExists
public static boolean tableExists(@NotNull DBFunctions dbf, @NotNull String tableName) throws SQLException
Check table existence via database metadata.- Parameters:
connection
- connectiontableName
- table name- Returns:
- flag
- Throws:
SQLException
- raw database exception
-
renameTable
public static void renameTable(@NotNull DBFunctions dbf, @NotNull String oldName, @NotNull String newName) throws SQLException
Rename database table.- Parameters:
connection
- connectionoldName
- old namenewName
- name name- Throws:
SQLException
- raw database exception
-
renameTable
public static void renameTable(@NotNull Connection connection, @NotNull String oldName, @NotNull String newName) throws SQLException
- Throws:
SQLException
-
createSQLFunctionsByConnection
@Deprecated @NotNull public static SQLDialect createSQLFunctionsByConnection(@NotNull Connection conn)
Deprecated.
-
getNextId
public static long getNextId(DBFunctions dbf, String tableName, String idColumnName) throws SQLException
Get next id by finding max value for given column. TODO: no better way yet but we should use hibernate genereator approach- Parameters:
dbf
- connectiontableName
- table nameidColumnName
- column name to check- Returns:
- next id
- Throws:
SQLException
- raw database exception
-
getNextId
public static long getNextId(Connection connection, String tableName, String idColumnName) throws SQLException
- Throws:
SQLException
-
renameColumn
@Deprecated public static void renameColumn(DBFunctions dbf, String tableName, String columnName, String newColumnName, String definition) throws SQLException
Deprecated.use #RENAME_COLUMN and use dbf.DBFunctions.executeDdls(java.lang.String...)
Change column name. WARNING: do use this to change type or nullability or default value of column!- Parameters:
connection
- connectiontableName
- table namecolumnName
- column namenewColumnName
- new column namedefinition
- original type declaration - actually used on MySQL only- Throws:
SQLException
- raw database exception
-
renameColumn
@Deprecated public static void renameColumn(Connection connection, String tableName, String columnName, String newColumnName, String definition) throws SQLException
Deprecated.- Throws:
SQLException
-
addColumn
public static void addColumn(DBFunctions dbf, String tableName, String columnName, String columnDefinition) throws SQLException
Add column.- Parameters:
connection
- connectiontableName
- table namecolumnName
- column namecolumnDefinition
- column type declaration- Throws:
SQLException
- raw database exception
-
addColumn
public static void addColumn(Connection connection, String tableName, String columnName, String columnDefinition) throws SQLException
- Throws:
SQLException
-
dropColumn
public static void dropColumn(Connection connection, String tableName, String columnName) throws SQLException
Drop column. Drops dependent constraints.- Parameters:
connection
- connectiontableName
- table namecolumnName
- column name- Throws:
SQLException
- raw database exception
-
changeColumn
public static void changeColumn(DBFunctions dbf, String tableName, String columnName, String columnDefinition) throws SQLException
Change column type. WARNING: do use this to change nullability or default value of column!- Parameters:
dbf
- dbftableName
- table namecolumnName
- column namecolumnDefinition
- column type declaration- Throws:
SQLException
-
changeColumn
@Deprecated public static void changeColumn(Connection connection, String tableName, String columnName, String columnDefinition) throws SQLException
Deprecated.Change column type. WARNING: do use this to change nullability or default value of column!- Parameters:
connection
- connectiontableName
- table namecolumnName
- column namecolumnDefinition
- column type declaration- Throws:
SQLException
- raw database exception
-
setColumnNullable
public static void setColumnNullable(DBFunctions dbf, String tableName, String columnName, String columnDefinition, boolean nullable)
Change nullability of given column.- Parameters:
connection
- connectiontableName
- table namecolumnName
- column namecolumnDefinition
- column type declarationnullable
- nullability flag- Throws:
SQLException
- raw database exception
-
dropColumnDefault
@Deprecated public static void dropColumnDefault(String columnName, String tableName, DBFunctions dbf)
Deprecated.this method is highly unportable, please avoid explicit default expectations. (set default via UPDATE).Drop table column default value (set it to NULL).- Parameters:
columnName
- column nametableName
- table nameconnection
- connection- Throws:
SQLException
- raw database exception
-
dropColumnDefault
@Deprecated public static void dropColumnDefault(String columnName, String tableName, Connection connection) throws SQLException
Deprecated.this method is highly unportable, please avoid explicit default expectations. (set default via UPDATE).- Throws:
SQLException
-
dropIndex
public static void dropIndex(String indexName, String tableName, DBFunctions dbf) throws SQLException
Drop table index by name- Parameters:
indexName
- index nametableName
- table nameconnection
- connection- Throws:
SQLException
- raw database exception
-
dropIndex
@Deprecated public static void dropIndex(String indexName, String tableName, Connection connection) throws SQLException
Deprecated.- Throws:
SQLException
-
execute
public static void execute(@NotNull DBFunctions dbf, String sqlText)
-
execute
public static void execute(@NotNull Connection conn, String sqlText)
-
execute
public static void execute(@NotNull Statement stmt, String sqlText)
Executes statement gathering as many error detail as possible- Parameters:
stmt
- statementsqlText
- original SQL or code description
-
close
public static void close(Object... args)
Close anything closable- Parameters:
args
- closeable objects to close
-
countTableRows
public static Integer countTableRows(@NotNull DBFunctions dbf, @NotNull String tableName, @Nullable String condition)
-
-