@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;
  }
  /**
   * Caches the asset in the entity cache if it is enabled.
   *
   * @param asset the asset
   */
  @Override
  public void cacheResult(Asset asset) {
    EntityCacheUtil.putResult(
        AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey(), asset);

    asset.resetOriginalValues();
  }
  /**
   * 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;
  }
 /**
  * Caches the assets in the entity cache if it is enabled.
  *
  * @param assets the assets
  */
 public void cacheResult(List<Asset> assets) {
   for (Asset asset : assets) {
     if (EntityCacheUtil.getResult(
             AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey())
         == null) {
       cacheResult(asset);
     }
   }
 }
  @Override
  public void clearCache(List<Asset> assets) {
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

    for (Asset asset : assets) {
      EntityCacheUtil.removeResult(
          AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey());
    }
  }
 /**
  * Caches the assets in the entity cache if it is enabled.
  *
  * @param assets the assets
  */
 @Override
 public void cacheResult(List<Asset> assets) {
   for (Asset asset : assets) {
     if (EntityCacheUtil.getResult(
             AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey())
         == null) {
       cacheResult(asset);
     } else {
       asset.resetOriginalValues();
     }
   }
 }
  @Override
  protected Asset removeImpl(Asset asset) throws SystemException {
    asset = toUnwrappedModel(asset);

    Session session = null;

    try {
      session = openSession();

      if (!session.contains(asset)) {
        asset = (Asset) session.get(AssetImpl.class, asset.getPrimaryKeyObj());
      }

      if (asset != null) {
        session.delete(asset);
      }
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    if (asset != null) {
      clearCache(asset);
    }

    return asset;
  }
  @Override
  protected Asset removeImpl(Asset asset) throws SystemException {
    asset = toUnwrappedModel(asset);

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.delete(session, asset);
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

    FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL, FINDER_ARGS_EMPTY);

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

    return asset;
  }
  /**
   * Clears the cache for the asset.
   *
   * <p>The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link
   * com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
   */
  @Override
  public void clearCache(Asset asset) {
    EntityCacheUtil.removeResult(
        AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, asset.getPrimaryKey());

    FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL, FINDER_ARGS_EMPTY);
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof Asset)) {
      return false;
    }

    Asset asset = (Asset) obj;

    long primaryKey = asset.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  public int compareTo(Asset asset) {
    long primaryKey = asset.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    Asset asset = null;

    try {
      asset = (Asset) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = asset.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @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;
  }
  protected Asset toUnwrappedModel(Asset asset) {
    if (asset instanceof AssetImpl) {
      return asset;
    }

    AssetImpl assetImpl = new AssetImpl();

    assetImpl.setNew(asset.isNew());
    assetImpl.setPrimaryKey(asset.getPrimaryKey());

    assetImpl.setAssetId(asset.getAssetId());
    assetImpl.setCompanyId(asset.getCompanyId());
    assetImpl.setUserId(asset.getUserId());
    assetImpl.setUserName(asset.getUserName());
    assetImpl.setCreateDate(asset.getCreateDate());
    assetImpl.setModifiedDate(asset.getModifiedDate());
    assetImpl.setDefinitionId(asset.getDefinitionId());
    assetImpl.setSerialNumber(asset.getSerialNumber());
    assetImpl.setInactiveDate(asset.getInactiveDate());
    assetImpl.setActive(asset.isActive());

    return assetImpl;
  }
  /**
   * 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);
  }