Class DatabaseUtil
- java.lang.Object
-
- jetbrains.buildServer.serverSide.db.DatabaseUtil
-
public final class DatabaseUtil 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.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassignTmpInts(DBFunctions dbf, String tableName, Collection<Integer> values)Assigns the given set of integer values to the specified temporary table.static voidassignTmpLongs(DBFunctions dbf, String tableName, Collection<Long> values)Assigns the given set of long integer values to the specified temporary table.static voidassignTmpStrings(DBFunctions dbf, String tableName, Collection<String> values)Assigns the given set of strings to the specified temporary table.static voidassignUnicodeTmpStrings(DBFunctions dbf, String tableName, Collection<UnicodeString> values)Assigns the given set of objects to the specified temporary table.static voidcleanTmpTable(DBFunctions dbf, String tableName)Cleans the specified temporary table.static voidclose(Object... args)Close anything closablestatic voidclose(ResultSet rset)Closes aResultSet.static voidclose(Statement stmt)Closes aStatement.static voidexecute(Statement stmt, String sqlText)Executes statement gathering as many error detail as possiblestatic StringfixTableName(DatabaseType databaseType, String name)Converts table name to proper case for metadata quering.static chargetChar(ResultSet rset, int columnIndex, char defaultChar)static DatabaseTypegetDatabaseType(DBFunctions dbf)Only to compatibility with legacy converters.static intgetInt(ResultSet rset, int columnIndex, int defaultValue)static intgetInt(ResultSet rset, String columnName, int defaultValue)static IntegergetNullableInt(ResultSet rs, String columnName)static Collection<Integer>getTmpInts(DBFunctions dbf, String tableName)Retrieves integer values from the first column of the specified temporary table.static Collection<Long>getTmpLongs(DBFunctions dbf, String tableName)Retrieves long integer values from the first column of the specified temporary table.static Collection<String>getTmpStrings(DBFunctions dbf, String tableName)Retrieves strings from the first column of the specified temporary table.static booleantableExists(DBFunctions dbf, String tableName)Check table existence via database metadata.
-
-
-
Method Detail
-
assignTmpInts
public static void assignTmpInts(@NotNull DBFunctions dbf, @NotNull String tableName, @NotNull Collection<Integer> values) throws DBExceptionAssigns the given set of integer values to the specified temporary table. The table is cleaned up before assigning.- Parameters:
dbf- dbf-access service.tableName- logical table name.values- values to assign.- Throws:
DBException- Since:
- 7.0
- See Also:
getTmpInts(DBFunctions, String)
-
assignTmpLongs
public static void assignTmpLongs(@NotNull DBFunctions dbf, @NotNull String tableName, @NotNull Collection<Long> values) throws DBExceptionAssigns the given set of long integer values to the specified temporary table. The table is cleaned up before assigning.- Parameters:
dbf- dbf-access service.tableName- logical table name.values- values to assign.- Throws:
DBException- Since:
- 7.0
- See Also:
getTmpLongs(DBFunctions, String)
-
assignTmpStrings
public static void assignTmpStrings(@NotNull DBFunctions dbf, @NotNull String tableName, @NotNull Collection<String> values) throws DBExceptionAssigns the given set of strings to the specified temporary table. The table is cleaned up before assigning.- Parameters:
dbf- dbf-access service.tableName- logical table name.values- strings to assign.- Throws:
DBException- Since:
- 7.0
- See Also:
getTmpStrings(DBFunctions, String)
-
assignUnicodeTmpStrings
public static void assignUnicodeTmpStrings(@NotNull DBFunctions dbf, @NotNull String tableName, @NotNull Collection<UnicodeString> values) throws DBExceptionAssigns the given set of objects to the specified temporary table. The table is cleaned up before assigning.- Parameters:
dbf- dbf-access service.tableName- logical table name.values- values to assign.- Throws:
DBException- Since:
- 7.0
-
cleanTmpTable
public static void cleanTmpTable(@NotNull DBFunctions dbf, @NotNull String tableName) throws DBExceptionCleans the specified temporary table.- Parameters:
dbf- dbf-access service.tableName- logical table name.- Throws:
DBException- Since:
- 7.0
-
getTmpInts
public static Collection<Integer> getTmpInts(@NotNull DBFunctions dbf, @NotNull String tableName) throws DBException
Retrieves integer values from the first column of the specified temporary table.- Parameters:
dbf- database access service.tableName- logical table name.- Returns:
- retrieved values, the order is unpredictable.
- Throws:
DBException- Since:
- 7.0
- See Also:
assignTmpInts(jetbrains.buildServer.serverSide.db.DBFunctions, java.lang.String, java.util.Collection<java.lang.Integer>)
-
getTmpLongs
public static Collection<Long> getTmpLongs(@NotNull DBFunctions dbf, @NotNull String tableName) throws DBException
Retrieves long integer values from the first column of the specified temporary table.- Parameters:
dbf- database access service.tableName- logical table name.- Returns:
- retrieved values, the order is unpredictable.
- Throws:
DBException- Since:
- 7.0
- See Also:
assignTmpLongs(jetbrains.buildServer.serverSide.db.DBFunctions, java.lang.String, java.util.Collection<java.lang.Long>)
-
getTmpStrings
public static Collection<String> getTmpStrings(@NotNull DBFunctions dbf, @NotNull String tableName) throws DBException
Retrieves strings from the first column of the specified temporary table.- Parameters:
dbf- database access service.tableName- logical table name.- Returns:
- retrieved values, the order is unpredictable.
- Throws:
DBException- Since:
- 7.0
- See Also:
assignTmpStrings(jetbrains.buildServer.serverSide.db.DBFunctions, java.lang.String, java.util.Collection<java.lang.String>)
-
getDatabaseType
public static DatabaseType getDatabaseType(DBFunctions dbf)
Only to compatibility with legacy converters.
-
tableExists
public static boolean tableExists(@NotNull DBFunctions dbf, @NotNull String tableName)Check table existence via database metadata.- Parameters:
connection- connectiontableName- table name- Returns:
- flag
- Throws:
SQLException- raw database exception
-
fixTableName
public static String fixTableName(DatabaseType databaseType, String name)
Converts table name to proper case for metadata quering.- Parameters:
databaseType- database typename- table name- Returns:
- proper table name
-
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(@NotNull Statement stmt)Closes a
Statement.- Parameters:
stmt- theStatementto close.- Since:
- 10.0.5
- See Also:
close(ResultSet),close(Object...)
-
close
public static void close(@NotNull ResultSet rset)Closes a
ResultSet.- Parameters:
rset- theResultSetto close.- Since:
- 10.0.5
- See Also:
close(Statement),close(Object...)
-
close
public static void close(@NotNull Object... args)Close anything closable- Parameters:
args- closeable objects to close- See Also:
close(Statement),close(ResultSet)
-
getChar
public static char getChar(@NotNull ResultSet rset, int columnIndex, char defaultChar) throws SQLException- Throws:
SQLException
-
getInt
public static int getInt(@NotNull ResultSet rset, int columnIndex, int defaultValue) throws SQLException- Throws:
SQLException
-
getInt
public static int getInt(@NotNull ResultSet rset, String columnName, int defaultValue) throws SQLException- Throws:
SQLException
-
getNullableInt
@Nullable public static Integer getNullableInt(@NotNull ResultSet rs, @NotNull String columnName) throws SQLException
- Throws:
SQLException
-
-