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