/**
   * Creates a new portal preferences with the primary key. Does not add the portal preferences to
   * the database.
   *
   * @param portalPreferencesId the primary key for the new portal preferences
   * @return the new portal preferences
   */
  public PortalPreferences create(long portalPreferencesId) {
    PortalPreferences portalPreferences = new PortalPreferencesImpl();

    portalPreferences.setNew(true);
    portalPreferences.setPrimaryKey(portalPreferencesId);

    return portalPreferences;
  }
  @Override
  public PortalPreferences updateImpl(com.liferay.portal.model.PortalPreferences portalPreferences)
      throws SystemException {
    portalPreferences = toUnwrappedModel(portalPreferences);

    boolean isNew = portalPreferences.isNew();

    PortalPreferencesModelImpl portalPreferencesModelImpl =
        (PortalPreferencesModelImpl) portalPreferences;

    Session session = null;

    try {
      session = openSession();

      if (portalPreferences.isNew()) {
        session.save(portalPreferences);

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    EntityCacheUtil.putResult(
        PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
        PortalPreferencesImpl.class,
        portalPreferences.getPrimaryKey(),
        portalPreferences);

    if (isNew) {
      FinderCacheUtil.putResult(
          FINDER_PATH_FETCH_BY_O_O,
          new Object[] {
            Long.valueOf(portalPreferences.getOwnerId()),
            Integer.valueOf(portalPreferences.getOwnerType())
          },
          portalPreferences);
    } else {
      if ((portalPreferencesModelImpl.getColumnBitmask()
              & FINDER_PATH_FETCH_BY_O_O.getColumnBitmask())
          != 0) {
        Object[] args =
            new Object[] {
              Long.valueOf(portalPreferencesModelImpl.getOriginalOwnerId()),
              Integer.valueOf(portalPreferencesModelImpl.getOriginalOwnerType())
            };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);

        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);

        FinderCacheUtil.putResult(
            FINDER_PATH_FETCH_BY_O_O,
            new Object[] {
              Long.valueOf(portalPreferences.getOwnerId()),
              Integer.valueOf(portalPreferences.getOwnerType())
            },
            portalPreferences);
      }
    }

    return portalPreferences;
  }