code: public void endRecord_() {
      // this is where we actually update the link database. basically,
      // all we need to do is to retract those links which weren't seen
      // this time around, and that can be done via assertLink, since it
      // can override existing links.
  
      // get all the existing links
      Collection<Link> oldlinks = linkdb.getAllLinksFor(getIdentity(current));
  
      // build a hashmap so we can look up corresponding old links from
      // new links
      if (oldlinks != null) {
        Map<String, Link> oldmap = new HashMap(oldlinks.size());
        for (Link l : oldlinks)
          oldmap.put(makeKey(l), l);
  
        // removing all the links we found this time around from the set of
        // old links. any links remaining after this will be stale, and need
        // to be retracted
        for (Link newl : new ArrayList<Link>(curlinks)) {
          String key = makeKey(newl);
          Link oldl = oldmap.get(key);
          if (oldl == null)
            continue;
  
          if (oldl.overrides(newl))
            // previous information overrides this link, so ignore
            curlinks.remove(newl);
          else if (sameAs(oldl, newl)) {
            // there's no new information here, so just ignore this
            curlinks.remove(newl);
            oldmap.remove(key); // we don't want to retract the old one
          } else
            // the link is out of date, but will be overwritten, so remove
            oldmap.remove(key);
        }
  
        // all the inferred links left in oldmap are now old links we
        // didn't find on this pass. there is no longer any evidence
        // supporting them, and so we can retract them.
        for (Link oldl : oldmap.values())
          if (oldl.getStatus() == LinkStatus.INFERRED) {
            oldl.retract(); // changes to retracted, updates timestamp
            curlinks.add(oldl);
          }
      }
  
      // okay, now we write it all to the database
      for (Link l : curlinks)
        linkdb.assertLink(l);
    }
docs: this method is called from the event methods