Class TestDB


  • public class TestDB
    extends Object
    Contains a static DBFacade for testing. This facade initializes on startup and never closes during tests.
    • Constructor Detail

      • TestDB

        public TestDB()
    • Method Detail

      • startupDbFacade

        public static void startupDbFacade()
      • shutdownDbFacade

        public static void shutdownDbFacade()
      • getTestDBAccess

        @NotNull
        public static TestDBAccess getTestDBAccess()
      • getNonReturnedConnectionsCount

        public static int getNonReturnedConnectionsCount()
      • createSchemaFromScratch

        public static void createSchemaFromScratch()
        Creates DB schema with data. Drops all tables before creating (if any exist).
      • createTable

        public static void createTable​(@NotNull
                                       TableDef table,
                                       boolean recreateIfExists)
      • createTable

        public static void createTable​(DBFunctions dbf,
                                       TableDef table,
                                       boolean recreateIfExists)
      • createSchemaIfNotCreated

        public static void createSchemaIfNotCreated()
        Creates DB schema with data on first call, do nothing on next calls.

        Use this procedure carefully - it doesn't guarantee anything.

      • reinitData

        public static void reinitData()
      • reinitMutableData

        public static void reinitMutableData()
      • dropAllTables

        public static void dropAllTables()
        Shuts the DB facade down, drops all true schema tables and then re-init the DB facade. They are all permanent tables for any type of database, and also all temporary tables for Oracle and HSQL.

        All borrowed connections must be released before this method call!

        See Also:
        dropAllPermanentTables(), dropAllTemporaryTables()
      • keepExistingData

        public static boolean keepExistingData()
        keep.db property allows reusing existing DB data in performance tests. Make sure - all your build configurations/projects in your tests are persisted - test seed data is not re-initialized with keep.db property is set - teamcity data directory is not a temporary one, but a fixed non-cleaned up directory
      • dropAllPermanentTables

        public static void dropAllPermanentTables()
        Drops all permanent tables in the current schema.
      • dropAllTemporaryTables

        public static void dropAllTemporaryTables()
        For Oracle and HSQL - drops all temporary tables. For other database types - does nothing. Note 1: in order to drop temporary tables in another DB type just close the connection(s). Note 2: in order to be able to drop temporary tables on Oracle, there are must be no borrowed connections.
      • ensureNoTables

        public static void ensureNoTables​(String... tableNames)
        Drops tables if exist.
        Parameters:
        tableNames - table names to drop.
      • cleanAllTables

        public static void cleanAllTables()
      • cleanMutableTables

        public static void cleanMutableTables()
      • retrieveTableNames

        public static Set<String> retrieveTableNames​(boolean includePermanent,
                                                     boolean includeTemporary,
                                                     boolean lowerCase)
      • resetUsedConnectionsList

        public static void resetUsedConnectionsList()
      • getOurUsedConnections

        public static Set<Connection> getOurUsedConnections()
      • withDB

        public static void withDB​(@NotNull
                                  DBActionNoResults action,
                                  boolean commitOnSuccess)
      • withDB

        public static <T> T withDB​(@NotNull
                                   DBAction<T> action,
                                   boolean commitOnSuccess)
      • withDB2

        public static void withDB2​(@NotNull
                                   DBAction2 actions,
                                   boolean commitOnSuccess)
      • withDataSource

        public static void withDataSource​(@NotNull
                                          DataSourceAction action)
      • getDialect

        @NotNull
        public static SQLDialect getDialect()
      • getSqlRunner

        @NotNull
        public static SQLRunnerEx getSqlRunner()
      • getDBFacade

        @NotNull
        public static DBFacade getDBFacade()
      • getDBType

        @NotNull
        public static DatabaseType getDBType()
      • getServerPaths

        public static ServerPaths getServerPaths()
      • isDatabaseCaseSensitive

        public static boolean isDatabaseCaseSensitive()
      • dumpThreadsSafely

        public static void dumpThreadsSafely()
      • fatalError

        public static void fatalError​(@NotNull
                                      String failureShortDescription,
                                      @Nullable
                                      Throwable exception,
                                      boolean dumpThreads)
      • getJdbcDriversDir

        public static File getJdbcDriversDir()
      • isTestingWithInternalDB

        public static boolean isTestingWithInternalDB()
      • getJdbcDrivers

        public static JdbcDrivers getJdbcDrivers()
      • ensureNoOrphanConnections

        public static void ensureNoOrphanConnections()
      • ensureIntTable

        public static void ensureIntTable​(int N,
                                          boolean withKey)
        Creates a table named "intN" or "intNk" (where N is the given number) with one field name "x", and fill it with rows from 1 to N.
        Parameters:
        N -
      • makeListOfN

        public static List<Integer> makeListOfN​(int min,
                                                int max)
      • getGuidGenerator

        public static GuidGenerator getGuidGenerator()
      • debugQuery

        public static String debugQuery​(String queryText)