类 JdbcTestUtils

java.lang.Object
cn.taketoday.test.jdbc.JdbcTestUtils

public abstract class JdbcTestUtils extends Object
JdbcTestUtils is a collection of JDBC related utility functions intended to simplify standard database testing scenarios.
从以下版本开始:
4.0
作者:
Thomas Risberg, Sam Brannen, Juergen Hoeller, Phillip Webb, Chris Baldwin, Harry Yang
另请参阅:
  • JdbcTemplate
  • ScriptUtils
  • ResourceDatabasePopulator
  • DatabasePopulator
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    private static final cn.taketoday.logging.Logger
     
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static int
    countRowsInTable(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String tableName)
    Count the rows in the given table.
    static int
    countRowsInTable(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String tableName)
    Count the rows in the given table.
    static int
    countRowsInTableWhere(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String tableName, String whereClause)
    Count the rows in the given table, using the provided WHERE clause.
    static int
    countRowsInTableWhere(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String tableName, String whereClause)
    Count the rows in the given table, using the provided WHERE clause.
    static int
    deleteFromTables(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String... tableNames)
    Delete all rows from the specified tables.
    static int
    deleteFromTables(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String... tableNames)
    Delete all rows from the specified tables.
    static int
    deleteFromTableWhere(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String tableName, String whereClause, Object... args)
    Delete rows from the given table, using the provided WHERE clause.
    static int
    deleteFromTableWhere(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String tableName, String whereClause, Object... args)
    Delete rows from the given table, using the provided WHERE clause.
    static void
    dropTables(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String... tableNames)
    Drop the specified tables.
    static void
    dropTables(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String... tableNames)
    Drop the specified tables.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • logger

      private static final cn.taketoday.logging.Logger logger
  • 构造器详细资料

    • JdbcTestUtils

      public JdbcTestUtils()
  • 方法详细资料

    • countRowsInTable

      public static int countRowsInTable(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String tableName)
      Count the rows in the given table.
      参数:
      jdbcTemplate - the JdbcOperations with which to perform JDBC operations
      tableName - name of the table to count rows in
      返回:
      the number of rows in the table
    • countRowsInTable

      public static int countRowsInTable(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String tableName)
      Count the rows in the given table.
      参数:
      jdbcClient - the JdbcClient with which to perform JDBC operations
      tableName - name of the table to count rows in
      返回:
      the number of rows in the table
    • countRowsInTableWhere

      public static int countRowsInTableWhere(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String tableName, @Nullable String whereClause)
      Count the rows in the given table, using the provided WHERE clause.

      If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated SELECT statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "SELECT COUNT(0) FROM person WHERE name = 'Bob' and age > 25".

      参数:
      jdbcTemplate - the JdbcOperations with which to perform JDBC operations
      tableName - the name of the table to count rows in
      whereClause - the WHERE clause to append to the query
      返回:
      the number of rows in the table that match the provided WHERE clause
    • countRowsInTableWhere

      public static int countRowsInTableWhere(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String tableName, @Nullable String whereClause)
      Count the rows in the given table, using the provided WHERE clause.

      If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated SELECT statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "SELECT COUNT(0) FROM person WHERE name = 'Bob' and age > 25".

      参数:
      jdbcClient - the JdbcClient with which to perform JDBC operations
      tableName - the name of the table to count rows in
      whereClause - the WHERE clause to append to the query
      返回:
      the number of rows in the table that match the provided WHERE clause
    • deleteFromTables

      public static int deleteFromTables(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String... tableNames)
      Delete all rows from the specified tables.
      参数:
      jdbcTemplate - the JdbcOperations with which to perform JDBC operations
      tableNames - the names of the tables to delete from
      返回:
      the total number of rows deleted from all specified tables
    • deleteFromTables

      public static int deleteFromTables(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String... tableNames)
      Delete all rows from the specified tables.
      参数:
      jdbcClient - the JdbcClient with which to perform JDBC operations
      tableNames - the names of the tables to delete from
      返回:
      the total number of rows deleted from all specified tables
    • deleteFromTableWhere

      public static int deleteFromTableWhere(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String tableName, String whereClause, Object... args)
      Delete rows from the given table, using the provided WHERE clause.

      If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated DELETE statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "DELETE FROM person WHERE name = 'Bob' and age > 25".

      As an alternative to hard-coded values, the "?" placeholder can be used within the WHERE clause, binding to the given arguments.

      参数:
      jdbcTemplate - the JdbcOperations with which to perform JDBC operations
      tableName - the name of the table to delete rows from
      whereClause - the WHERE clause to append to the query
      args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale.
      返回:
      the number of rows deleted from the table
    • deleteFromTableWhere

      public static int deleteFromTableWhere(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String tableName, String whereClause, Object... args)
      Delete rows from the given table, using the provided WHERE clause.

      If the provided WHERE clause contains text, it will be prefixed with " WHERE " and then appended to the generated DELETE statement. For example, if the provided table name is "person" and the provided where clause is "name = 'Bob' and age > 25", the resulting SQL statement to execute will be "DELETE FROM person WHERE name = 'Bob' and age > 25".

      As an alternative to hard-coded values, the "?" placeholder can be used within the WHERE clause, binding to the given arguments.

      参数:
      jdbcClient - the JdbcClient with which to perform JDBC operations
      tableName - the name of the table to delete rows from
      whereClause - the WHERE clause to append to the query
      args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale.
      返回:
      the number of rows deleted from the table
    • dropTables

      public static void dropTables(cn.taketoday.jdbc.core.JdbcOperations jdbcTemplate, String... tableNames)
      Drop the specified tables.
      参数:
      jdbcTemplate - the JdbcOperations with which to perform JDBC operations
      tableNames - the names of the tables to drop
    • dropTables

      public static void dropTables(cn.taketoday.jdbc.core.simple.JdbcClient jdbcClient, String... tableNames)
      Drop the specified tables.
      参数:
      jdbcClient - the JdbcClient with which to perform JDBC operations
      tableNames - the names of the tables to drop