/**
   * 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();
  }
  @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;
  }
  @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);
  }
  /**
   * 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.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
  }
 /**
  * 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);
     }
   }
 }
  public int compareTo(Asset asset) {
    long primaryKey = asset.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
 /**
  * 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
  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;
    }
  }
  @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;
    }
  }
  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;
  }
  @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;
  }