Class LiquibaseStatementsWriter

java.lang.Object
org.fastnate.generator.statements.AbstractStatementsWriter
org.fastnate.generator.statements.LiquibaseStatementsWriter
All Implemented Interfaces:
Closeable, AutoCloseable, StatementsWriter

public class LiquibaseStatementsWriter extends AbstractStatementsWriter
Generates statements for the Liquibase changelog file.
Author:
Tobias Liefke
See Also:
  • Field Details

  • Constructor Details

    • LiquibaseStatementsWriter

      public LiquibaseStatementsWriter(GeneratorContext context) throws XMLStreamException, FileNotFoundException
      Creates a new writer which generates an XML file with "UTF-8" encoding.
      Parameters:
      context - contains all the settings that we need to build the file
      Throws:
      XMLStreamException - if already the root element could not be created
      FileNotFoundException - if the parent directory does not exist
    • LiquibaseStatementsWriter

      public LiquibaseStatementsWriter(GeneratorDialect dialect, OutputStream outputStream, String version) throws XMLStreamException
      Creates a new writer which generates an XML file with "UTF-8" encoding.
      Parameters:
      dialect - the database dialect for any plain SQL statement
      outputStream - the target stream, will be close when this wirter is closed
      version - the liquibase version - this is only for the referenced schema and won't change anything else
      Throws:
      XMLStreamException - if already the root element could not be created
    • LiquibaseStatementsWriter

      public LiquibaseStatementsWriter(GeneratorDialect dialect, XMLStreamWriter writer, String version) throws XMLStreamException
      Creates a new writer.
      Parameters:
      dialect - the database dialect for any plain SQL statement
      writer - the stream writer for generating the XML
      version - the liquibase version - this is only for the referenced schema and won't change anything else
      Throws:
      XMLStreamException - if already the root element could not be created
    • LiquibaseStatementsWriter

      public LiquibaseStatementsWriter(OutputStream outputStream, String version) throws XMLStreamException
      Creates a new writer which generates an XML file with "UTF-8" encoding and use the H2 dialect for any plain statement.
      Parameters:
      outputStream - the target stream, will be close when this wirter is closed
      version - the liquibase version - this is only for the referenced schema and won't change anything else
      Throws:
      XMLStreamException - if already the root element could not be created
    • LiquibaseStatementsWriter

      public LiquibaseStatementsWriter(XMLStreamWriter writer, String version) throws XMLStreamException
      Creates a new writer which uses H2 for any plain statement.
      Parameters:
      writer - the stream writer for generating the XML
      version - the liquibase version - this is only for the referenced schema and won't change anything else
      Throws:
      XMLStreamException - if already the root element could not be created
  • Method Details

    • close

      public void close() throws IOException
      Writes the remaining elements. This will not close the output stream, you will need to close it manually.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AbstractStatementsWriter
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Description copied from interface: StatementsWriter
      Flushes any open statements.
      Specified by:
      flush in interface StatementsWriter
      Overrides:
      flush in class AbstractStatementsWriter
      Throws:
      IOException - if the target throws an exception
    • startNextChangeSet

      public void startNextChangeSet(String id, String author, String comment) throws XMLStreamException
      Closes the current change set (if any was started) and sets the infos of the next change set.
      Parameters:
      id - the ID of the next change set
      author - the author of the next change set
      comment - the (optional) comment of the next change set
      Throws:
      XMLStreamException - if there is an error during closing the current change set
    • writeComment

      public void writeComment(String comment) throws IOException
      Description copied from interface: StatementsWriter
      Writes a SQL comment to the target.
      Specified by:
      writeComment in interface StatementsWriter
      Overrides:
      writeComment in class AbstractStatementsWriter
      Parameters:
      comment - the comment to write
      Throws:
      IOException - if the target throws an exception
    • writePlainStatement

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

      public void writeSectionSeparator() throws IOException
      Description copied from interface: StatementsWriter
      Writes a new line to the target file to separate different sections in the SQL file.
      Specified by:
      writeSectionSeparator in interface StatementsWriter
      Overrides:
      writeSectionSeparator in class AbstractStatementsWriter
      Throws:
      IOException - if the target throws such an exception
    • writeStatement

      public void writeStatement(EntityStatement statement) throws IOException
      Description copied from interface: StatementsWriter
      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
    • getDialect

      public GeneratorDialect getDialect()
      The current database dialect (in case any plain SQL statement needs to be written).
    • getWriter

      public XMLStreamWriter getWriter()
      The receiver of our XML elements.
    • isRelativeDatesSupported

      public boolean isRelativeDatesSupported()
      Indicates if our liquibase version supports relative dates.
    • getChangeSetId

      public String getChangeSetId()
      The ID of the next created change set.
    • getChangeSetAuthour

      public String getChangeSetAuthour()
      The author of the next created change set.
    • getChangeSetComment

      public String getChangeSetComment()
      The comment of the next created change set.
    • isChangeSetStarted

      public boolean isChangeSetStarted()
      Indicates if we are currently in a changeSet.