ViewNavigator Fails on Traversal Back to Category

100 views Asked by At

I'm getting an interesting error in some code that is near identical (at least in structure) to code I have working, elsewhere. I'm getting a "Notes error: Entry not found in index " error, and it occurs in the line of my ViewNavigator.getNext(ViewEntry) in a while loop. I feel like I'm missing something obvious on this one, so hopefully someone can spot it (I'm going batty from just staring at it).

[Update] Jesse's note on setting autoUpdate to false did the trick. It seems to relate back to this tech note from 2002, as my loop does save to another document (same DB, different View) during this loop. I succeeded by placing vw.setAutoUpdate(false); immediately after I defined my handle on the View. [/Update]

I'm walking a single-category View (by reference field value from each Document in the View) to summarize some information from the grouped Documents. After enabling debug, I found that the error occurs on my traversal from the last Document (ViewEntry of a Doc) in the first category back to a category (ViewEntry).

Here's a stripped down version of my code (//... denotes removed lines for clarity):

View vw = db.getView("<ViewName>");
ViewNavigator nav = vw.createViewNav();
ViewEntry first = nav.getFirst();
String unid = "";
while(first != null){
  if(first.isCategory()){
    if(!unid.isEmpty()){
      //summarize the info and save it back to the category-relevant doc
      Document myDoc = db.getDocumentByUNID(unid);
      //doing my thing
      boolean success = myDoc.save(true, false);
      myDoc.recycle();
    }
    unid = "";
  }
  if(first.isDocument()){
    Vector<?> colVals = first.getColumnValues();
    if(unid.isEmpty()){
      //reset temp aggregation vars back to initial value (e.g.- 0)
      //...
      unid = (String) colVals.get(5); // the value of the category-relevant UNID
    }else{
      //doing the aggregation of summary values with the temp vars established before and handled after
      //...
      //perform aggregation from colVals with temp vars
    }
    session.recycle(colVals);
  }
  ViewEntry tmp = nav.getNext(first); //this is the line that fails!! only if it's the next category, which there is one
  first.recycle();
  first = tmp;
}
1

There are 1 answers

1
Jesse Gallagher On BEST ANSWER

Setting view.setAutoUpdate(false) should clear it up, probably because of the document save in there.

I've found it to be a good policy to set this all the time after fetching a view (I believe ODA does it automatically in Khan mode). It also then lets you set nav.setBufferMaxEntries(400), which improves lengthy view navigation.