MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
全部  文件 函数 变量 枚举 枚举值 宏定义  
session.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Wangyunlai on 2021/5/12.
13//
14
15#pragma once
16
17#include <string>
18
19class Trx;
20class Db;
21class SessionEvent;
22
27class Session
28{
29public:
34 static Session &default_session();
35
36public:
37 Session() = default;
38 ~Session();
39
40 Session(const Session &other);
41 void operator=(Session &) = delete;
42
43 const char *get_current_db_name() const;
44 Db *get_current_db() const;
45
51 void set_current_db(const std::string &dbname);
52
56 void set_trx_multi_operation_mode(bool multi_operation_mode);
57
61 bool is_trx_multi_operation_mode() const;
62
68
72 void set_current_request(SessionEvent *request);
73
78
79 void set_sql_debug(bool sql_debug) { sql_debug_ = sql_debug; }
80 bool sql_debug_on() const { return sql_debug_; }
81
86 static void set_current_session(Session *session);
87
92 static Session *current_session();
93
94private:
95 Db *db_ = nullptr;
96 Trx *trx_ = nullptr;
99 bool sql_debug_ = false;
100};
一个DB实例负责管理一批表
Definition: db.h:34
表示一个SQL请求
Definition: session_event.h:32
表示会话
Definition: session.h:28
static Session * current_session()
获取当前的会话
Definition: session.cpp:89
bool sql_debug_
是否输出SQL调试信息
Definition: session.h:99
static Session & default_session()
获取默认的会话数据,新生成的会话都基于默认会话设置参数
Definition: session.cpp:21
bool is_trx_multi_operation_mode() const
当前事务是否为多语句模式
Definition: session.cpp:69
static void set_current_session(Session *session)
将指定会话设置到线程变量中
Definition: session.cpp:84
void set_current_request(SessionEvent *request)
设置当前正在处理的请求
Definition: session.cpp:94
bool trx_multi_operation_mode_
当前事务的模式,是否多语句模式. 单语句模式自动提交
Definition: session.h:98
SessionEvent * current_request_
当前正在处理的请求
Definition: session.h:97
Trx * current_trx()
当前会话关联的事务
Definition: session.cpp:74
void set_current_db(const std::string &dbname)
设置当前会话关联的数据库
Definition: session.cpp:51
SessionEvent * current_request() const
获取当前正在处理的请求
Definition: session.cpp:99
void set_trx_multi_operation_mode(bool multi_operation_mode)
设置当前事务为多语句模式,需要明确的指出提交或回滚
Definition: session.cpp:64
事务接口
Definition: trx.h:142