001package io.ebean;
002
003import java.net.URL;
004import java.nio.file.Path;
005import java.util.Map;
006
007/**
008 * Runs DDL and SQL scripts.
009 * <p/>
010 * Typically these are scripts used for testing such as seed SQL scripts or truncate SQL scripts.
011 * <p/>
012 * Scripts are executed in their own transaction and committed on successful completion.
013 *
014 * <h3>Example of simple use</h3>
015 * <pre>{@code
016 *
017 *   Database database = DB.getDefault();
018 *   database.script().run("/scripts/test-script.sql");
019 *
020 * }</pre>
021 */
022public interface ScriptRunner {
023
024  /**
025   * Run a script given the resource path (that should start with "/").
026   */
027  void run(String resourcePath);
028
029  /**
030   * Run a script given the resource path (that should start with "/") and place-holders.
031   *
032   * <pre>{@code
033   *
034   *   Map<String,String> placeholders = new HashMap<>();
035   *   placeholders.put("tableName", "e_basic");
036   *
037   *   Database database = DB.getDefault();
038   *   database.script().run("/scripts/test-script.sql", placeholders);
039   *
040   * }</pre>
041   */
042  void run(String resourcePath, Map<String, String> placeholderMap);
043
044  /**
045   * Run a DDL or SQL script given the resource.
046   */
047  void run(URL resource);
048
049  /**
050   * Run a DDL or SQL script given the resource and place-holders.
051   */
052  void run(URL resource, Map<String, String> placeholderMap);
053
054  /**
055   * Run a DDL or SQL script given the file.
056   */
057  void run(Path file);
058
059  /**
060   * Run a DDL or SQL script given the file and place-holders.
061   */
062  void run(Path file, Map<String, String> placeholderMap);
063
064  /**
065   * Run the raw provided DDL or SQL script.
066   *
067   * @param name          The name of the script for logging purposes
068   * @param content       The SQL content
069   * @param useAutoCommit Set to true to use auto commit true and continue when any errors occur
070   */
071  void runScript(String name, String content, boolean useAutoCommit);
072
073}