Top Description Fields Methods
liquibase.sqlgenerator

public Interface SqlGenerator<T extends SqlStatement>

extends PrioritizedService
Known Direct Implementers
liquibase.sqlgenerator.core.AbstractSqlGenerator
Type Parameters
<T>
Used to specify which type of SqlStatement this generator supports. If it supports multiple SqlStatement types, pass SqlStatement. The SqlGeneratorFactory will use this parameter to augment the response from the supports() method
Imports
liquibase.database.Database, liquibase.exception.ValidationErrors, .Warnings, liquibase.servicelocator.PrioritizedService, liquibase.sql.Sql, liquibase.statement.SqlStatement

SqlGenerator implementations take a database-independent SqlStatement interface and create a database-specific Sql object. SqlGenerators are registered with the SqlGeneratorFactory, which is used to determine the correct generator to use for a given statement/database combination.

The SqlGenerator implementations are responsible for determining whether the data contained in the SqlStatement method is valid using the validate method.

Naming Conventions:
Default SqlGenerators for a particular SqlStatement use the same name as the SqlStatement class, replacing "Statement" with "Generator" (e.g.: CreateTableStatement -> CreateTableGenerator). Database-specific or alternate SqlGenerators append a description of what makes them different appended (e.g. CreateTableStatement -> CreateTableGeneratorOracle)

Note

There is only one instance of each SqlGenerator implementation created, and they must be thread safe.

Lifecycle:

  1. Instance of SqlGenerator subclass is created when registered with SqlGeneratorFactory
  2. For each SqlStatement to execute, SqlGeneratorFactory calls supports() to determine if the given SqlGenerator will work for the current SqlStatement/Database combination
  3. SqlGeneratorFactory calls getPriority to determine which of all the SqlGenerators that support a given SqlStatement/Database combination is the best to use.
  4. Liquibase calls validate() on the best SqlGenerator to determine if the data contained in the SqlStatement is correct and complete for the given Database
  5. If validate returns a no-error ValidationErrors object, Liquibase will call the generateSql() method and execute the resulting SQL against the database.
See Also
SqlGeneratorFactory, liquibase.statement.SqlStatement, liquibase.sql.Sql

Field Summary

Modifier and TypeField and Description
public static final Sql[]
EMPTY_SQL

Represent an empty array of Sql.

public static final int
public static final int
Inherited from liquibase.servicelocator.PrioritizedService:
COMPARATOR

Method Summary

Modifier and TypeMethod and Description
public boolean
public Sql[]
generateSql(T statement, Database database, SqlGeneratorChain<T> sqlGeneratorChain)

Generate the actual Sql for the given statement and database.

public boolean
generateStatementsIsVolatile(Database database)

Does this change require access to the database metadata?

public int
getPriority()

Redeclares liquibase.servicelocator.PrioritizedService.getPriority.

Of all the SqlGenerators that "support" a given SqlStatement/Database, SqlGeneratorFactory will return the one with the highest priority.

public boolean
supports(T statement, Database database)

Does this generator support the given statement/database combination?

public ValidationErrors
validate(T statement, Database database, SqlGeneratorChain<T> sqlGeneratorChain)

Validate the data contained in the SqlStatement.

public Warnings
warn(T statementType, Database database, SqlGeneratorChain<T> sqlGeneratorChain)

Field Detail

EMPTY_SQLback to summary
public static final Sql[] EMPTY_SQL

Represent an empty array of Sql.

PRIORITY_DATABASEback to summary
public static final int PRIORITY_DATABASE

Hides liquibase.servicelocator.PrioritizedService.PRIORITY_DATABASE.

PRIORITY_DEFAULTback to summary
public static final int PRIORITY_DEFAULT

Hides liquibase.servicelocator.PrioritizedService.PRIORITY_DEFAULT.

Method Detail

generateRollbackStatementsIsVolatileback to summary
public boolean generateRollbackStatementsIsVolatile(Database database)
generateSqlback to summary
public Sql[] generateSql(T statement, Database database, SqlGeneratorChain<T> sqlGeneratorChain)

Generate the actual Sql for the given statement and database.

generateStatementsIsVolatileback to summary
public boolean generateStatementsIsVolatile(Database database)

Does this change require access to the database metadata? If true, the change cannot be used in an updateSql-style command.

getPriorityback to summary
public int getPriority()

Redeclares liquibase.servicelocator.PrioritizedService.getPriority.

Of all the SqlGenerators that "support" a given SqlStatement/Database, SqlGeneratorFactory will return the one with the highest priority.

Annotations
@Override
supportsback to summary
public boolean supports(T statement, Database database)

Does this generator support the given statement/database combination? Do not validate the statement with this method, only return if it can support it.

validateback to summary
public ValidationErrors validate(T statement, Database database, SqlGeneratorChain<T> sqlGeneratorChain)

Validate the data contained in the SqlStatement. If there are no errors, return an empty ValidationErrors object, not a null value. Liquibase will inspect the ValidationErrors result before attempting to call generateSql.

warnback to summary
public Warnings warn(T statementType, Database database, SqlGeneratorChain<T> sqlGeneratorChain)