@Override
  public Asset updateImpl(com.liferay.ams.model.Asset asset, boolean merge) throws SystemException {
    asset = toUnwrappedModel(asset);

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.update(session, asset, merge);

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

    EntityCacheUtil.putResult(
        AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey(), asset);

    return asset;
  }
  /**
   * Creates a new asset with the primary key. Does not add the asset to the database.
   *
   * @param assetId the primary key for the new asset
   * @return the new asset
   */
  public Asset create(long assetId) {
    Asset asset = new AssetImpl();

    asset.setNew(true);
    asset.setPrimaryKey(assetId);

    return asset;
  }
  @Override
  public Asset updateImpl(com.liferay.ams.model.Asset asset) throws SystemException {
    asset = toUnwrappedModel(asset);

    boolean isNew = asset.isNew();

    Session session = null;

    try {
      session = openSession();

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

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    EntityCacheUtil.putResult(
        AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey(), asset);

    asset.resetOriginalValues();

    return asset;
  }
  /**
   * Adds the asset to the database. Also notifies the appropriate model listeners.
   *
   * @param asset the asset
   * @return the asset that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  public Asset addAsset(Asset asset) throws SystemException {
    asset.setNew(true);

    return assetPersistence.update(asset, false);
  }
  /**
   * Updates the asset in the database or adds it if it does not yet exist. Also notifies the
   * appropriate model listeners.
   *
   * @param asset the asset
   * @param merge whether to merge the asset with the current session. See {@link
   *     com.liferay.portal.service.persistence.BatchSession#update(com.liferay.portal.kernel.dao.orm.Session,
   *     com.liferay.portal.model.BaseModel, boolean)} for an explanation.
   * @return the asset that was updated
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  public Asset updateAsset(Asset asset, boolean merge) throws SystemException {
    asset.setNew(false);

    return assetPersistence.update(asset, merge);
  }