@Override
  public Quota updateImpl(org.lsug.quota.model.Quota quota, boolean merge) throws SystemException {
    quota = toUnwrappedModel(quota);

    boolean isNew = quota.isNew();

    QuotaModelImpl quotaModelImpl = (QuotaModelImpl) quota;

    Session session = null;

    try {
      session = openSession();

      BatchSessionUtil.update(session, quota, merge);

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

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

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

    EntityCacheUtil.putResult(
        QuotaModelImpl.ENTITY_CACHE_ENABLED, QuotaImpl.class, quota.getPrimaryKey(), quota);

    if (isNew) {
      FinderCacheUtil.putResult(
          FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK,
          new Object[] {Long.valueOf(quota.getClassNameId()), Long.valueOf(quota.getClassPK())},
          quota);
    } else {
      if ((quotaModelImpl.getColumnBitmask()
              & FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK.getColumnBitmask())
          != 0) {
        Object[] args =
            new Object[] {
              Long.valueOf(quotaModelImpl.getOriginalClassNameId()),
              Long.valueOf(quotaModelImpl.getOriginalClassPK())
            };

        FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEIDCLASSPK, args);

        FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK, args);

        FinderCacheUtil.putResult(
            FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK,
            new Object[] {Long.valueOf(quota.getClassNameId()), Long.valueOf(quota.getClassPK())},
            quota);
      }
    }

    return quota;
  }
  /**
   * Clears the cache for the quota.
   *
   * <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(Quota quota) {
    EntityCacheUtil.removeResult(
        QuotaModelImpl.ENTITY_CACHE_ENABLED, QuotaImpl.class, quota.getPrimaryKey());

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

    clearUniqueFindersCache(quota);
  }
 /**
  * Caches the quotas in the entity cache if it is enabled.
  *
  * @param quotas the quotas
  */
 public void cacheResult(List<Quota> quotas) {
   for (Quota quota : quotas) {
     if (EntityCacheUtil.getResult(
             QuotaModelImpl.ENTITY_CACHE_ENABLED, QuotaImpl.class, quota.getPrimaryKey())
         == null) {
       cacheResult(quota);
     } else {
       quota.resetOriginalValues();
     }
   }
 }
  /**
   * Caches the quota in the entity cache if it is enabled.
   *
   * @param quota the quota
   */
  public void cacheResult(Quota quota) {
    EntityCacheUtil.putResult(
        QuotaModelImpl.ENTITY_CACHE_ENABLED, QuotaImpl.class, quota.getPrimaryKey(), quota);

    FinderCacheUtil.putResult(
        FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK,
        new Object[] {Long.valueOf(quota.getClassNameId()), Long.valueOf(quota.getClassPK())},
        quota);

    quota.resetOriginalValues();
  }
  protected Quota toUnwrappedModel(Quota quota) {
    if (quota instanceof QuotaImpl) {
      return quota;
    }

    QuotaImpl quotaImpl = new QuotaImpl();

    quotaImpl.setNew(quota.isNew());
    quotaImpl.setPrimaryKey(quota.getPrimaryKey());

    quotaImpl.setQuotaId(quota.getQuotaId());
    quotaImpl.setClassNameId(quota.getClassNameId());
    quotaImpl.setClassPK(quota.getClassPK());
    quotaImpl.setQuotaAssigned(quota.getQuotaAssigned());
    quotaImpl.setQuotaUsed(quota.getQuotaUsed());
    quotaImpl.setQuotaStatus(quota.getQuotaStatus());
    quotaImpl.setQuotaAlert(quota.getQuotaAlert());

    return quotaImpl;
  }