public function store($updateNulls = false)
    {
        $k = $this->getKeyName();

        /*
         * If the primary key is empty, then we assume we are inserting a new node into the
         * tree.  From this point we would need to determine where in the tree to insert it.
         */
        if (empty($this->$k)) {
            /*
             * We are inserting a node somewhere in the tree with a known reference
             * node.  We have to make room for the new node and set the left and right
             * values before we insert the row.
             */
            if ($this->locationId < 0) {
                // Negative parent ids are invalid
                throw new NestedHandleException(sprintf('%s::store() used a negative _location_id', get_class($this)));
            }

            // We are inserting a node relative to the last root node.
            if ($this->locationId == 0) {
                // Get the last root node as the reference node.
                $query = $this->db->getQuery(true)
                    ->select($this->getKeyName() . ', parent_id, level, lft, rgt')
                    ->from($this->db->quoteName($this->table))
                    ->where('parent_id = 0')
                    ->order('lft DESC')
                    ->limit(1);

                $this->db->setQuery($query);

                $reference = $this->db->loadOne();
            } else {
                // We have a real node set as a location reference.
                // Get the reference node by primary key.
                if (!$reference = $this->getNode($this->locationId)) {
                    throw new NestedHandleException('Cannot get node by location id: ' . $this->locationId);
                }
            }

            // Get the reposition data for shifting the tree and re-inserting the node.
            if (!($repositionData = $this->getTreeRepositionData($reference, 2, $this->location))) {
                throw new NestedHandleException('Cannot get reposition data.');
            }

            // Create space in the tree at the new location for the new node in left ids.
            $query = $this->db->getQuery(true)
                ->update($this->db->quoteName($this->table))
                ->set('lft = lft + 2')
                ->where($repositionData->left_where);

            $this->db->setQuery($query)->execute();

            // Create space in the tree at the new location for the new node in right ids.
            $query->clear()
                ->update($this->db->quoteName($this->table))
                ->set('rgt = rgt + 2')
                ->where($repositionData->right_where);

            $this->db->setQuery($query)->execute();

            // Set the object values.
            $this->parent_id = $repositionData->new_parent_id;
            $this->level = $repositionData->new_level;
            $this->lft = $repositionData->new_lft;
            $this->rgt = $repositionData->new_rgt;
        } else {
            /*
             * If we have a given primary key then we assume we are simply updating this
             * node in the tree.  We should assess whether or not we are moving the node
             * or just updating its data fields.
             */

            // If the location has been set, move the node to its new location.
            if ($this->locationId > 0) {
                $this->moveByReference($this->locationId, $this->location, $this->$k);
            }
        }

        return parent::store($updateNulls);
    }