def add_element(self, elem):

        self.db.store(elem)

        # If the element is a node, add it to the appropriate geodoc.
        ns = elem.namespace
        backreference = make_backreference(ns, elem.id)

        if self.verbose:
            increment_stats(ns)

        # Do element-specific processing.
        if ns == C.NODE:
            # Add the element to the appropriate geodoc.
            self.geotable.add(elem)

        elif ns == C.WAY:
            # Backlink referenced nodes to the current way.
            for (rstatus, node_or_key) in \
                    self.db.fetch_keys(C.NODE, map(str, elem[C.NODES])):
                if rstatus:
                    node = node_or_key
                else:
                    node = new_osm_element(C.NODE, node_or_key)
                node[C.REFERENCES].add(backreference)
                self.db.store(node)

        elif ns == C.RELATION:
            # If the element is a relation, backlink referenced ways &
            # relations.

            def _retrieve(selector, members):
                return [str(mref) for (mref, mrole, mtype) in members
                        if mtype == selector]

            members = elem[C.MEMBERS]

            elements = []
            for ns in [C.NODE, C.WAY, C.RELATIONS]:
                elements.append((ns, _retrieve(ns, members)))

            for (ns, refs) in elements:
                if len(refs) == 0:
                    continue
                for (rstatus, node_or_key) in self.db.fetch_keys(ns, refs):
                    # Retrieve all elements referenced by the relation.
                    if rstatus:
                        elem = node_or_key
                    else:
                        elem = new_osm_element(ns, node_or_key)

                    # Add a backreference to the element being
                    # referenced by this relation.
                    elem[C.REFERENCES].add(backreference)
                    self.db.store(elem)
Add an element to the datastore.
dataset/ETHPy150Open MapQuest/mapquest-osm-server/src/python/dbmgr/dbm_ops.py/DBOps.add_element