protected void importRatings(long oldClassNameId, long oldClassPK, long classNameId, long classPK)
      throws SystemException {

    List<RatingsEntry> ratingsEntries =
        ratingsEntryPersistence.findByC_C(oldClassNameId, oldClassPK);

    for (RatingsEntry ratingsEntry : ratingsEntries) {
      addRatingsEntry(
          counterLocalService.increment(),
          ratingsEntry.getCompanyId(),
          ratingsEntry.getUserId(),
          ratingsEntry.getUserName(),
          ratingsEntry.getCreateDate(),
          ratingsEntry.getModifiedDate(),
          classNameId,
          classPK,
          ratingsEntry.getScore());
    }

    RatingsStats ratingsStats = ratingsStatsPersistence.fetchByC_C(oldClassNameId, oldClassPK);

    if (ratingsStats == null) {
      return;
    }

    addRatingsStats(
        counterLocalService.increment(),
        classNameId,
        classPK,
        ratingsStats.getTotalEntries(),
        ratingsStats.getTotalScore(),
        ratingsStats.getAverageScore());
  }
  /**
   * Adds the ratings stats to the database. Also notifies the appropriate model listeners.
   *
   * @param ratingsStats the ratings stats
   * @return the ratings stats that was added
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public RatingsStats addRatingsStats(RatingsStats ratingsStats) {
    ratingsStats.setNew(true);

    return ratingsStatsPersistence.update(ratingsStats);
  }
  protected RatingsStats addRatingsStats(
      long statsId,
      long classNameId,
      long classPK,
      int totalEntries,
      double totalScore,
      double averageScore)
      throws SystemException {

    RatingsStats ratingsStats = ratingsStatsPersistence.create(statsId);

    ratingsStats.setClassNameId(classNameId);
    ratingsStats.setClassPK(classPK);
    ratingsStats.setTotalEntries(totalEntries);
    ratingsStats.setTotalScore(totalScore);
    ratingsStats.setAverageScore(averageScore);

    return ratingsStatsPersistence.update(ratingsStats);
  }