Package com.atlassian.bamboo.utils.db
Class JdbcUtils
- java.lang.Object
-
- com.atlassian.bamboo.utils.db.JdbcUtils
-
public class JdbcUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Function<ResultSet,Void>
LOG_RESULT
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
execute(Connection connection, String queryToFormat, String... args)
Executes query on a connection.static <T> List<T>
executeQuery(Connection connection, Function<ResultSet,T> function, String queryToFormat, String... args)
Executes query on a connection.static boolean
executeQuietly(Statement statement, String query)
static String
executeSingleValueQuery(Connection connection, String sql, String... args)
static List<List<String>>
getAllRows(ResultSet rs)
static List<List<String>>
getAllRows(ResultSet rs, Predicate<List<String>> filter)
static Function<ResultSet,String>
getColumnValue(int columnIndex)
Note that the columnIndex is 1-based, not 0-based.static @NotNull List<Long>
getListOfLong(@NotNull Connection c, @NotNull String query)
static long
getLong(ResultSet resultSet, int columnIndex)
static List<String>
getRowData(ResultSet rs)
static Function<ResultSet,String>
getString(int columnIndex)
static String
getString(ResultSet resultSet, int columnIndex)
static boolean
isTablePresent(@NotNull Connection connection, @NotNull String tableName)
static <T> List<T>
map(ResultSet resultSet, Function<ResultSet,T> function)
static int
runDeleteQuery(@NotNull Connection connection, @NotNull String query, @NotNull String entityName)
static int
runDeleteQuery(@NotNull Connection connection, @NotNull String tableName, @NotNull String idColumn, @NotNull Iterable<? extends BambooIdProvider> objects)
static int
runDeleteQuery(@NotNull PreparedStatement statement, @NotNull String query, @NotNull String entityName)
static int
runUpdateQuery(@NotNull PreparedStatement statement, @NotNull String query, @NotNull String entityName)
-
-
-
Method Detail
-
execute
public static void execute(Connection connection, String queryToFormat, String... args) throws SQLException
Executes query on a connection. Args are treated as a format string arguments for the query.- Throws:
SQLException
-
executeSingleValueQuery
public static String executeSingleValueQuery(Connection connection, String sql, String... args) throws SQLException
- Throws:
SQLException
-
executeQuery
public static <T> List<T> executeQuery(Connection connection, Function<ResultSet,T> function, String queryToFormat, String... args) throws SQLException
Executes query on a connection. Args are treated as a format string arguments for the query.- Throws:
SQLException
-
isTablePresent
public static boolean isTablePresent(@NotNull @NotNull Connection connection, @NotNull @NotNull String tableName)
-
runDeleteQuery
public static int runDeleteQuery(@NotNull @NotNull Connection connection, @NotNull @NotNull String query, @NotNull @NotNull String entityName) throws SQLException
- Throws:
SQLException
-
runDeleteQuery
public static int runDeleteQuery(@NotNull @NotNull PreparedStatement statement, @NotNull @NotNull String query, @NotNull @NotNull String entityName)
- Parameters:
statement
- statement to be executed (caller is responsible for closing statement)query
-entityName
-- Returns:
- Throws:
SQLException
-
runUpdateQuery
public static int runUpdateQuery(@NotNull @NotNull PreparedStatement statement, @NotNull @NotNull String query, @NotNull @NotNull String entityName) throws SQLException
- Parameters:
statement
- statement to be executed (caller is responsible for closing statement)query
-entityName
-- Returns:
- Throws:
SQLException
-
getListOfLong
@NotNull public static @NotNull List<Long> getListOfLong(@NotNull @NotNull Connection c, @NotNull @NotNull String query) throws SQLException
- Throws:
SQLException
-
map
public static <T> List<T> map(ResultSet resultSet, Function<ResultSet,T> function) throws SQLException
- Throws:
SQLException
-
runDeleteQuery
public static int runDeleteQuery(@NotNull @NotNull Connection connection, @NotNull @NotNull String tableName, @NotNull @NotNull String idColumn, @NotNull @NotNull Iterable<? extends BambooIdProvider> objects) throws SQLException
- Throws:
SQLException
-
getColumnValue
public static Function<ResultSet,String> getColumnValue(int columnIndex)
Note that the columnIndex is 1-based, not 0-based.
-
getRowData
public static List<String> getRowData(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getAllRows
public static List<List<String>> getAllRows(ResultSet rs, Predicate<List<String>> filter)
-
getLong
public static long getLong(ResultSet resultSet, int columnIndex)
-
-