public function save(\Tx_Oelib_Model $model)
    {
        if ($this->isModelAMemoryOnlyDummy($model)) {
            throw new \InvalidArgumentException(
                'This model is a memory-only dummy that must not be saved.',
                1331319682
            );
        }

        if (!$this->hasDatabaseAccess()
            || !$model->isDirty()
            || !$model->isLoaded()
            || $model->isReadOnly()
        ) {
            return;
        }

        $data = $this->getPreparedModelData($model);
        $this->cacheModelByKeys($model, $data);

        if ($model->hasUid()) {
            \Tx_Oelib_Db::update($this->getTableName(), 'uid = ' . $model->getUid(), $data);
            $this->deleteManyToManyRelationIntermediateRecords($model);
        } else {
            $this->prepareDataForNewRecord($data);
            $model->setUid(\Tx_Oelib_Db::insert($this->getTableName(), $data));
            $this->map->add($model);
        }

        if ($model->isDeleted()) {
            $model->markAsDead();
        } else {
            $model->markAsClean();
            // We save the 1:n relations after marking this model as clean
            // in order to avoid infinite loops when the foreign model tries
            // to save this parent.
            $this->saveOneToManyRelationRecords($model);
            $this->createManyToManyRelationIntermediateRecords($model);
        }
    }