/**
  * Load the next bunch of items
  * 
  * @return void
  * @access public
  * @since 3/1/06
  */
 function loadNext()
 {
     $dbc = Services::getService("DatabaseManager");
     // get the list of the next set of Ids
     $query = new SelectQuery();
     $query->addTable("log_entry");
     $query->addColumn("id", "entry_id", "log_entry");
     $query->setDistinct(true);
     $query->addOrderBy("timestamp", DESCENDING);
     $this->addWhereClauses($query);
     $query->limitNumberOfRows($this->_numPerLoad);
     if ($this->_currentRow) {
         $query->startFromRow($this->_currentRow + 1);
     }
     // 		printpre('CurrentRow at load: '.$this->_currentRow);
     // 		printpre($query->asString());
     $results = $dbc->query($query, $this->_dbIndex);
     $nextIds = array();
     while ($results->hasNext()) {
         $row = $results->next();
         $nextIds[] = $row['entry_id'];
     }
     // 		printpre($nextIds);
     /*********************************************************
      * Load the rows for the next set of Ids
      *********************************************************/
     $query = new SelectQuery();
     $query->addTable("log_entry");
     $query->addColumn("id", "id", "log_entry");
     $query->addColumn("timestamp", "timestamp", "log_entry");
     $query->addColumn("category", "category", "log_entry");
     $query->addColumn("description", "description", "log_entry");
     $query->addColumn("backtrace", "backtrace", "log_entry");
     $subQuery = new SelectQuery();
     $subQuery->addColumn("*");
     $subQuery->addTable("log_agent");
     $subQuery->addWhereIn("fk_entry", $nextIds);
     $query->addDerivedTable($subQuery, LEFT_JOIN, "log_entry.id = tmp_agent.fk_entry", "tmp_agent");
     $query->addColumn("fk_agent", "agent_id", "tmp_agent");
     $subQuery = new SelectQuery();
     $subQuery->addColumn("*");
     $subQuery->addTable("log_node");
     $subQuery->addWhereIn("fk_entry", $nextIds);
     $query->addDerivedTable($subQuery, LEFT_JOIN, "log_entry.id = tmp_node.fk_entry", "tmp_node");
     $query->addColumn("fk_node", "node_id", "tmp_node");
     $query->addWhereIn("id", $nextIds);
     $query->addOrderBy("timestamp", DESCENDING);
     $query->addOrderBy("id", ASCENDING);
     //  		printpre($query->asString());
     $results = $dbc->query($query, $this->_dbIndex);
     $i = $this->_current;
     $currentEntryId = null;
     $timestamp = null;
     $category = null;
     $description = null;
     $backtrace = '';
     $agents = array();
     $nodes = array();
     while ($results->hasNext()) {
         $row = $results->next();
         // Create the entry if we have all of the data for it.
         if ($currentEntryId && $currentEntryId != $row["id"]) {
             // 				printpre("Creating Entry: ".$currentEntryId." ".$timestamp." -- ".($i+1)." of ".$this->_count);
             $this->_entries[$i] = new HarmoniEntry($dbc->fromDBDate($timestamp, $this->_dbIndex), $category, $description, $backtrace, array_unique($agents), array_unique($nodes), $this->_formatType, $this->_priorityType);
             $i++;
             $this->_currentRow++;
             $currentEntryId = null;
             $timestamp = null;
             $category = null;
             $description = null;
             $backtrace = '';
             $agents = array();
             $nodes = array();
         }
         $currentEntryId = $row["id"];
         $timestamp = $row["timestamp"];
         $category = $row["category"];
         $description = $row["description"];
         $backtrace = $row["backtrace"];
         $agents[] = $row["agent_id"];
         $nodes[] = $row["node_id"];
         // 			printpre($currentEntryId." ".$timestamp." ".$this->_currentRow);
     }
     $results->free();
     // get the last entry if we are at the end of the iterator
     if ($currentEntryId && $i == $this->_count - 1) {
         // 			printpre("Creating Entry: ".$currentEntryId." ".$timestamp." -- ".($i+1)." of ".$this->_count);
         $this->_entries[$i] = new HarmoniEntry($dbc->fromDBDate($timestamp, $this->_dbIndex), $category, $description, $backtrace, array_unique($agents), array_unique($nodes), $this->_formatType, $this->_priorityType);
     }
 }