// We need to iterate again - can be avoided with a query.
  // delete will fail if the pm is different than the one used to
  // load the object - we must close the object when we're done
  public void deleteRegistration(String regId) {
    if (ctx == null) {
      return;
    }
    PersistenceManager pm = DBHelper.getPMF(ctx).getPersistenceManager();
    try {
      List<DeviceInfo> registrations = DeviceInfo.getDeviceInfoForUserEmail(pm, userEmail);
      for (int i = 0; i < registrations.size(); i++) {
        DeviceInfo deviceInfo = registrations.get(i);
        if (deviceInfo.getDeviceRegistrationID().equals(regId)) {
          pm.deletePersistent(deviceInfo);
          // Keep looping in case of duplicates

          log.log(
              Level.INFO,
              "RequestInfo:deleteRegistration() : deleted deviceInfo for "
                  + deviceInfo.getDeviceRegistrationID());
        }
      }
    } catch (JDOObjectNotFoundException e) {
      log.warning("RequestInfo:deleteRegistration() : User unknown");
    } catch (Exception e) {
      log.warning(
          "RequestInfo:deleteRegistration() : Error unregistering device: " + e.getMessage());
    } finally {
      pm.close();
    }
  }
  private void initDevices(ServletContext ctx) {
    // Context-shared PMF.
    PersistenceManager pm = DBHelper.getPMF(ctx).getPersistenceManager();

    try {
      devices = DeviceInfo.getDeviceInfoForUserEmail(pm, userEmail);
      // cleanup for multi-device
      /*if (devices.size() > 1) {
      // Make sure there is no 'bare' registration
      // Keys are sorted - check the first
      DeviceInfo first = devices.get(0);
      Key oldKey = first.getKey();
      if (oldKey.toString().indexOf("#") < 0) {
          log.warning("Removing old-style key " + oldKey.toString());
          // multiple devices, first is old-style.
          devices.remove(0);
          pm.deletePersistent(first);
      }
         }*/
      log.log(
          Level.INFO,
          "RequestInfo:initDevices() : loading devices "
              + devices.size()
              + " for user = "******"RequestInfo:initDevices() : Error loading registrations ", e);
    } finally {
      pm.close();
    }
  }