How does \Magento\Sales\Model\ResourceModel\Order::_beforeSave() work?

Context: How does an order saving work?

958164/app/code/Magento/Sales/Model/ResourceModel/Order.php#L139-L165

/**
 * @param \Magento\Framework\Model\AbstractModel $object
 * @return $this
 */
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
	if (!$object->getId()) {
		/** @var \Magento\Store\Model\Store $store */
		$store = $object->getStore();
		$name = [
			$store->getWebsite()->getName(),
			$store->getGroup()->getName(),
			$store->getName(),
		];
		$object->setStoreName(implode(PHP_EOL, $name));
		$object->setTotalItemCount($this->calculateItems($object));
	}
	$object->setData(
		'protect_code',
		substr(md5(uniqid(Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6)
	);
	$isNewCustomer = !$object->getCustomerId() || $object->getCustomerId() === true;
	if ($isNewCustomer && $object->getCustomer()) {
		$object->setCustomerId($object->getCustomer()->getId());
	}
	return parent::_beforeSave($object);
}