public function writeSession($id, $data)
    {
        // exception must be caught in session write handler
        // http://us.php.net/manual/en/function.session-set-save-handler.php#refsect1-function.session-set-save-handler-notes
        try {
            $fields = $this->composeFields($id, $data);
            $fields = $this->typecastFields($fields);
            $this->db->createCommand()->upsert($this->sessionTable, $fields)->execute();
        } catch (\Exception $e) {
            Yii::getApp()->errorHandler->handleException($e);
            return false;
        }

        return true;
    }