Package com.metadot.book.connectr.server.domain

Examples of com.metadot.book.connectr.server.domain.Friend


  public FriendDTO updateFriend(FriendDTO friendDTO) {

    PersistenceManager pm = PMF.getTxnPm();
    if (friendDTO.getId() == null) { // create new Friend
      Friend newFriend = addFriend(friendDTO);
      return newFriend.toDTO();
    }

    // otherwise, do an update of an existing Friend.
    // do this operation under transactional control
    Friend friend = null;
    try {
      for (int i = 0; i < NUM_RETRIES; i++) {
        pm.currentTransaction().begin();
        friend = pm.getObjectById(Friend.class, friendDTO.getId());

        Set<String> origurls = new HashSet<String>(friend.getUrls());
        logger.info("original Friend urls are: " + origurls);

        // delete feed information from the feedids cache
        // only need to do this if the URLs set has changed
        if (!origurls.equals(friendDTO.getUrls())) {
          CacheSupport.cacheDelete(feedids_nmspce, friendDTO.getId());
        }

        friend.updateFromDTO(friendDTO);

        if (!(origurls.isEmpty() && friendDTO.getUrls().isEmpty())) {
          // build task payload:
          Map<String, Object> hm = new HashMap<String, Object>();
          hm.put("newurls", friendDTO.getUrls());
View Full Code Here


  }
 
  private Friend addFriend(FriendDTO friendDTO) {

    PersistenceManager pm = PMF.getTxnPm();
    Friend friend = null;
    String fid = null;
    try {
      // do this operation under transactional control
      for (int i = 0; i < NUM_RETRIES; i++) {
        pm.currentTransaction().begin();

        UserAccount currentUser = LoginHelper.getLoggedInUser(getThreadLocalRequest().getSession(), pm);

        friend = new Friend(friendDTO);
        currentUser.getFriends().add(friend);
        pm.makePersistent(currentUser);
        fid = friend.getId();
       
        if (!(friendDTO.getUrls().isEmpty())) {
          // build task payload:
          Map<String, Object> hm = new HashMap<String, Object>();
          hm.put("newurls", friendDTO.getUrls());
View Full Code Here

    CacheSupport.cacheDelete(feedids_nmspce, id);

    logger.fine("in deleteFriend, pm is: " + pm);
    Set<String> urls = null;
    Friend friend = null;
    String retval = null;
    try {
      for (int i = 0; i < NUM_RETRIES; i++) {
        pm.currentTransaction().begin();
        friend = pm.getObjectById(Friend.class, id);

        if (friend != null) {
          urls = friend.getDetails().getUrls();

          Map<String, Object> hm = new HashMap<String, Object>();
          hm.put("origurls", urls);
          hm.put("delete", true);
          hm.put("fid", id);
View Full Code Here

  }
 
  public FriendDTO getFriend(String id) {

    PersistenceManager pm = PMF.getNonTxnPm();
    Friend detached = null;

    try {
      detached = getFriendViaCache(id, pm);
    } finally {
      pm.close();
    }
    logger.fine("in getFriend- urls are: " + detached.getUrls());
    return detached.toDTO();
  }
View Full Code Here

    logger.fine("in getFriend- urls are: " + detached.getUrls());
    return detached.toDTO();
  }

  private Friend getFriendViaCache(String id, PersistenceManager pm) {
    Friend dsFriend = null, detached = null;

    // check cache first
    Object o = null;
    o = CacheSupport.cacheGet(Friend.class.getName(), id);
    if (o != null && o instanceof Friend) {
      detached = (Friend) o;
      logger.fine("cache hit for Friend " + detached);
    } else {
      dsFriend = pm.getObjectById(Friend.class, id); // the get adds
                            // to cache
      dsFriend.getDetails();
      detached = pm.detachCopy(dsFriend);
    }
    return detached;
  }
View Full Code Here

 
  /**
   * add the sample Friends
   */
  public static void addFriends(UserAccount user) {
    Friend friend;
    for (int i = 0; i < friendsFirstNameData.length; ++i) {
      friend = new Friend();
      friend.setBasicInfo(friendsFirstNameData[i], friendsLastNameData[i], friendsEmailData[i]);
      log.info("Adding friend: " + friend.getFirstName());
      user.addFriend(friend);
    } // end for
  }
View Full Code Here

TOP

Related Classes of com.metadot.book.connectr.server.domain.Friend

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.