Package com.google.livingstories.server.dataservices.entities

Examples of com.google.livingstories.server.dataservices.entities.UserLivingStoryEntity


*/
public class UserDataServiceImpl implements UserDataService {

  @Override
  public synchronized Date getLastVisitTimeForStory(String userId, Long livingStoryId) {
    UserLivingStoryEntity entity = retrieveUserLivingStoryEntity(userId, livingStoryId);
    return entity == null ? null : entity.getLastVisitedTime();
  }
View Full Code Here


    }
  }

  @Override
  public synchronized boolean isUserSubscribedToEmails(String userId, Long livingStoryId) {
    UserLivingStoryEntity entity = retrieveUserLivingStoryEntity(userId, livingStoryId);
    return entity == null ? false : entity.isSubscribedToEmails();
  }
View Full Code Here

    return entity == null ? false : entity.isSubscribedToEmails();
  }
 
  @Override
  public synchronized int getVisitCountForStory(String userId, Long livingStoryId) {
    UserLivingStoryEntity entity = retrieveUserLivingStoryEntity(userId, livingStoryId);
    return entity == null ? 0 : entity.getVisitCount();
  }
View Full Code Here

    }
  }

  @Override
  public synchronized void updateVisitDataForStory(String userEmail, Long livingStoryId) {
    UserLivingStoryEntity userLivingStoryEntity =
        retrieveUserLivingStoryEntity(userEmail, livingStoryId);
    if (userLivingStoryEntity == null) {
      // This means the user has not visited this living story before. A new row needs to be added.
      // Check if a userEntity exists for this user.  If not, we need to create that first.
      if (retrieveUserEntity(userEmail) == null) {
        createNewUserEntity(userEmail);
      }
      createNewUserLivingStoryEntity(userEmail, livingStoryId, false, null);
    } else {
      // This means the user has visited this living story before and the timestamp needs to be
      // updated in place.
      PersistenceManager pm = PMF.get().getPersistenceManager();
     
      try {
        // This object needs to be queried using its primary key from the same
        // PeristentManager object as the one that is going to persist it
        userLivingStoryEntity = pm.getObjectById(
            UserLivingStoryEntity.class, userLivingStoryEntity.getId());
        userLivingStoryEntity.setLastVisitedTime(new Date());
        userLivingStoryEntity.incrementVisitCount();
        pm.makePersistent(userLivingStoryEntity);
      } finally {
        pm.close();
      }
    }
View Full Code Here

  }
 
  @Override
  public synchronized void setEmailSubscription(String userEmail, Long livingStoryId,
      boolean subscribe, String localeId) {
    UserLivingStoryEntity userLivingStoryEntity =
        retrieveUserLivingStoryEntity(userEmail, livingStoryId);
    if (userLivingStoryEntity == null) {
      // This means the user has not visited this living story before. A new row needs to be added.
      // Check if a userEntity exists for this user.  If not, we need to create that first.
      if (retrieveUserEntity(userEmail) == null) {
        createNewUserEntity(userEmail);
      }
      createNewUserLivingStoryEntity(userEmail, livingStoryId, subscribe, localeId);
    } else {
      // This means the user has visited this living story before and only the subscription needs
      // to be updated.
      PersistenceManager pm = PMF.get().getPersistenceManager();
      try {
        // This object needs to be queried using its primary key from the same
        // PersistentManager object as the one that is going to persist it
        userLivingStoryEntity = pm.getObjectById(
            UserLivingStoryEntity.class, userLivingStoryEntity.getId());
        userLivingStoryEntity.setSubscribedToEmails(subscribe);
        userLivingStoryEntity.setSubscriptionLocale(localeId);
        pm.makePersistent(userLivingStoryEntity);
      } finally {
        pm.close();
      }
    }
View Full Code Here

   */
  private UserLivingStoryEntity createNewUserLivingStoryEntity(String userEmail,
      Long livingStoryId, boolean subscribedToEmails, String localeId) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      UserLivingStoryEntity userLivingStoryEntity =
          new UserLivingStoryEntity(userEmail, livingStoryId, new Date());
      userLivingStoryEntity.setSubscribedToEmails(subscribedToEmails);
      if (localeId != null) {
        userLivingStoryEntity.setSubscriptionLocale(localeId);
      }
      pm.makePersistent(userLivingStoryEntity);
      return userLivingStoryEntity;
    } finally {
      pm.close();
View Full Code Here

TOP

Related Classes of com.google.livingstories.server.dataservices.entities.UserLivingStoryEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.