2016-10-25 13:49:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
#include <mutex>
|
2016-10-25 13:49:07 +00:00
|
|
|
#include <DB/Databases/IDatabase.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
#include <DB/Storages/IStorage.h>
|
2016-10-25 13:49:07 +00:00
|
|
|
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
namespace Poco { class Logger; }
|
|
|
|
|
|
|
|
|
2016-10-25 13:49:07 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** A non-persistent database to store temporary data.
|
|
|
|
* It doesn't make any manipulations with filesystem.
|
|
|
|
* All tables are created by calling code.
|
|
|
|
* TODO: Maybe DatabaseRuntime is more suitable class name.
|
|
|
|
*/
|
|
|
|
class DatabaseMemory : public IDatabase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
const String name;
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
Tables tables;
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
Poco::Logger * log;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DatabaseMemory(const String & name_) : name(name_) {}
|
|
|
|
|
|
|
|
String getEngineName() const override { return "Memory"; }
|
|
|
|
|
|
|
|
void loadTables(Context & context, ThreadPool * thread_pool, bool has_force_restore_data_flag) override;
|
|
|
|
|
|
|
|
bool isTableExist(const String & table_name) const override;
|
|
|
|
StoragePtr tryGetTable(const String & table_name) override;
|
|
|
|
|
|
|
|
DatabaseIteratorPtr getIterator() override;
|
|
|
|
|
|
|
|
bool empty() const override;
|
|
|
|
|
2017-01-23 18:05:07 +00:00
|
|
|
void createTable(
|
|
|
|
const String & table_name, const StoragePtr & table, const ASTPtr & query, const String & engine, const Settings & settings) override;
|
|
|
|
|
2016-10-25 13:49:07 +00:00
|
|
|
void removeTable(const String & table_name) override;
|
|
|
|
|
|
|
|
void attachTable(const String & table_name, const StoragePtr & table) override;
|
|
|
|
StoragePtr detachTable(const String & table_name) override;
|
|
|
|
|
2017-01-23 18:05:07 +00:00
|
|
|
void renameTable(
|
|
|
|
const Context & context, const String & table_name, IDatabase & to_database, const String & to_table_name, const Settings & settings) override;
|
2016-10-25 13:49:07 +00:00
|
|
|
|
|
|
|
time_t getTableMetadataModificationTime(const String & table_name) override;
|
|
|
|
|
|
|
|
ASTPtr getCreateQuery(const String & table_name) const override;
|
|
|
|
|
|
|
|
void shutdown() override;
|
|
|
|
void drop() override;
|
|
|
|
|
|
|
|
void alterTable(
|
|
|
|
const Context & context,
|
|
|
|
const String & name,
|
|
|
|
const NamesAndTypesList & columns,
|
|
|
|
const NamesAndTypesList & materialized_columns,
|
|
|
|
const NamesAndTypesList & alias_columns,
|
|
|
|
const ColumnDefaults & column_defaults,
|
|
|
|
const ASTModifier & engine_modifier) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|