/**
   * Checks for duplicate identity objects and deletes duplicates if they exist. I have absolutely
   * NO idea why Bombe does happen to have a duplicate identity, I see no code path which could
   * cause this. TODO: Get rid of this function if nobody reports a duplicate for some time - the
   * function was added at 2011-01-10
   */
  private synchronized void deleteDuplicateIdentities() {
    WoTMessageManager messageManager = mFreetalk.getMessageManager();
    PersistentTaskManager taskManager = mFreetalk.getTaskManager();

    synchronized (messageManager) {
      synchronized (taskManager) {
        synchronized (db.lock()) {
          try {
            HashSet<String> deleted = new HashSet<String>();

            Logger.normal(this, "Searching for duplicate identities ...");

            for (WoTIdentity identity : getAllIdentities()) {
              Query q = db.query();
              q.constrain(WoTIdentity.class);
              q.descend("mID").constrain(identity.getID());
              q.constrain(identity).identity().not();
              ObjectSet<WoTIdentity> duplicates =
                  new Persistent.InitializingObjectSet<WoTIdentity>(mFreetalk, q);

              for (WoTIdentity duplicate : duplicates) {
                if (deleted.contains(duplicate.getID()) == false) {
                  Logger.error(
                      duplicate, "Deleting duplicate identity " + duplicate.getRequestURI());
                  deleteIdentity(duplicate, messageManager, taskManager);
                }
              }
              deleted.add(identity.getID());
            }
            Persistent.checkedCommit(db, this);

            Logger.normal(this, "Finished searching for duplicate identities.");
          } catch (RuntimeException e) {
            Persistent.checkedRollback(db, this, e);
          }
        }
      }
    }
  }
 protected void checkedCommit(Object loggingObject) {
   super.checkedCommit(loggingObject);
 }