Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To create a new SqlGenerator implementation, implement the liquibase.sqlgenerator.SqlGenerator interface.  There are four methods exposed:

Code Block

public boolean supports(SqlStatement statement, Database database)

Return "true" if the generator suppots the passed SqlStatement/Database combination.  Note: your SqlGenerator implementation can pass a SqlStatement as a generic to the class.  If you do, the supports method will automatically include a check for the correct SqlStatement type.

Code Block

public int getPriority();

For each SqlStatement, a chain of SqlGenerators can be supplied from all classes that return true from supports().  The SqlGenerators in the chain will be ordered via getPriority from higest (executed first) to lowest.  Core LiquiBase Liquibase SqlGenerators use priorities of 1 and 5.

Code Block

public ValidationErrors validate(StatementType statement, Database database, SqlGeneratorChain sqlGeneratorChain);

Before executing a SqlGeneratorChain, the validate method will be called on the first (highest priority) SqlGenerator.  If your SqlGenerator is completely replacing lower priority generators, you do not need to call sqlGeneratorChain.validate().  If you are appending to, or wish to allow lower priority generators to still run their validation checks, call sqlGeneratorChain.validate() and include the returned ValidationErrors in your ValidationErrors object.  If any errors are returned, the SqlStatement will not be executed by LiquiBaseLiquibase.

Code Block

public Sql[] generateSql(StatementType statement, Database database, SqlGeneratorChain sqlGeneratorChain);

...

  1. Create the class in the package "liquibase.sqlgenerator.ext".  LiquiBase Liquibase automatically registers SqlGenerators it finds in that package
  2. Call liquibase.sqlgenerator.SqlGeneratorFactory.getInstance().register(yourSqlGenerator)

...