'Create the resource in the database.
If self.id is set, we update the existing stack.'

def store(self, set_metadata=False, lock=LOCK_NONE):

    if (not self.root_stack_id):
        self.root_stack_id = self.stack.root_stack_id()
    rs = {'action': self.action, 'status': self.status, 'status_reason': six.text_type(self.status_reason), 'stack_id': self.stack.id, 'physical_resource_id': self.resource_id, 'name': self.name, 'rsrc_prop_data_id': self._create_or_replace_rsrc_prop_data(), 'needed_by': self.needed_by, 'requires': self.requires, 'replaces': self.replaces, 'replaced_by': self.replaced_by, 'current_template_id': self.current_template_id, 'root_stack_id': self.root_stack_id, 'updated_at': self.updated_time, 'properties_data': None}
    if set_metadata:
        metadata = self.t.metadata()
        rs['rsrc_metadata'] = metadata
        self._rsrc_metadata = metadata
    if (self.id is not None):
        if ((lock == self.LOCK_NONE) or (self._calling_engine_id is None)):
            resource_objects.Resource.update_by_id(self.context, self.id, rs)
            if ((lock != self.LOCK_NONE) and (self._calling_engine_id is None)):
                LOG.warning('no    calling_engine_id    in    store    %s', str(rs))
        else:
            self._store_with_lock(rs, lock)
    else:
        new_rs = resource_objects.Resource.create(self.context, rs)
        self.id = new_rs.id
        self.uuid = new_rs.uuid
        self.created_time = new_rs.created_at
