SwatDB
Loading...
Searching...
No Matches
filemgr.h
Go to the documentation of this file.
1/*
2 * SwatDB
3 *
4 * @authors: See Contributors.doc for code contributors
5 *
6 * Copyright (c) 2020 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10#ifndef _SWATDB_FILEMGR_H_
11#define _SWATDB_FILEMGR_H_
12
17#include <string>
18#include <vector>
19#include "swatdb_types.h"
20
21// too many circular includes, just define these types like
22// this and include the .h file for them in the .cpp files:
23class BufferManager;
24class Catalog;
25class Schema;
26class File;
27
33
34 public:
35
56 bool load = false); // default value paramater
57
65
97 FileId createRelation(std::string name, Schema *schema, CatType type,
98 std::string file_name, bool save_on_exit = true);
99
132 FileId createIndex(std::string name, std::vector<std::string> field_list,
133 std::string index_file_name, FileId rel_fid,
134 bool save_on_exit = false);
147 void removeRelation(std::string name);
148
162 void removeFile(FileId file_id);
163
175 File* getRelation(std::string name);
176
188 File* getFile(FileId file_id);
189
190
203 void printFile(FileId file_id, std::uint64_t max_to_print = 50);
204
215 std::uint64_t getNumRecords(FileId file_id);
216
217
221 void fileToText(FileId file_id, std::string file_name);
222
223 protected:
224
236
251
252 friend class SwatDB;
253
254 private:
255
269
310 void _loadFile(FileId fid);
311
316
321
322};
323
324#endif
Definition bufmgr.h:121
Definition catalog.h:161
Definition filemgr.h:32
BufferManager * buf_mgr
Definition filemgr.h:320
void _saveOrRemoveFiles()
Flushes and closes all underlying files in the system, saving db state.
void _loadAllFiles()
Loads all Files listed in the Catalog.
FileId createRelation(std::string name, Schema *schema, CatType type, std::string file_name, bool save_on_exit=true)
Creates a new Relation in the system. Adds an entry for the new file to the Catalog and creates the u...
void removeFile(FileId file_id)
Deletes a File or Index from the system and removes its underlying storage from the database.
void removeRelation(std::string name)
Deletes relation from the system and removes its underlying storage from the database.
void _removeAllFiles()
Removes all Files in the system and their underlying storage from the database.
File * getRelation(std::string name)
Retuns File object identified by the relation name.
File * getFile(FileId file_id)
Retuns File object identified by the given FileId.
void fileToText(FileId file_id, std::string file_name)
saves contents of a file to a text file.
void printFile(FileId file_id, std::uint64_t max_to_print=50)
prints a file's contents to stdout (default, only prints up to the first 50 records)
void _loadFile(FileId fid)
Loads an existing relation into the system, whose contents are already stored in a file on disk.
~FileManager()
Destructor.
FileId createIndex(std::string name, std::vector< std::string > field_list, std::string index_file_name, FileId rel_fid, bool save_on_exit=false)
Creates a new Index in the system. Adds an entry for the new file to the Catalog and creates the unde...
std::uint64_t getNumRecords(FileId file_id)
returns the number of records in a relation file
Catalog * catalog
Definition filemgr.h:315
FileManager(Catalog *cat, BufferManager *buf_mgr, bool load=false)
Creates SwatDB FileManager, the interface to the File layer.
Definition file.h:45
Definition schema.h:37
Definition swatdb.h:48
std::uint32_t FileId
Definition swatdb_types.h:33
CatType
Definition swatdb_types.h:145