Class DBSQLScript

java.lang.Object
org.apache.empire.db.DBSQLScript
All Implemented Interfaces:
Iterable<String>, DBContextAware

public class DBSQLScript extends Object implements DBContextAware, Iterable<String>
DBSQLScript
This class is a collection of sql command strings.
The class is used for obtaining and executing DDL commands supplied by the database dbms (@see DBMSHandler.getDDLScript(DDLActionType, DBObject, DBSQLScript))
  • Field Details

  • Constructor Details

    • DBSQLScript

      public DBSQLScript(DBContext context)
    • DBSQLScript

      public DBSQLScript(DBContext context, String commandSeparator)
  • Method Details

    • getContext

      public DBContext getContext()
      Returns the current Context
      Specified by:
      getContext in interface DBContextAware
      Returns:
      the database context
    • addStmt

      public void addStmt(String sql)
      Adds a statement to the script.
      Parameters:
      sql - the statement
    • addStmt

      public void addStmt(String sql, Object[] params)
      Adds a statement to the script.
      Parameters:
      sql - the statement
      params - the statement parameters
    • addStmt

      public final void addStmt(DBSQLBuilder sql)
      Adds a statement to the script.
      The supplied StringBuilder will be reset to a length of 0
      Parameters:
      sql - the statement
    • addInsert

      public void addInsert(DBCommand cmd)
      Adds an insert statement
      Parameters:
      cmd - the insert command
    • addUpdate

      public void addUpdate(DBCommand cmd)
      Adds an update statement
      Parameters:
      cmd - the insert command
    • addDelete

      public void addDelete(DBCommand cmd, DBTable table)
      Adds an delete statement
      Parameters:
      cmd - the insert command
      table - the table to delete
    • getCount

      public int getCount()
      Returns the number of statements in this script
      Returns:
      number of statements in this script
    • getStmt

      public String getStmt(int i)
      Returns the statement command at the given index
      Parameters:
      i - index of the statement to retrieve
      Returns:
      the sql statement command
    • getStmtParams

      public Object[] getStmtParams(int i)
      Returns the statement command at the given index
      Parameters:
      i - index of the statement to retrieve
      Returns:
      the sql statement params
    • insertStmt

      public void insertStmt(int i, String stmt, Object[] params)
      Inserts an entry in the list
      Parameters:
      i - index of the statement to replace
      stmt - the new statement for this index, or NULL to remove the statement
      params - the statement params
    • insertStmt

      public final void insertStmt(int i, String stmt)
      Inserts an entry in the list
      Parameters:
      i - index of the statement to replace
      stmt - the new statement for this index, or NULL to remove the statement
    • replaceStmt

      public void replaceStmt(int i, String cmd, Object[] params)
      Replaces an entry in the list
      Parameters:
      i - index of the statement to replace
      cmd - the new statement for this index, or NULL to remove the statement
      params - the command params (optional)
    • replaceStmt

      public final void replaceStmt(int i, String cmd)
      Replaces an entry in the list
      Parameters:
      i - index of the statement to replace
      cmd - the new statement for this index, or NULL to remove the statement
    • removeStmt

      public void removeStmt(int i)
      Removes a statement from the list
      Parameters:
      i - index of the statement to replace
    • clear

      public void clear()
      Clears the script by removing all statements
    • executeAll

      public int executeAll(boolean ignoreErrors)
      Executes all SQL Statements one by one using the supplied dbms and connection.
      Parameters:
      ignoreErrors - true if errors should be ignored
      Returns:
      number of records affected
    • executeAll

      public final int executeAll()
      Executes all SQL Statements one by one using the supplied dbms and connection.
      Returns:
      number of records affected
    • executeBatch

      public int executeBatch()
      Executes all SQL Statements as a JDBC Batch Job.
      Returns:
      the total number of affected records
    • iterator

      public Iterator<String> iterator()
      Returns an iterator
      Specified by:
      iterator in interface Iterable<String>
    • toString

      public String toString()
      Returns the sql script as a string
      Overrides:
      toString in class Object
    • logStmt

      protected void logStmt(DBUtils utils, String sqlCmd, Object[] sqlParams, boolean comment)
      logs a statement before execution
      Parameters:
      utils - the DBUils
      sqlCmd - the statement
      sqlParams - the params
      comment - flag indicating whether the command is a comment or not
    • executeStmt

      protected int executeStmt(DBMSHandler dbms, String sqlCmd, Object[] sqlParams, Connection conn) throws SQLException
      Executes a single statement
      Parameters:
      dbms - the dbms
      sqlCmd - the sql statement
      sqlParams - the statement params
      conn - the connection
      Returns:
      number of rows affected
      Throws:
      SQLException