/**
  * Update or rebuild the index.
  *
  * @param Mage_Index_Model_Event $event
  * @param array $limitToGroupIds Only add the specified group ids to the index
  * @return void
  */
 protected function _reindexEntity($event = null, array $limitToGroupIds = null)
 {
     Varien_Profiler::start($this->_getProfilerName() . '::reindexEntity');
     $this->_checkIndexTable();
     $this->_checkAttribute();
     $entityType = Mage::getSingleton('eav/config')->getEntityType($this->_getEntityTypeCode());
     $attribute = Mage::getSingleton('eav/config')->getAttribute($this->_getEntityTypeCode(), Netzarbeiter_GroupsCatalog2_Helper_Data::HIDE_GROUPS_ATTRIBUTE);
     $select = $this->_getReadAdapter()->select()->from(array('e' => $this->getTable($entityType->getEntityTable())), array('entity_id' => 'e.entity_id'))->joinLeft(array('a' => $attribute->getBackend()->getTable()), $this->_getReadAdapter()->quoteInto('e.entity_id=a.entity_id AND a.attribute_id = ?', $attribute->getId()), array('group_ids' => 'value', 'store_id' => 'store_id'))->order('e.entity_id ASC')->order('a.store_id ASC');
     $entityIds = array();
     if ($event && $event->hasData('entity_ids')) {
         $entityIds = $event->getData('entity_ids');
         $select->where('e.entity_id IN (?)', $entityIds);
     }
     $this->_clearRecordsForReindex($entityIds, $limitToGroupIds);
     $stmt = $this->_getReadAdapter()->query($select);
     $this->_insertIndexRecords($stmt, $limitToGroupIds);
     Varien_Profiler::stop($this->_getProfilerName() . '::reindexEntity');
 }