@Override
  public long performCount() throws PortalException {
    if (_performCountMethod != null) {
      return _performCountMethod.performCount();
    }

    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(_clazz, _classLoader);

    addDefaultCriteria(dynamicQuery);

    addCriteria(dynamicQuery);

    return (Long) executeDynamicQuery(_dynamicQueryCountMethod, dynamicQuery, getCountProjection());
  }
  protected long doPerformActions(long previousPrimaryKey) throws PortalException {

    final DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(_clazz, _classLoader);

    Property property = PropertyFactoryUtil.forName(_primaryKeyPropertyName);

    dynamicQuery.add(property.gt(previousPrimaryKey));

    dynamicQuery.addOrder(OrderFactoryUtil.asc(_primaryKeyPropertyName));

    dynamicQuery.setLimit(0, _interval);

    addDefaultCriteria(dynamicQuery);

    addCriteria(dynamicQuery);

    Callable<Long> callable =
        new Callable<Long>() {

          @Override
          public Long call() throws Exception {
            List<Object> objects =
                (List<Object>) executeDynamicQuery(_dynamicQueryMethod, dynamicQuery);

            if (objects.isEmpty()) {
              return -1L;
            }

            for (Object object : objects) {
              performAction(object);
            }

            if (objects.size() < _interval) {
              return -1L;
            }

            BaseModel<?> baseModel = (BaseModel<?>) objects.get(objects.size() - 1);

            return (Long) baseModel.getPrimaryKeyObj();
          }
        };

    TransactionAttribute transactionAttribute = getTransactionAttribute();

    try {
      if (transactionAttribute == null) {
        return callable.call();
      } else {
        return TransactionInvokerUtil.invoke(transactionAttribute, callable);
      }
    } catch (Throwable t) {
      if (t instanceof PortalException) {
        throw (PortalException) t;
      }

      if (t instanceof SystemException) {
        throw (SystemException) t;
      }

      throw new SystemException(t);
    } finally {
      indexInterval();
    }
  }