Class HyperSqlUtil

java.lang.Object
com.github.hypfvieh.db.HyperSqlUtil

public final class HyperSqlUtil extends Object
HyperSQL utility is intended to support database-backed tests by copying HyperSQL test databases from the classpath to another location (such as the system's temp directory) and performing clean-up work afterward.
  • Constructor Details

    • HyperSqlUtil

      public HyperSqlUtil(String dbBaseName)
      Copies the given database to system temp directory using the calling class name as subdirectory.
      Parameters:
      dbBaseName - the base name of the database without extension; must not be null
    • HyperSqlUtil

      public HyperSqlUtil(String dbBaseName, File targetDir, boolean deleteOnExit)
      Constructs a new instance of HyperSqlUtil to manage a HyperSQL database in a target directory. This constructor ensures the provided target directory exists, is writable, and may optionally delete the directory on JVM exit.

      Warning: Existing database files (dbBaseName + any of the extensions listed in HYPERSQL_EXTENSIONS) will be removed!

      Parameters:
      dbBaseName - the base name of the database without extension; must not be null
      targetDir - the directory where the database files will be managed; must not be null
      deleteOnExit - specifies if the target directory should be deleted when the JVM exits
      Throws:
      NullPointerException - if dbBaseName or targetDir is null
      RuntimeException - if the target directory cannot be created or its read/write permissions cannot be set
  • Method Details

    • getDbPath

      public String getDbPath()
      Returns the path including database file name to use in JDBC URL.
      Returns:
      String
    • copyHsqlDbFiles

      public HyperSqlUtil copyHsqlDbFiles(String searchPath, boolean overwrite)
      See Also:
      • copyHsqlDbFiles(String, String, boolean, String...)
    • copyHsqlDbFiles

      public HyperSqlUtil copyHsqlDbFiles()
      See Also:
      • copyHsqlDbFiles(String, String, boolean, String...)
    • cleanupTargetDir

      public void cleanupTargetDir()
      Cleans and removes the target directory.
    • getTargetDir

      public File getTargetDir()
    • toString

      public String toString()
      Overrides:
      toString in class Object