Class MySqlDumpRunner

java.lang.Object
br.net.dd.netherwingcore.database.parser.MySqlDumpRunner

public final class MySqlDumpRunner extends Object
MySqlDumpRunner is a utility class designed to execute SQL dump files against a MySQL database connection. It reads SQL statements from a specified dump file, handles comments and string literals correctly, and executes the statements while managing transactions and error handling. The class includes an inner static class, SqlStatementIterator, which is responsible for parsing the SQL dump file and iterating over individual SQL statements, taking into account MySQL-specific syntax such as comments, string literals, and custom delimiters.
  • Constructor Details

    • MySqlDumpRunner

      public MySqlDumpRunner()
  • Method Details

    • runSqlDump

      public static void runSqlDump(Connection conn, Path dumpFile) throws IOException, SQLException
      Executes the SQL statements contained in the specified dump file against the provided database connection. The method manages transactions, disables foreign key and unique checks for performance, and ensures that any errors during execution are properly handled with rollbacks.
      Parameters:
      conn - the Connection object representing the database connection to execute the SQL statements on
      dumpFile - the Path object representing the location of the SQL dump file to be executed
      Throws:
      IOException - if there is an error reading the dump file
      SQLException - if there is an error executing any of the SQL statements