Package liquibase.executor.jvm
Class JdbcExecutor
java.lang.Object
liquibase.executor.AbstractExecutor
liquibase.executor.jvm.JdbcExecutor
- Direct Known Subclasses:
SnowflakeJdbcExecutor
Class to simplify execution of SqlStatements. Based heavily on Spring's JdbcTemplate.
Note: This class is currently intended for Liquibase-internal use only and may change without notice in the future
Note: This class is currently intended for Liquibase-internal use only and may change without notice in the future
-
Field Summary
Fields inherited from class liquibase.executor.AbstractExecutor
database, resourceAccessor
Fields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a comment to the database.execute
(liquibase.executor.jvm.CallableStatementCallback action, List<SqlVisitor> sqlVisitors) execute
(liquibase.executor.jvm.StatementCallback action, List<SqlVisitor> sqlVisitors) void
execute
(SqlStatement sql) void
execute
(SqlStatement sql, List<SqlVisitor> sqlVisitors) protected RowMapper
Create a new RowMapper for reading columns as key-value pairs.getName()
Return the name of the Executorint
Return the Executor priorityprotected RowMapper
getSingleColumnRowMapper
(Class requiredType) Create a new RowMapper for reading result objects from a single column.query
(SqlStatement sql, liquibase.executor.jvm.ResultSetExtractor rse) query
(SqlStatement sql, liquibase.executor.jvm.ResultSetExtractor rse, List<SqlVisitor> sqlVisitors) query
(SqlStatement sql, RowMapper rowMapper) query
(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors) int
queryForInt
(SqlStatement sql) Executes a query that is expected to return a scalar (1 row, 1 column).int
queryForInt
(SqlStatement sql, List<SqlVisitor> sqlVisitors) Applies a number of SqlVisitors to the sql query.queryForList
(SqlStatement sql) Executes a given SQL statement and returns a List of rows.queryForList
(SqlStatement sql, Class elementType) queryForList
(SqlStatement sql, Class elementType, List<SqlVisitor> sqlVisitors) queryForList
(SqlStatement sql, List<SqlVisitor> sqlVisitors) Applies a list of SqlVisitors to the SQL query, then executes the (possibly modified) SQL query and lastly, returns the list of rows.long
queryForLong
(SqlStatement sql) Executes a query that is expected to return a scalar (1 row, 1 column).long
queryForLong
(SqlStatement sql, List<SqlVisitor> sqlVisitors) Applies a number of SqlVisitors to the sql query.<T> T
queryForObject
(SqlStatement sql, Class<T> requiredType) Execute a query that is expected to return a scalar (1 row, 1 column).<T> T
queryForObject
(SqlStatement sql, Class<T> requiredType, List<SqlVisitor> sqlVisitors) Applies a number of SqlVisitors to the sql query.queryForObject
(SqlStatement sql, RowMapper rowMapper) queryForObject
(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors) int
update
(SqlStatement sql) int
update
(SqlStatement sql, List<SqlVisitor> sqlVisitors) boolean
Methods inherited from class liquibase.executor.AbstractExecutor
applyVisitors, execute, execute, modifyChangeSet, setDatabase, setResourceAccessor, validate
-
Field Details
-
SHOULD_UPDATE_ROWS_AFFECTED_SCOPE_KEY
- See Also:
-
ROWS_AFFECTED_SCOPE_KEY
- See Also:
-
-
Constructor Details
-
JdbcExecutor
public JdbcExecutor()
-
-
Method Details
-
getName
Return the name of the Executor- Specified by:
getName
in interfaceExecutor
- Specified by:
getName
in classAbstractExecutor
- Returns:
- String The Executor name
-
getPriority
public int getPriority()Return the Executor priority- Specified by:
getPriority
in interfaceExecutor
- Specified by:
getPriority
in classAbstractExecutor
- Returns:
- int The Executor priority
-
updatesDatabase
public boolean updatesDatabase() -
execute
public Object execute(liquibase.executor.jvm.StatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException - Throws:
DatabaseException
-
execute
public Object execute(liquibase.executor.jvm.CallableStatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException - Throws:
DatabaseException
-
execute
- Throws:
DatabaseException
-
execute
- Throws:
DatabaseException
-
query
public Object query(SqlStatement sql, liquibase.executor.jvm.ResultSetExtractor rse) throws DatabaseException - Throws:
DatabaseException
-
query
public Object query(SqlStatement sql, liquibase.executor.jvm.ResultSetExtractor rse, List<SqlVisitor> sqlVisitors) throws DatabaseException - Throws:
DatabaseException
-
query
- Throws:
DatabaseException
-
query
public List query(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors) throws DatabaseException - Throws:
DatabaseException
-
queryForObject
- Throws:
DatabaseException
-
queryForObject
public Object queryForObject(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors) throws DatabaseException - Throws:
DatabaseException
-
queryForObject
Description copied from interface:Executor
Execute a query that is expected to return a scalar (1 row, 1 column). It is expected that the scalar can be cast into an object of type T.- Parameters:
sql
- The query to execute- Returns:
- An object of type T, if successful. May also return null if no object is found.
- Throws:
DatabaseException
- in case something goes wrong during the query execution
-
queryForObject
public <T> T queryForObject(SqlStatement sql, Class<T> requiredType, List<SqlVisitor> sqlVisitors) throws DatabaseException Description copied from interface:Executor
Applies a number of SqlVisitors to the sql query. Then, executes the (possibly modified) query. The query is expected to return a scalar (1 row, 1 column). That scalar is expected to return a single value that can be cast into an object of type T.- Parameters:
sql
- The query to execute- Returns:
- An object of type T, if successful. May also return null if no object is found.
- Throws:
DatabaseException
- in case something goes wrong during the query execution
-
queryForLong
Description copied from interface:Executor
Executes a query that is expected to return a scalar (1 row, 1 column). It is expected that the scalar can be cast into a long.- Parameters:
sql
- The query to execute- Returns:
- A long value, if successful
- Throws:
DatabaseException
- in case something goes wrong during the query execution
-
queryForLong
Description copied from interface:Executor
Applies a number of SqlVisitors to the sql query. Then, executes the (possibly modified) query. The query is expected to return a scalar (1 row, 1 column), and that scalar is expected to be a long value.- Parameters:
sql
- The query to execute- Returns:
- A long value, if successful
- Throws:
DatabaseException
- in case something goes wrong during the query execution
-
queryForInt
Description copied from interface:Executor
Executes a query that is expected to return a scalar (1 row, 1 column). It is expected that the scalar can be cast into an int.- Parameters:
sql
- The query to execute- Returns:
- An integer, if successful
- Throws:
DatabaseException
- in case something goes wrong during the query execution
-
queryForInt
Description copied from interface:Executor
Applies a number of SqlVisitors to the sql query. Then, executes the (possibly modified) query. The query is expected to return a scalar (1 row, 1 column), and that scalar is expected to be an int.- Parameters:
sql
- The query to execute- Returns:
- An integer, if successful
- Throws:
DatabaseException
- in case something goes wrong during the query execution
-
queryForList
- Throws:
DatabaseException
-
queryForList
public List queryForList(SqlStatement sql, Class elementType, List<SqlVisitor> sqlVisitors) throws DatabaseException - Throws:
DatabaseException
-
queryForList
Description copied from interface:Executor
Executes a given SQL statement and returns a List of rows. Each row is represented a a Map<String, ?>, where the String is the column name and the value if the content of the column in the row (=cell).- Parameters:
sql
- the SQL query to execute- Returns:
- a List of [Column name] -> [column value]-mapped rows.
- Throws:
DatabaseException
- if an error occurs during SQL processing (e.g. the SQL is not valid for the database)
-
queryForList
public List<Map<String,?>> queryForList(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException Description copied from interface:Executor
Applies a list of SqlVisitors to the SQL query, then executes the (possibly modified) SQL query and lastly, returns the list of rows. Each row is represented a a Map<String, ?>, where the String is the column name and the value if the content of the column in the row (=cell).- Parameters:
sql
- the SQL query to execute- Returns:
- a List of [Column name] -> [column value]-mapped rows.
- Throws:
DatabaseException
- if an error occurs during SQL processing (e.g. the SQL is not valid for the database)
-
update
- Throws:
DatabaseException
-
update
- Throws:
DatabaseException
-
getColumnMapRowMapper
Create a new RowMapper for reading columns as key-value pairs.- Returns:
- the RowMapper to use
- See Also:
-
getSingleColumnRowMapper
Create a new RowMapper for reading result objects from a single column.- Parameters:
requiredType
- the type that each result object is expected to match- Returns:
- the RowMapper to use
- See Also:
-
SingleColumnRowMapper
-
comment
Description copied from interface:Executor
Adds a comment to the database. Currently does nothing but is overridden in the output JDBC template- Throws:
DatabaseException
-