In both, CustomSqlChange is passed a Database object. Were you creating a snapshot from that before and are wondering how to create a snapshot now in 3.0?
Actually I want to get the name of a unique constraint by specifying the table and the column name.
With table and column information my CustomSqlChange was able to drop an unique constraint without specifying its name. Useful when you have generated names that are diffrernt from an instance to another.
public class DropUnknownUniqueConstraint implements CustomSqlChange { private final DropUniqueConstraintChange change = new DropUniqueConstraintChange();
private Set columnNames;
public void setTableName(String tableName) { change.setTableName(tableName); }
public void setUniqueColumns(String uniqueColumns) { this.change.setUniqueColumns(uniqueColumns); columnNames = new HashSet<>(Arrays.asList(uniqueColumns.split(","))); }
@Override public String getConfirmationMessage() { return change.getConfirmationMessage(); }
@Override public void setUp() throws SetupException { }
@Override public void setFileOpener(ResourceAccessor resourceAccessor) { }
@Override public ValidationErrors validate(Database database) { return new ValidationErrors(); }
@Override public SqlStatement[] generateStatements(Database database) throws CustomChangeException { Set constraints; try { constraints = DatabaseSnapshotGeneratorFactory.getInstance() .createSnapshot(database, null, null).getUniqueConstraints(); } catch (DatabaseException e) { throw new CustomChangeException(e.getMessage(), e); } UniqueConstraint constraintToRemove = null; for (UniqueConstraint constraint : constraints) { if (constraint.getTable().getName().equals(change.getTableName())) { Set columns = new HashSet<>(constraint.getColumns()); if (columns.equals(columnNames)) { constraintToRemove = constraint; break; } } } if (constraintToRemove == null) { throw new CustomChangeException(“Constraint not found for table '” + change.getTableName() + “’ and columns '” + change.getUniqueColumns() + “’.”); }
With 3.0, DatabaseSnapshotGeneratorFactory changed to SnapshotGeneratorFactory. The larger change is that the createSnapshot() method now take different parameters. The one you probably want is Nathan