protected AnnouncementsFlag toUnwrappedModel(AnnouncementsFlag announcementsFlag) {
    if (announcementsFlag instanceof AnnouncementsFlagImpl) {
      return announcementsFlag;
    }

    AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();

    announcementsFlagImpl.setNew(announcementsFlag.isNew());
    announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());

    announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
    announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
    announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
    announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
    announcementsFlagImpl.setValue(announcementsFlag.getValue());

    return announcementsFlagImpl;
  }
  @Override
  public AnnouncementsFlag updateImpl(
      com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag, boolean merge)
      throws SystemException {
    announcementsFlag = toUnwrappedModel(announcementsFlag);

    boolean isNew = announcementsFlag.isNew();

    AnnouncementsFlagModelImpl announcementsFlagModelImpl =
        (AnnouncementsFlagModelImpl) announcementsFlag;

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.update(session, announcementsFlag, merge);

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew || !AnnouncementsFlagModelImpl.COLUMN_BITMASK_ENABLED) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else {
      if ((announcementsFlagModelImpl.getColumnBitmask()
              & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask())
          != 0) {
        Object[] args =
            new Object[] {Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId())};

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
        FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID, args);

        args = new Object[] {Long.valueOf(announcementsFlagModelImpl.getEntryId())};

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
        FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID, args);
      }
    }

    EntityCacheUtil.putResult(
        AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
        AnnouncementsFlagImpl.class,
        announcementsFlag.getPrimaryKey(),
        announcementsFlag);

    if (isNew) {
      FinderCacheUtil.putResult(
          FINDER_PATH_FETCH_BY_U_E_V,
          new Object[] {
            Long.valueOf(announcementsFlag.getUserId()),
            Long.valueOf(announcementsFlag.getEntryId()),
            Integer.valueOf(announcementsFlag.getValue())
          },
          announcementsFlag);
    } else {
      if ((announcementsFlagModelImpl.getColumnBitmask()
              & FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask())
          != 0) {
        Object[] args =
            new Object[] {
              Long.valueOf(announcementsFlagModelImpl.getOriginalUserId()),
              Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId()),
              Integer.valueOf(announcementsFlagModelImpl.getOriginalValue())
            };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);

        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);

        FinderCacheUtil.putResult(
            FINDER_PATH_FETCH_BY_U_E_V,
            new Object[] {
              Long.valueOf(announcementsFlag.getUserId()),
              Long.valueOf(announcementsFlag.getEntryId()),
              Integer.valueOf(announcementsFlag.getValue())
            },
            announcementsFlag);
      }
    }

    return announcementsFlag;
  }