Search in sources :

Example 1 with TableRowCountStatement

use of liquibase.statement.core.TableRowCountStatement in project liquibase by liquibase.

the class RowCountPrecondition method check.

@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
    try {
        TableRowCountStatement statement = new TableRowCountStatement(catalogName, schemaName, tableName);
        int result = ExecutorService.getInstance().getExecutor(database).queryForInt(statement);
        if (result != expectedRows) {
            throw new PreconditionFailedException(getFailureMessage(result), changeLog, this);
        }
    } catch (PreconditionFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new PreconditionErrorException(e, changeLog, this);
    }
}
Also used : PreconditionFailedException(liquibase.exception.PreconditionFailedException) TableRowCountStatement(liquibase.statement.core.TableRowCountStatement) PreconditionFailedException(liquibase.exception.PreconditionFailedException) PreconditionErrorException(liquibase.exception.PreconditionErrorException) PreconditionErrorException(liquibase.exception.PreconditionErrorException)

Example 2 with TableRowCountStatement

use of liquibase.statement.core.TableRowCountStatement in project liquibase by liquibase.

the class RowCountPrecondition method check.

@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet, ChangeExecListener changeExecListener) throws PreconditionFailedException, PreconditionErrorException {
    try {
        TableRowCountStatement statement = new TableRowCountStatement(catalogName, schemaName, tableName);
        int result = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database).queryForInt(statement);
        if (result != expectedRows) {
            throw new PreconditionFailedException(getFailureMessage(result), changeLog, this);
        }
    } catch (PreconditionFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new PreconditionErrorException(e, changeLog, this);
    }
}
Also used : PreconditionFailedException(liquibase.exception.PreconditionFailedException) TableRowCountStatement(liquibase.statement.core.TableRowCountStatement) PreconditionFailedException(liquibase.exception.PreconditionFailedException) PreconditionErrorException(liquibase.exception.PreconditionErrorException) PreconditionErrorException(liquibase.exception.PreconditionErrorException)

Aggregations

PreconditionErrorException (liquibase.exception.PreconditionErrorException)2 PreconditionFailedException (liquibase.exception.PreconditionFailedException)2 TableRowCountStatement (liquibase.statement.core.TableRowCountStatement)2