pm.addReferences(channelID, toAdd, true);
pm.pageReferences(channelID, toAdd, true);
   protected void flushDownCache() throws Exception   {      if (trace) { log.trace(this + " flushing " + downCache.size() + " refs from downcache"); }      // Non persistent refs won't already be in the db so they need to be inserted      // Persistent refs in a recoverable state will already be there so need to      // be updated      List toUpdate = new ArrayList();      List toAdd = new ArrayList();      Iterator iter = downCache.iterator();            while (iter.hasNext())      {         MessageReference ref = (MessageReference) iter.next();                  if (ref.isReliable() && recoverable)         {            toUpdate.add(ref);         }         else         {            toAdd.add(ref);         }      }      if (!toAdd.isEmpty())      {         pm.addReferences(channelID, toAdd, true);      }      if (!toUpdate.isEmpty())      {         pm.updatePageOrder(channelID, toUpdate);      }      // Release in memory refs for the refs we just spilled      // Note! This must be done after the db inserts - to ensure message is      // still in memory      iter = downCache.iterator();      while (iter.hasNext())      {         MessageReference ref = (MessageReference) iter.next();         ref.releaseMemoryReference();      }      downCache.clear();               if (trace) { log.trace(this + " cleared downcache"); }   }