Class Deduper

  • public class Deduper
    extends Object
    Remove duplicated rows from a table before a unique constraint can be added. This is a 2-step process: 1. Query all duplicate rows 2. Use a suitable DedupeStrategy to delete those duplicates Note: 1. Tables with composite keys are not supported. 2. This implementation doesn't scale well because it puts everything in memory and process DMLs one at a time
    • Constructor Detail

      • Deduper

        public Deduper​(org.hibernate.SessionFactory sessionFactory,
                       com.atlassian.config.db.HibernateConfig hibernateConfig)
    • Method Detail

      • removeDuplicates

        public long removeDuplicates​(String table,
                                     String idColumn,
                                     List<String> uniqueColumns,
                                     DedupeStrategy dedupeStrategy)
                              throws UpgradeException
        Remove all duplicates of combination of uniqueColumns from table. Note: names of tables and columns are not to be quoted.
        number of duplicate rows removed
      • multipleNullsNotAllowed

        public boolean multipleNullsNotAllowed()
        Oracle and SQL Server behave differently from the rest: two rows that contain nulls for one or more key columns and the same combination of values for the other key columns violate a unique constraint.
        true if current SQL vendor doesn't accepts multiple null values in multi-column unique constraints