/// <summary> /// Adds the database to the Frost system Db directory file /// </summary> /// <param name="database">The database object</param> /// <param name="isOnline">True if the database is online, otherwise false</param> public void AddDatabaseToDirectory(Database2 database, bool isOnline) { // databaseName <bool> isOnline lock (_fileLock) { using (var sw = File.AppendText(_fileName)) { sw.WriteLine($"{database.Name},{isOnline.ToString()}"); } } }
public void AddDatabase2(Database2 database) { if (database != null) { if (!HasDatabase2(database.Name)) { _databases2.Add(database); _storageManager.AddNewDatabase(database); } } else { throw new ArgumentNullException(nameof(database)); } }
public int GetMaxDatabaseId() { int result = 0; Database2 db = Databases2.MaxBy(d => d.DatabaseId).FirstOrDefault(); if (db is null) { result = 0; } else { result = db.DatabaseId; } return(result); }
/// <summary> /// Returns all rows for the specified table (via tree address) /// </summary> /// <param name="treeAddress">The tree's address (dbId, tableId)</param> /// <returns>All rows for the table</returns> public List <RowStruct> GetAllRows(BTreeAddress treeAddress) { var result = new List <RowStruct>(); Database2 database = _process.GetDatabase2(treeAddress.DatabaseId); TableSchema2 schema = database.GetTable(treeAddress.TableId).Schema; if (CacheHasContainer(treeAddress)) { result.AddRange(GetContainerFromCache(treeAddress).GetAllRows(schema, false)); } else { AddContainerToCache(treeAddress); result.AddRange(GetContainerFromCache(treeAddress).GetAllRows(schema, false)); } return(result); }
/// <summary> /// Gets a list of databases from disk /// </summary> /// <returns>A list of databases</returns> public Database2[] GetDatabases() { var databases = GetOnlineDatabases(); Database2[] result = new Database2[databases.Length]; int i = 0; foreach (var db in databases) { var storage = new DbStorage(_process, db); var dbItem = storage.GetDatabase(db); storage.Initialize(); result[i] = dbItem; i++; } return(result); }
/// <summary> /// Tries to load a container from disk file. If this is a fresh database, will return a new container. /// </summary> /// <param name="address">The address of the container to get</param> /// <returns>A container from disk</returns> private BTreeContainer GetContainerFromDisk(BTreeAddress address) { Database2 db = _process.GetDatabase2(address.DatabaseId); DbStorage storage = db.Storage; var tree = new TreeDictionary <int, Page>(); TableSchema2 schema = db.GetTable(address.TableId).Schema; // get the first page Page page = storage.GetPage(1, address); // if this is a brand new table if (page == null) { page = new Page(1, address.TableId, address.DatabaseId, schema, _process); } tree.Add(page.Id, page); return(new BTreeContainer(address, tree, storage, schema, _process)); }
/// <summary> /// Creates the appropriate disk files for a new database hosted by this Frost process /// </summary> /// <param name="database"></param> public void AddNewDatabase(Database2 database) { database.Storage.CreateFiles(database.DatabaseId); _directory.AddDatabaseToDirectory(database, true); }