@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;
  }
  /**
   * 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;
  }
  /**
   * Returns the quota where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if
   * it could not be found, optionally using the finder cache.
   *
   * @param classNameId the class name ID
   * @param classPK the class p k
   * @param retrieveFromCache whether to use the finder cache
   * @return the matching quota, or <code>null</code> if a matching quota could not be found
   * @throws SystemException if a system exception occurred
   */
  public Quota fetchByClassNameIdClassPK(long classNameId, long classPK, boolean retrieveFromCache)
      throws SystemException {
    Object[] finderArgs = new Object[] {classNameId, classPK};

    Object result = null;

    if (retrieveFromCache) {
      result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK, finderArgs, this);
    }

    if (result instanceof Quota) {
      Quota quota = (Quota) result;

      if ((classNameId != quota.getClassNameId()) || (classPK != quota.getClassPK())) {
        result = null;
      }
    }

    if (result == null) {
      StringBundler query = new StringBundler(3);

      query.append(_SQL_SELECT_QUOTA_WHERE);

      query.append(_FINDER_COLUMN_CLASSNAMEIDCLASSPK_CLASSNAMEID_2);

      query.append(_FINDER_COLUMN_CLASSNAMEIDCLASSPK_CLASSPK_2);

      String sql = query.toString();

      Session session = null;

      try {
        session = openSession();

        Query q = session.createQuery(sql);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(classNameId);

        qPos.add(classPK);

        List<Quota> list = q.list();

        result = list;

        Quota quota = null;

        if (list.isEmpty()) {
          FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK, finderArgs, list);
        } else {
          quota = list.get(0);

          cacheResult(quota);

          if ((quota.getClassNameId() != classNameId) || (quota.getClassPK() != classPK)) {
            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK, finderArgs, quota);
          }
        }

        return quota;
      } catch (Exception e) {
        throw processException(e);
      } finally {
        if (result == null) {
          FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK, finderArgs);
        }

        closeSession(session);
      }
    } else {
      if (result instanceof List<?>) {
        return null;
      } else {
        return (Quota) result;
      }
    }
  }
 protected void clearUniqueFindersCache(Quota quota) {
   FinderCacheUtil.removeResult(
       FINDER_PATH_FETCH_BY_CLASSNAMEIDCLASSPK,
       new Object[] {Long.valueOf(quota.getClassNameId()), Long.valueOf(quota.getClassPK())});
 }