protected PanicButton toUnwrappedModel(PanicButton panicButton) {
    if (panicButton instanceof PanicButtonImpl) {
      return panicButton;
    }

    PanicButtonImpl panicButtonImpl = new PanicButtonImpl();

    panicButtonImpl.setNew(panicButton.isNew());
    panicButtonImpl.setPrimaryKey(panicButton.getPrimaryKey());

    panicButtonImpl.setPanicButtonId(panicButton.getPanicButtonId());
    panicButtonImpl.setUserId(panicButton.getUserId());
    panicButtonImpl.setCreateDate(panicButton.getCreateDate());
    panicButtonImpl.setModuleId(panicButton.getModuleId());
    panicButtonImpl.setSlideId(panicButton.getSlideId());
    panicButtonImpl.setReason(panicButton.getReason());

    return panicButtonImpl;
  }
  /**
   * Returns an ordered range of all the panic buttons where moduleId = ?.
   *
   * <p>Useful when paginating results. Returns a maximum of <code>end - start</code> instances.
   * <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result
   * set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start
   * </code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}
   * will return the full result set.
   *
   * @param moduleId the module ID
   * @param start the lower bound of the range of panic buttons
   * @param end the upper bound of the range of panic buttons (not inclusive)
   * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
   * @return the ordered range of matching panic buttons
   * @throws SystemException if a system exception occurred
   */
  public List<PanicButton> findByByModule(
      long moduleId, int start, int end, OrderByComparator orderByComparator)
      throws SystemException {
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
      finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYMODULE;
      finderArgs = new Object[] {moduleId};
    } else {
      finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BYMODULE;
      finderArgs = new Object[] {moduleId, start, end, orderByComparator};
    }

    List<PanicButton> list =
        (List<PanicButton>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
      for (PanicButton panicButton : list) {
        if ((moduleId != panicButton.getModuleId())) {
          list = null;

          break;
        }
      }
    }

    if (list == null) {
      StringBundler query = null;

      if (orderByComparator != null) {
        query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
      } else {
        query = new StringBundler(3);
      }

      query.append(_SQL_SELECT_PANICBUTTON_WHERE);

      query.append(_FINDER_COLUMN_BYMODULE_MODULEID_2);

      if (orderByComparator != null) {
        appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
      } else {
        query.append(PanicButtonModelImpl.ORDER_BY_JPQL);
      }

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(moduleId);

        list = (List<PanicButton>) QueryUtil.list(q, getDialect(), start, end);
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (list == null) {
          FinderCacheUtil.removeResult(finderPath, finderArgs);
        } else {
          cacheResult(list);

          FinderCacheUtil.putResult(finderPath, finderArgs, list);
        }

        closeSession(session);
      }
    }

    return list;
  }