Top Description Inners Fields Constructors Methods
liquibase.executor.jvm

public Class JdbcExecutor

extends AbstractExecutor
Class Inheritance
Known Direct Subclasses
liquibase.executor.jvm.SnowflakeJdbcExecutor
Imports
liquibase.Scope, liquibase.database.DatabaseConnection, .OfflineConnection, .PreparedStatementFactory, liquibase.database.core.Db2zDatabase, .OracleDatabase, liquibase.database.jvm.JdbcConnection, liquibase.exception.DatabaseException, liquibase.executor.AbstractExecutor, liquibase.listener.SqlListener, liquibase.logging.Logger, liquibase.servicelocator.PrioritizedService, liquibase.sql.CallableSql, .Sql, .SqlConfiguration, liquibase.sql.visitor.SqlVisitor, liquibase.sqlgenerator.SqlGeneratorFactory, liquibase.statement.CallableSqlStatement, .CompoundStatement, .ExecutablePreparedStatement, .SqlStatement, liquibase.statement.core.RawParameterizedSqlStatement, liquibase.util.JdbcUtil, .StringUtil, java.sql.*, java.util.ArrayList, .List, .Map, java.util.concurrent.atomic.AtomicInteger, java.util.logging.Level

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class

Field Summary

Inherited from liquibase.executor.AbstractExecutor:
databaseresourceAccessor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
addUpdateCountToScope(int updateCount)

private String
private void
checkCallStatus(ResultSet resultSet, String status)

public void
comment(String message)

Implements liquibase.executor.Executor.comment.

Adds a comment to the database.

public Object
execute(StatementCallback action, List<SqlVisitor> sqlVisitors)

public Object
public void
public void
execute(final SqlStatement sql, final List<SqlVisitor> sqlVisitors)

Implements liquibase.executor.Executor.execute.

private void
executeDb2ZosComplexStatement(final SqlStatement sqlStatement, final List<SqlVisitor> sqlVisitors)

protected RowMapper

Returns:

the RowMapper to use
getColumnMapRowMapper
()

Create a new RowMapper for reading columns as key-value pairs.

pack-priv String
public String

Returns:

String The Executor name
getName
()

Implements abstract liquibase.executor.AbstractExecutor.getName.

Implements liquibase.executor.Executor.getName.

Return the name of the Executor

public int

Returns:

int The Executor priority
getPriority
()

Implements abstract liquibase.executor.AbstractExecutor.getPriority.

Implements liquibase.executor.Executor.getPriority.

Return the Executor priority

protected RowMapper

Returns:

the RowMapper to use
getSingleColumnRowMapper
(Class<T>
the type that each result object is expected to match
requiredType
)

Create a new RowMapper for reading result objects from a single column.

public Object
query(final SqlStatement sql, final ResultSetExtractor rse)

public Object
query(final SqlStatement sql, final ResultSetExtractor rse, final List<SqlVisitor> sqlVisitors)

public List<E>
query(SqlStatement sql, RowMapper rowMapper)

public List<E>
query(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors)

public int
queryForInt(SqlStatement
The query to execute
sql
)

Implements liquibase.executor.Executor.queryForInt.

Executes a query that is expected to return a scalar (1 row, 1 column).

public int
queryForInt(SqlStatement
The query to execute
sql
,
List<SqlVisitor> sqlVisitors)

Implements liquibase.executor.Executor.queryForInt.

Applies a number of SqlVisitors to the sql query.

public List<E>
public List<E>
public List<Map<String, ?>>
queryForList(SqlStatement
the SQL query to execute
sql
)

Implements liquibase.executor.Executor.queryForList.

Executes a given SQL statement and returns a List of rows.

public List<Map<String, ?>>
queryForList(SqlStatement
the SQL query to execute
sql
,
List<SqlVisitor> sqlVisitors)

Implements liquibase.executor.Executor.queryForList.

Applies a list of SqlVisitors to the SQL query, then executes the (possibly modified) SQL query and lastly, returns the list of rows.

public long
queryForLong(SqlStatement
The query to execute
sql
)

Implements liquibase.executor.Executor.queryForLong.

Executes a query that is expected to return a scalar (1 row, 1 column).

public long
queryForLong(SqlStatement
The query to execute
sql
,
List<SqlVisitor> sqlVisitors)

Implements liquibase.executor.Executor.queryForLong.

Applies a number of SqlVisitors to the sql query.

public Object
public Object
queryForObject(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors)

public <T> T
queryForObject(SqlStatement
The query to execute
sql
,
Class<T> requiredType)

Implements liquibase.executor.Executor.queryForObject.

Execute a query that is expected to return a scalar (1 row, 1 column).

public <T> T
queryForObject(SqlStatement
The query to execute
sql
,
Class<T> requiredType, List<SqlVisitor> sqlVisitors)

Implements liquibase.executor.Executor.queryForObject.

Applies a number of SqlVisitors to the sql query.

private void
private void
public int
public int
update(final SqlStatement sql, final List<SqlVisitor> sqlVisitors)

Implements liquibase.executor.Executor.update.

public boolean
Inherited from liquibase.executor.AbstractExecutor:
applyVisitorsexecuteexecutemodifyChangeSetsetDatabasesetResourceAccessorvalidate

Constructor Detail

JdbcExecutorback to summary
public JdbcExecutor()

Method Detail

addUpdateCountToScopeback to summary
private void addUpdateCountToScope(int updateCount)
applyVisitorsback to summary
private String applyVisitors(RawParameterizedSqlStatement sql, List<SqlVisitor> sqlVisitors)
checkCallStatusback to summary
private void checkCallStatus(ResultSet resultSet, String status) throws SQLException, DatabaseException
commentback to summary
public void comment(String message) throws DatabaseException

Implements liquibase.executor.Executor.comment.

Doc from liquibase.executor.Executor.comment.

Adds a comment to the database. Currently does nothing but is overridden in the output JDBC template

Annotations
@Override
executeback to summary
public Object execute(StatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException
executeback to summary
public Object execute(CallableStatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException
Annotations
@SuppressWarnings:squid:S2077
executeback to summary
public void execute(final SqlStatement sql) throws DatabaseException

Implements liquibase.executor.Executor.execute.

Annotations
@Override
executeback to summary
public void execute(final SqlStatement sql, final List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.execute.

Annotations
@Override
executeDb2ZosComplexStatementback to summary
private void executeDb2ZosComplexStatement(final SqlStatement sqlStatement, final List<SqlVisitor> sqlVisitors) throws DatabaseException
getColumnMapRowMapperback to summary
protected RowMapper getColumnMapRowMapper()

Create a new RowMapper for reading columns as key-value pairs.

Returns:RowMapper

the RowMapper to use

See Also
ColumnMapRowMapper
getErrorCodeback to summary
pack-priv String getErrorCode(Throwable e)
getNameback to summary
public String getName()

Implements abstract liquibase.executor.AbstractExecutor.getName.

Implements liquibase.executor.Executor.getName.

Return the name of the Executor

Returns:String

String The Executor name

Annotations
@Override
getPriorityback to summary
public int getPriority()

Implements abstract liquibase.executor.AbstractExecutor.getPriority.

Implements liquibase.executor.Executor.getPriority.

Return the Executor priority

Returns:int

int The Executor priority

Annotations
@Override
getSingleColumnRowMapperback to summary
protected RowMapper getSingleColumnRowMapper(Class<T> requiredType)

Create a new RowMapper for reading result objects from a single column.

Parameters
requiredType:Class<T>

the type that each result object is expected to match

Returns:RowMapper

the RowMapper to use

See Also
SingleColumnRowMapper
queryback to summary
public Object query(final SqlStatement sql, final ResultSetExtractor rse) throws DatabaseException
queryback to summary
public Object query(final SqlStatement sql, final ResultSetExtractor rse, final List<SqlVisitor> sqlVisitors) throws DatabaseException
queryback to summary
public List<E> query(SqlStatement sql, RowMapper rowMapper) throws DatabaseException
queryback to summary
public List<E> query(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors) throws DatabaseException
queryForIntback to summary
public int queryForInt(SqlStatement sql) throws DatabaseException

Implements liquibase.executor.Executor.queryForInt.

Doc from liquibase.executor.Executor.queryForInt.

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:SqlStatement

The query to execute

Returns:int

An integer, if successful

Annotations
@Override
Exceptions
DatabaseException:
in case something goes wrong during the query execution
queryForIntback to summary
public int queryForInt(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.queryForInt.

Doc from liquibase.executor.Executor.queryForInt.

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:SqlStatement

The query to execute

Returns:int

An integer, if successful

Annotations
@Override
Exceptions
DatabaseException:
in case something goes wrong during the query execution
queryForListback to summary
public List<E> queryForList(SqlStatement sql, Class<T> elementType) throws DatabaseException

Implements liquibase.executor.Executor.queryForList.

Annotations
@Override
queryForListback to summary
public List<E> queryForList(SqlStatement sql, Class<T> elementType, List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.queryForList.

Annotations
@Override
queryForListback to summary
public List<Map<String, ?>> queryForList(SqlStatement sql) throws DatabaseException

Implements liquibase.executor.Executor.queryForList.

Doc from liquibase.executor.Executor.queryForList.

Executes a given SQL statement and returns a List of rows. Each row is represented a a Map, where the String is the column name and the value if the content of the column in the row (=cell).

Parameters
sql:SqlStatement

the SQL query to execute

Returns:List<Map<String, ?>>

a List of [Column name] -> [column value]-mapped rows.

Annotations
@Override
Exceptions
DatabaseException:
if an error occurs during SQL processing (e.g. the SQL is not valid for the database)
queryForListback to summary
public List<Map<String, ?>> queryForList(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.queryForList.

Doc from liquibase.executor.Executor.queryForList.

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, where the String is the column name and the value if the content of the column in the row (=cell).

Parameters
sql:SqlStatement

the SQL query to execute

Returns:List<Map<String, ?>>

a List of [Column name] -> [column value]-mapped rows.

Annotations
@Override
Exceptions
DatabaseException:
if an error occurs during SQL processing (e.g. the SQL is not valid for the database)
queryForLongback to summary
public long queryForLong(SqlStatement sql) throws DatabaseException

Implements liquibase.executor.Executor.queryForLong.

Doc from liquibase.executor.Executor.queryForLong.

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:SqlStatement

The query to execute

Returns:long

A long value, if successful

Annotations
@Override
Exceptions
DatabaseException:
in case something goes wrong during the query execution
queryForLongback to summary
public long queryForLong(SqlStatement sql, List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.queryForLong.

Doc from liquibase.executor.Executor.queryForLong.

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:SqlStatement

The query to execute

Returns:long

A long value, if successful

Annotations
@Override
Exceptions
DatabaseException:
in case something goes wrong during the query execution
queryForObjectback to summary
public Object queryForObject(SqlStatement sql, RowMapper rowMapper) throws DatabaseException
queryForObjectback to summary
public Object queryForObject(SqlStatement sql, RowMapper rowMapper, List<SqlVisitor> sqlVisitors) throws DatabaseException
queryForObjectback to summary
public <T> T queryForObject(SqlStatement sql, Class<T> requiredType) throws DatabaseException

Implements liquibase.executor.Executor.queryForObject.

Doc from liquibase.executor.Executor.queryForObject.

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:SqlStatement

The query to execute

Returns:T

An object of type T, if successful. May also return null if no object is found.

Annotations
@Override
Exceptions
DatabaseException:
in case something goes wrong during the query execution
queryForObjectback to summary
public <T> T queryForObject(SqlStatement sql, Class<T> requiredType, List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.queryForObject.

Doc from liquibase.executor.Executor.queryForObject.

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:SqlStatement

The query to execute

Returns:T

An object of type T, if successful. May also return null if no object is found.

Annotations
@Override
Exceptions
DatabaseException:
in case something goes wrong during the query execution
setParametersback to summary
private void setParameters(final PreparedStatement pstmt, final RawParameterizedSqlStatement sql) throws SQLException
showSqlWarningsback to summary
private void showSqlWarnings(Statement stmtToUse) throws SQLException
updateback to summary
public int update(final SqlStatement sql) throws DatabaseException

Implements liquibase.executor.Executor.update.

Annotations
@Override
updateback to summary
public int update(final SqlStatement sql, final List<SqlVisitor> sqlVisitors) throws DatabaseException

Implements liquibase.executor.Executor.update.

Annotations
@SuppressWarnings:squid:S2077
@Override
updatesDatabaseback to summary
public boolean updatesDatabase()

Implements liquibase.executor.Executor.updatesDatabase.

Annotations
@Override
liquibase.executor.jvm back to summary

private Class JdbcExecutor.ExecuteStatementCallback

extends Object
implements StatementCallback
Class Inheritance
All Implemented Interfaces
liquibase.executor.jvm.StatementCallback

Field Summary

Modifier and TypeField and Description
private final SqlStatement
private final List<SqlVisitor>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Object
doInStatement(Statement
active JDBC Statement
stmt
)

Implements liquibase.executor.jvm.StatementCallback.doInStatement.

Gets called by JdbcTemplate.execute with an active JDBC Statement.

public SqlStatement
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sqlback to summary
private final SqlStatement sql
sqlVisitorsback to summary
private final List<SqlVisitor> sqlVisitors

Constructor Detail

ExecuteStatementCallbackback to summary
private ExecuteStatementCallback(SqlStatement sql, List<SqlVisitor> sqlVisitors)

Method Detail

doInStatementback to summary
public Object doInStatement(Statement stmt) throws SQLException, DatabaseException

Implements liquibase.executor.jvm.StatementCallback.doInStatement.

Doc from liquibase.executor.jvm.StatementCallback.doInStatement.

Gets called by JdbcTemplate.execute with an active JDBC Statement. Does not need to care about closing the Statement or the Connection, or about handling transactions: this will all be handled by JdbcTemplate.

Parameters
stmt:Statement

active JDBC Statement

Returns:Object

a result object, or null if none

Annotations
@Override
getStatementback to summary
public SqlStatement getStatement()

Implements liquibase.executor.jvm.StatementCallback.getStatement.

Annotations
@Override
liquibase.executor.jvm back to summary

private Class JdbcExecutor.QueryCallableStatementCallback

extends Object
implements CallableStatementCallback
Class Inheritance
  • java.lang.Object
  • liquibase.executor.jvm.JdbcExecutor.QueryCallableStatementCallback
All Implemented Interfaces
liquibase.executor.jvm.CallableStatementCallback

Field Summary

Modifier and TypeField and Description
private final ResultSetExtractor
private final SqlStatement

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Object
doInCallableStatement(CallableStatement
active JDBC CallableStatement
cs
)

Implements liquibase.executor.jvm.CallableStatementCallback.doInCallableStatement.

Gets called by JdbcTemplate.execute with an active JDBC CallableStatement.

public SqlStatement
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rseback to summary
private final ResultSetExtractor rse
sqlback to summary
private final SqlStatement sql

Constructor Detail

QueryCallableStatementCallbackback to summary
private QueryCallableStatementCallback(SqlStatement sql, ResultSetExtractor rse)

Method Detail

doInCallableStatementback to summary
public Object doInCallableStatement(CallableStatement cs) throws SQLException, DatabaseException

Implements liquibase.executor.jvm.CallableStatementCallback.doInCallableStatement.

Doc from liquibase.executor.jvm.CallableStatementCallback.doInCallableStatement.

Gets called by JdbcTemplate.execute with an active JDBC CallableStatement. Does not need to care about closing the Statement or the Connection, or about handling transactions: this will all be handled by Spring's JdbcTemplate.

Parameters
cs:CallableStatement

active JDBC CallableStatement

Returns:Object

a result object, or null if none

Annotations
@Override
Exceptions
SQLException:
if thrown by a JDBC method, to be auto-converted into a DataAccessException by a SQLExceptionTranslator
DatabaseException:
in case of custom exceptions
getStatementback to summary
public SqlStatement getStatement()

Implements liquibase.executor.jvm.CallableStatementCallback.getStatement.

Annotations
@Override
liquibase.executor.jvm back to summary

private Class JdbcExecutor.QueryStatementCallback

extends Object
implements StatementCallback
Class Inheritance
All Implemented Interfaces
liquibase.executor.jvm.StatementCallback

Field Summary

Modifier and TypeField and Description
private final ResultSetExtractor
private final SqlStatement
private final List<SqlVisitor>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

An object representing all data from the result set.
doInStatement
(Statement
A JDBC Statement that is expected to return a ResultSet (e.g. SELECT)
stmt
)

Implements liquibase.executor.jvm.StatementCallback.doInStatement.

1.

public SqlStatement
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rseback to summary
private final ResultSetExtractor rse
sqlback to summary
private final SqlStatement sql
sqlVisitorsback to summary
private final List<SqlVisitor> sqlVisitors

Constructor Detail

QueryStatementCallbackback to summary
private QueryStatementCallback(SqlStatement sql, ResultSetExtractor rse, List<SqlVisitor> sqlVisitors)

Method Detail

doInStatementback to summary
public Object doInStatement(Statement stmt) throws SQLException, DatabaseException

Implements liquibase.executor.jvm.StatementCallback.doInStatement.

1. Applies all SqlVisitor to the stmt 2. Executes the (possibly modified) stmt 3. Reads all data from the java.sql.ResultSet into an Object and returns the Object.

Parameters
stmt:Statement

A JDBC Statement that is expected to return a ResultSet (e.g. SELECT)

Returns:Object

An object representing all data from the result set.

Annotations
@Override
@SuppressWarnings:squid:S2077
Exceptions
SQLException:
If an error occurs during SQL processing
DatabaseException:
If an error occurs in the DBMS-specific program code
getStatementback to summary
public SqlStatement getStatement()

Implements liquibase.executor.jvm.StatementCallback.getStatement.

Annotations
@Override