protected SocialActivitySet addSocialActivitySet() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SocialActivitySet socialActivitySet = _persistence.create(pk);

    socialActivitySet.setGroupId(RandomTestUtil.nextLong());

    socialActivitySet.setCompanyId(RandomTestUtil.nextLong());

    socialActivitySet.setUserId(RandomTestUtil.nextLong());

    socialActivitySet.setCreateDate(RandomTestUtil.nextLong());

    socialActivitySet.setModifiedDate(RandomTestUtil.nextLong());

    socialActivitySet.setClassNameId(RandomTestUtil.nextLong());

    socialActivitySet.setClassPK(RandomTestUtil.nextLong());

    socialActivitySet.setType(RandomTestUtil.nextInt());

    socialActivitySet.setExtraData(RandomTestUtil.randomString());

    socialActivitySet.setActivityCount(RandomTestUtil.nextInt());

    _socialActivitySets.add(_persistence.update(socialActivitySet));

    return socialActivitySet;
  }
  public SocialActivitySet addActivitySet(long activityId) throws PortalException, SystemException {

    // Activity set

    SocialActivity activity = socialActivityPersistence.findByPrimaryKey(activityId);

    long activitySetId = counterLocalService.increment();

    SocialActivitySet activitySet = socialActivitySetPersistence.create(activitySetId);

    activitySet.setGroupId(activity.getGroupId());
    activitySet.setCompanyId(activity.getCompanyId());
    activitySet.setUserId(activity.getUserId());
    activitySet.setCreateDate(activity.getCreateDate());
    activitySet.setModifiedDate(activity.getCreateDate());
    activitySet.setClassName(activity.getClassName());
    activitySet.setClassPK(activity.getClassPK());
    activitySet.setType(activity.getType());
    activitySet.setActivityCount(1);

    socialActivitySetPersistence.update(activitySet);

    // Activity

    activity.setActivitySetId(activitySetId);

    socialActivityPersistence.update(activity);

    return activitySet;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SocialActivitySet newSocialActivitySet = _persistence.create(pk);

    newSocialActivitySet.setGroupId(RandomTestUtil.nextLong());

    newSocialActivitySet.setCompanyId(RandomTestUtil.nextLong());

    newSocialActivitySet.setUserId(RandomTestUtil.nextLong());

    newSocialActivitySet.setCreateDate(RandomTestUtil.nextLong());

    newSocialActivitySet.setModifiedDate(RandomTestUtil.nextLong());

    newSocialActivitySet.setClassNameId(RandomTestUtil.nextLong());

    newSocialActivitySet.setClassPK(RandomTestUtil.nextLong());

    newSocialActivitySet.setType(RandomTestUtil.nextInt());

    newSocialActivitySet.setExtraData(RandomTestUtil.randomString());

    newSocialActivitySet.setActivityCount(RandomTestUtil.nextInt());

    _socialActivitySets.add(_persistence.update(newSocialActivitySet));

    SocialActivitySet existingSocialActivitySet =
        _persistence.findByPrimaryKey(newSocialActivitySet.getPrimaryKey());

    Assert.assertEquals(
        existingSocialActivitySet.getActivitySetId(), newSocialActivitySet.getActivitySetId());
    Assert.assertEquals(existingSocialActivitySet.getGroupId(), newSocialActivitySet.getGroupId());
    Assert.assertEquals(
        existingSocialActivitySet.getCompanyId(), newSocialActivitySet.getCompanyId());
    Assert.assertEquals(existingSocialActivitySet.getUserId(), newSocialActivitySet.getUserId());
    Assert.assertEquals(
        existingSocialActivitySet.getCreateDate(), newSocialActivitySet.getCreateDate());
    Assert.assertEquals(
        existingSocialActivitySet.getModifiedDate(), newSocialActivitySet.getModifiedDate());
    Assert.assertEquals(
        existingSocialActivitySet.getClassNameId(), newSocialActivitySet.getClassNameId());
    Assert.assertEquals(existingSocialActivitySet.getClassPK(), newSocialActivitySet.getClassPK());
    Assert.assertEquals(existingSocialActivitySet.getType(), newSocialActivitySet.getType());
    Assert.assertEquals(
        existingSocialActivitySet.getExtraData(), newSocialActivitySet.getExtraData());
    Assert.assertEquals(
        existingSocialActivitySet.getActivityCount(), newSocialActivitySet.getActivityCount());
  }
  public void decrementActivityCount(long activitySetId) throws PortalException, SystemException {

    if (activitySetId == 0) {
      return;
    }

    SocialActivitySet activitySet = socialActivitySetPersistence.findByPrimaryKey(activitySetId);

    if (activitySet.getActivityCount() == 1) {
      socialActivitySetPersistence.remove(activitySetId);

      return;
    }

    activitySet.setActivityCount(activitySet.getActivityCount() - 1);

    socialActivitySetPersistence.update(activitySet);
  }
  public void incrementActivityCount(long activitySetId, long activityId)
      throws PortalException, SystemException {

    // Activity set

    SocialActivitySet activitySet = socialActivitySetPersistence.findByPrimaryKey(activitySetId);

    SocialActivity activity = socialActivityPersistence.findByPrimaryKey(activityId);

    activitySet.setModifiedDate(activity.getCreateDate());

    activitySet.setActivityCount(activitySet.getActivityCount() + 1);

    socialActivitySetPersistence.update(activitySet);

    // Activity

    activity.setActivitySetId(activitySetId);

    socialActivityPersistence.update(activity);
  }