public static Database GetOrCreateEmptyDatabase(Client client, string dbName) { Database db = null; try { db = client.GetDatabase(dbName); } catch (SDBPException e) { if (e.Status == Status.SDBP_BADSCHEMA) { db = client.CreateDatabase(dbName); return(db); } } if (db == null) { return(null); } foreach (Table table in db.GetTables()) { table.DeleteTable(); } return(db); }
public static Database TryCreateDatabase(Client client, string databaseName) { try { var database = client.CreateDatabase(databaseName); return(database); } catch (SDBPException) { return(null); } }
public static Table GetOrCreateTableAndDatabase(Client client, string dbName, string tableName) { Database db = null; try { db = client.GetDatabase(dbName); } catch (SDBPException e) { if (e.Status == Status.SDBP_BADSCHEMA) { db = client.CreateDatabase(dbName); } } if (db == null) { return(null); } Table table = null; try { table = db.GetTable(tableName); } catch (SDBPException e) { if (e.Status == Status.SDBP_BADSCHEMA) { table = db.CreateTable(tableName); } } if (table == null) { table = db.CreateTable(tableName); } return(table); }
public static Database TryCreateDatabase(Client client, string databaseName) { try { var database = client.CreateDatabase(databaseName); return database; } catch (SDBPException) { return null; } }
public static void FillDatabaseWithNumericKeys(string databaseName, string tableName) { var client = new Client(Utils.GetConfigNodes()); Assert.IsTrue(ConfigStateHelpers.TryDeleteDatabase(client, databaseName)); var database = client.CreateDatabase(databaseName); Assert.IsNotNull(database, "Cannot create database " + databaseName); var table = ConfigStateHelpers.TryCreateTable(database, tableName); Assert.IsNotNull(table, "Cannot create table " + tableName); System.Console.WriteLine("Filling the database..."); DateTime last = DateTime.Now; for (ulong i = 0; i < 100 * 1000 * 1000; i++) { var key = Utils.Id(i); table.Set(key, key); TimeSpan timeSpan = DateTime.Now - last; if (timeSpan.TotalSeconds >= 60) { System.Console.WriteLine("i: " + i); last = DateTime.Now; } } client.Submit(); System.Console.WriteLine("Database filling is done."); }