protected LayoutSet toUnwrappedModel(LayoutSet layoutSet) {
    if (layoutSet instanceof LayoutSetImpl) {
      return layoutSet;
    }

    LayoutSetImpl layoutSetImpl = new LayoutSetImpl();

    layoutSetImpl.setNew(layoutSet.isNew());
    layoutSetImpl.setPrimaryKey(layoutSet.getPrimaryKey());

    layoutSetImpl.setLayoutSetId(layoutSet.getLayoutSetId());
    layoutSetImpl.setGroupId(layoutSet.getGroupId());
    layoutSetImpl.setCompanyId(layoutSet.getCompanyId());
    layoutSetImpl.setPrivateLayout(layoutSet.isPrivateLayout());
    layoutSetImpl.setLogo(layoutSet.isLogo());
    layoutSetImpl.setLogoId(layoutSet.getLogoId());
    layoutSetImpl.setThemeId(layoutSet.getThemeId());
    layoutSetImpl.setColorSchemeId(layoutSet.getColorSchemeId());
    layoutSetImpl.setWapThemeId(layoutSet.getWapThemeId());
    layoutSetImpl.setWapColorSchemeId(layoutSet.getWapColorSchemeId());
    layoutSetImpl.setCss(layoutSet.getCss());
    layoutSetImpl.setPageCount(layoutSet.getPageCount());
    layoutSetImpl.setSettings(layoutSet.getSettings());
    layoutSetImpl.setLayoutSetPrototypeId(layoutSet.getLayoutSetPrototypeId());

    return layoutSetImpl;
  }
  @Override
  public LayoutSet updateImpl(com.liferay.portal.model.LayoutSet layoutSet, boolean merge)
      throws SystemException {
    layoutSet = toUnwrappedModel(layoutSet);

    boolean isNew = layoutSet.isNew();

    LayoutSetModelImpl layoutSetModelImpl = (LayoutSetModelImpl) layoutSet;

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.update(session, layoutSet, merge);

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

    EntityCacheUtil.putResult(
        LayoutSetModelImpl.ENTITY_CACHE_ENABLED,
        LayoutSetImpl.class,
        layoutSet.getPrimaryKey(),
        layoutSet);

    if (!isNew
        && ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId())
            || (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
      FinderCacheUtil.removeResult(
          FINDER_PATH_FETCH_BY_G_P,
          new Object[] {
            Long.valueOf(layoutSetModelImpl.getOriginalGroupId()),
            Boolean.valueOf(layoutSetModelImpl.getOriginalPrivateLayout())
          });
    }

    if (isNew
        || ((layoutSet.getGroupId() != layoutSetModelImpl.getOriginalGroupId())
            || (layoutSet.getPrivateLayout() != layoutSetModelImpl.getOriginalPrivateLayout()))) {
      FinderCacheUtil.putResult(
          FINDER_PATH_FETCH_BY_G_P,
          new Object[] {
            Long.valueOf(layoutSet.getGroupId()), Boolean.valueOf(layoutSet.getPrivateLayout())
          },
          layoutSet);
    }

    return layoutSet;
  }