use of liquibase.exception.PreconditionErrorException 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);
}
}
use of liquibase.exception.PreconditionErrorException in project liquibase by liquibase.
the class IndexExistsPrecondition method check.
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet, ChangeExecListener changeExecListener) throws PreconditionFailedException, PreconditionErrorException {
try {
Schema schema = new Schema(getCatalogName(), getSchemaName());
Index example = new Index();
String tableName = StringUtil.trimToNull(getTableName());
if (tableName != null) {
example.setRelation((Table) new Table().setName(database.correctObjectName(getTableName(), Table.class)).setSchema(schema));
}
example.setName(database.correctObjectName(getIndexName(), Index.class));
if (StringUtil.trimToNull(getColumnNames()) != null) {
for (String column : getColumnNames().split("\\s*,\\s*")) {
example.addColumn(new Column(database.correctObjectName(column, Column.class)));
}
}
if (!SnapshotGeneratorFactory.getInstance().has(example, database)) {
String name = "";
if (getIndexName() != null) {
name += database.escapeObjectName(getIndexName(), Index.class);
}
if (tableName != null) {
name += " on " + database.escapeObjectName(getTableName(), Table.class);
if (StringUtil.trimToNull(getColumnNames()) != null) {
name += " columns " + getColumnNames();
}
}
throw new PreconditionFailedException("Index " + name + " does not exist", changeLog, this);
}
} catch (Exception e) {
if (e instanceof PreconditionFailedException) {
throw (((PreconditionFailedException) e));
}
throw new PreconditionErrorException(e, changeLog, this);
}
}
use of liquibase.exception.PreconditionErrorException 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);
}
}
use of liquibase.exception.PreconditionErrorException in project liquibase by liquibase.
the class ForeignKeyExistsPrecondition method check.
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet, ChangeExecListener changeExecListener) throws PreconditionFailedException, PreconditionErrorException {
try {
ForeignKey example = new ForeignKey();
example.setName(getForeignKeyName());
example.setForeignKeyTable(new Table());
if (StringUtil.trimToNull(getForeignKeyTableName()) != null) {
example.getForeignKeyTable().setName(getForeignKeyTableName());
}
example.getForeignKeyTable().setSchema(new Schema(getCatalogName(), getSchemaName()));
if (!SnapshotGeneratorFactory.getInstance().has(example, database)) {
throw new PreconditionFailedException("Foreign Key " + database.escapeIndexName(catalogName, schemaName, foreignKeyName) + " does not exist", changeLog, this);
}
} catch (PreconditionFailedException e) {
throw e;
} catch (Exception e) {
throw new PreconditionErrorException(e, changeLog, this);
}
}
use of liquibase.exception.PreconditionErrorException in project liquibase by liquibase.
the class ValidatingVisitorPreConditionsTest method testPreConditionsForOracleOnMSSQLWithPreconditionTag.
/**
* Test only the precondition tag with a precondition requiring oracle but
* giving a MSSQL database.
*/
@Test
public void testPreConditionsForOracleOnMSSQLWithPreconditionTag() {
// create the pre condition
PreconditionContainer preCondition = new PreconditionContainer();
preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
dbmsPrecondition.setType("oracle");
preCondition.addNestedPrecondition(dbmsPrecondition);
changeSet1.setPreconditions(preCondition);
MSSQLDatabase mssqlDb = new MSSQLDatabase() {
@Override
public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
return new ArrayList<RanChangeSet>();
}
@Override
public void rollback() throws DatabaseException {
// super.rollback();
}
};
boolean failedExceptionThrown = false;
boolean errorExceptionThrown = false;
try {
preCondition.check(mssqlDb, changeLog, changeSet1, null);
} catch (PreconditionFailedException ex) {
failedExceptionThrown = true;
} catch (PreconditionErrorException ex) {
errorExceptionThrown = true;
}
assertTrue(failedExceptionThrown);
assertFalse(errorExceptionThrown);
}
Aggregations