private function _writeObjectToDb($object, $id)
    {
        $objectId = (!is_null($id)) ? $id : $this->_generateUniqueId();
        $origin = $this->_getObjectOrigin($objectId);
        $object = json_decode(json_encode($object));
        $object->__id = $objectId;
        $object->__revision = $this->_generateRevisionNumber();
        $object->__updated = $this->_generateTimestamp();
        $object->__origin = ($origin) ? $origin : $object->__updated;

        //insert into database
        $insert = Statement::get(
            'INSERT_OBJECT',
            [
                '@collection' => $this->_name,
                '@id' => $this->_connector->quote($object->__id),
                '@revision' => $this->_connector->quote($object->__revision),
                '@committed' => $this->_connector->quote(0),
                '@updated' => $this->_connector->quote($object->__updated),
                '@origin' => $this->_connector->quote($object->__origin),
                '@obj' => $this->_connector->quote(json_encode($object))
            ]
        );
        $this->_connector->exec($insert);
        return $object;
    }