Example #1
0
  private synchronized void updateLocalTradeSessions(Collection<TradeSession> remoteList) {
    // Get all the local sessions
    Collection<TradeSession> localList = _db.getAll();

    // Iterate over local items to find records to delete or update locally
    Iterator<TradeSession> localIt = localList.iterator();
    while (localIt.hasNext()) {
      TradeSession localItem = localIt.next();
      TradeSession remoteItem = findAndEliminate(localItem, remoteList);
      if (remoteItem == null) {
        // A local item is not in the remote list, remove it locally
        _db.delete(localItem.id);
      } else {
        // A local item is in the new list, see if it needs to be updated
        if (needsUpdate(localItem, remoteItem)) {
          _db.update(remoteItem);
        }
      }
    }

    // Iterate over remaining remote items and insert them
    Iterator<TradeSession> remoteIt = remoteList.iterator();
    while (remoteIt.hasNext()) {
      TradeSession remoteItem = remoteIt.next();
      _db.insert(remoteItem);
    }
  }
Example #2
0
 public synchronized Collection<TradeSession> getLocalTradeSessions() {
   return _db.getAll();
 }