/**
   * Creates a new panic button with the primary key. Does not add the panic button to the database.
   *
   * @param panicButtonId the primary key for the new panic button
   * @return the new panic button
   */
  public PanicButton create(long panicButtonId) {
    PanicButton panicButton = new PanicButtonImpl();

    panicButton.setNew(true);
    panicButton.setPrimaryKey(panicButtonId);

    return panicButton;
  }
  /**
   * Caches the panic button in the entity cache if it is enabled.
   *
   * @param panicButton the panic button
   */
  public void cacheResult(PanicButton panicButton) {
    EntityCacheUtil.putResult(
        PanicButtonModelImpl.ENTITY_CACHE_ENABLED,
        PanicButtonImpl.class,
        panicButton.getPrimaryKey(),
        panicButton);

    panicButton.resetOriginalValues();
  }
  @Override
  public void clearCache(List<PanicButton> panicButtons) {
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

    for (PanicButton panicButton : panicButtons) {
      EntityCacheUtil.removeResult(
          PanicButtonModelImpl.ENTITY_CACHE_ENABLED,
          PanicButtonImpl.class,
          panicButton.getPrimaryKey());
    }
  }
 /**
  * Caches the panic buttons in the entity cache if it is enabled.
  *
  * @param panicButtons the panic buttons
  */
 public void cacheResult(List<PanicButton> panicButtons) {
   for (PanicButton panicButton : panicButtons) {
     if (EntityCacheUtil.getResult(
             PanicButtonModelImpl.ENTITY_CACHE_ENABLED,
             PanicButtonImpl.class,
             panicButton.getPrimaryKey())
         == null) {
       cacheResult(panicButton);
     } else {
       panicButton.resetOriginalValues();
     }
   }
 }
  @Override
  public PanicButton updateImpl(com.ese.ils.beta.model.PanicButton panicButton, boolean merge)
      throws SystemException {
    panicButton = toUnwrappedModel(panicButton);

    boolean isNew = panicButton.isNew();

    PanicButtonModelImpl panicButtonModelImpl = (PanicButtonModelImpl) panicButton;

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.update(session, panicButton, merge);

      panicButton.setNew(false);
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew || !PanicButtonModelImpl.COLUMN_BITMASK_ENABLED) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else {
      if ((panicButtonModelImpl.getColumnBitmask()
              & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYMODULE.getColumnBitmask())
          != 0) {
        Object[] args = new Object[] {Long.valueOf(panicButtonModelImpl.getOriginalModuleId())};

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BYMODULE, args);
        FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYMODULE, args);

        args = new Object[] {Long.valueOf(panicButtonModelImpl.getModuleId())};

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BYMODULE, args);
        FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BYMODULE, args);
      }
    }

    EntityCacheUtil.putResult(
        PanicButtonModelImpl.ENTITY_CACHE_ENABLED,
        PanicButtonImpl.class,
        panicButton.getPrimaryKey(),
        panicButton);

    return panicButton;
  }
  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 = &#63;.
   *
   * <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;
  }