public Change[] fixMissing( DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) { UniqueConstraint uc = (UniqueConstraint) missingObject; if (uc.getTable() == null) { return null; } AddUniqueConstraintChange change = new AddUniqueConstraintChange(); change.setTableName(uc.getTable().getName()); if (uc.getBackingIndex() != null && control.isIncludeTablespace()) { change.setTablespace(uc.getBackingIndex().getTablespace()); } if (control.isIncludeCatalog()) { change.setCatalogName(uc.getTable().getSchema().getCatalogName()); } if (control.isIncludeSchema()) { change.setSchemaName(uc.getTable().getSchema().getName()); } change.setConstraintName(uc.getName()); change.setColumnNames(uc.getColumnNames()); change.setDeferrable(uc.isDeferrable()); change.setInitiallyDeferred(uc.isInitiallyDeferred()); change.setDisabled(uc.isDisabled()); Index backingIndex = uc.getBackingIndex(); // if (backingIndex == null) { // Index exampleIndex = new Index().setTable(uc.getTable()); // for (String col : uc.getColumns()) { // exampleIndex.getColumns().add(col); // } // control.setAlreadyHandledMissing(exampleIndex); // } else { control.setAlreadyHandledMissing(backingIndex); // } return new Change[] {change}; }
@Override public Change[] fixMissing( DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) { List<Change> returnList = new ArrayList<Change>(); UniqueConstraint uc = (UniqueConstraint) missingObject; if (uc.getTable() == null) { return null; } AddUniqueConstraintChange change = new AddUniqueConstraintChange(); change.setTableName(uc.getTable().getName()); if (uc.getBackingIndex() != null && control.getIncludeTablespace()) { change.setTablespace(uc.getBackingIndex().getTablespace()); } if (control.getIncludeCatalog()) { change.setCatalogName(uc.getTable().getSchema().getCatalogName()); } if (control.getIncludeSchema()) { change.setSchemaName(uc.getTable().getSchema().getName()); } change.setConstraintName(uc.getName()); change.setColumnNames(uc.getColumnNames()); change.setDeferrable(uc.isDeferrable() ? Boolean.TRUE : null); change.setInitiallyDeferred(uc.isInitiallyDeferred() ? Boolean.TRUE : null); change.setDisabled(uc.isDisabled() ? Boolean.TRUE : null); if (comparisonDatabase instanceof OracleDatabase) { Index backingIndex = uc.getBackingIndex(); if (backingIndex != null && backingIndex.getName() != null) { Change[] changes = ChangeGeneratorFactory.getInstance() .fixMissing(backingIndex, control, referenceDatabase, comparisonDatabase); if (changes != null) { returnList.addAll(Arrays.asList(changes)); change.setForIndexName(backingIndex.getName()); Schema schema = backingIndex.getSchema(); if (schema != null) { if (control.getIncludeCatalog()) { change.setForIndexCatalogName(schema.getCatalogName()); } if (control.getIncludeSchema()) { change.setForIndexSchemaName(schema.getName()); } } } } } Index backingIndex = uc.getBackingIndex(); // if (backingIndex == null) { // Index exampleIndex = new Index().setTable(uc.getTable()); // for (String col : uc.getColumns()) { // exampleIndex.getColumns().add(col); // } // control.setAlreadyHandledMissing(exampleIndex); // } else { control.setAlreadyHandledMissing(backingIndex); // } returnList.add(change); return returnList.toArray(new Change[returnList.size()]); }