Interface StatementsWriter

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
AbstractStatementsWriter, ConnectedStatementsWriter, FileStatementsWriter, LiquibaseStatementsWriter, ListStatementsWriter, PostgreSqlBulkWriter

public interface StatementsWriter extends Closeable
Responsible to write EntityStatements to a file or to the database.
Author:
Tobias Liefke
  • Method Details

    • createInsertStatement

      TableStatement createInsertStatement(GeneratorDialect dialect, GeneratorTable table)
      Creates a container for a dedicated "insert into table" statement.
      Parameters:
      dialect - the current database dialect
      table - the name of the table
      Returns:
      the created statement
    • createPlainStatement

      EntityStatement createPlainStatement(GeneratorDialect dialect, String sql)
      Creates a container for a plain SQL statement, which is just executed "as is".
      Parameters:
      dialect - the current database dialect
      sql - the content of the sql statement (without any delimiter)
      Returns:
      the created statement
    • createUpdateStatement

      TableStatement createUpdateStatement(GeneratorDialect dialect, GeneratorTable table, GeneratorColumn idColumn, ColumnExpression idValue)
      Creates a container for a dedicated "update table" statement.
      Parameters:
      dialect - the current database dialect
      table - the name of the affected table
      idColumn - the column that contains the id of the changed entity
      idValue - the expression for the id of the changed entity
      Returns:
      the created statement
    • flush

      void flush() throws IOException
      Flushes any open statements.
      Throws:
      IOException - if the target throws an exception
    • truncateTables

      default void truncateTables(GeneratorContext context)
      Truncates all discovered tables before any data is written to that tables.
      Parameters:
      context - the generator context
    • writeComment

      void writeComment(String comment) throws IOException
      Writes a SQL comment to the target.
      Parameters:
      comment - the comment to write
      Throws:
      IOException - if the target throws an exception
    • writePlainStatement

      default void writePlainStatement(GeneratorDialect dialect, String sql) throws IOException
      Writes a plain SQL statement. Shortcut for writeStatement(createPlainStatement(sql), dialect).
      Parameters:
      dialect - the current database dialect
      sql - the content of the SQL statement
      Throws:
      IOException - if the file or database throws an exception
    • writeSectionSeparator

      void writeSectionSeparator() throws IOException
      Writes a new line to the target file to separate different sections in the SQL file.
      Throws:
      IOException - if the target throws such an exception
    • writeStatement

      void writeStatement(EntityStatement statement) throws IOException
      Writes the given statement to a file or database.
      Parameters:
      statement - contains the values to write
      Throws:
      IOException - if the file or database throws an exception