public void ShouldCreateAndDeleteDatabase() { string databaseName = "thisIsTestDatabaseForNetDriver"; OServer server = TestConnection.GetServer(); bool exists = server.DatabaseExist(databaseName, OStorageType.PLocal); if (exists) { server.DropDatabase(databaseName, OStorageType.PLocal); exists = server.DatabaseExist(databaseName, OStorageType.PLocal); } Assert.AreEqual(exists, false); if (!exists) { bool isCreated = server.CreateDatabase(databaseName, ODatabaseType.Graph, OStorageType.PLocal); Assert.AreEqual(isCreated, true); if (isCreated) { server.DropDatabase(databaseName, OStorageType.PLocal); exists = server.DatabaseExist(databaseName, OStorageType.PLocal); Assert.AreEqual(exists, false); } } }
private static void ConnectionPoolTest() { OServer server = new OServer(Configuration["ConnectionStrings:DefaultConnection:Server"], int.Parse(Configuration["ConnectionStrings:DefaultConnection:Port"]), Configuration["ConnectionStrings:DefaultConnection:Username"], Configuration["ConnectionStrings:DefaultConnection:Password"]); if (server.DatabaseExist(Configuration["ConnectionStrings:DefaultConnection:DefaultDB"], OStorageType.PLocal)) { server.DropDatabase(Configuration["ConnectionStrings:DefaultConnection:DefaultDB"], OStorageType.PLocal); } server.CreateDatabase(Configuration["ConnectionStrings:DefaultConnection:DefaultDB"], ODatabaseType.Graph, OStorageType.PLocal); using (ODatabase database = new ODatabase(Configuration["ConnectionStrings:DefaultConnection:Server"], int.Parse(Configuration["ConnectionStrings:DefaultConnection:Port"]), Configuration["ConnectionStrings:DefaultConnection:DefaultDB"], ODatabaseType.Graph, Configuration["ConnectionStrings:DefaultConnection:Username"], Configuration["ConnectionStrings:DefaultConnection:Password"])) { database.Create.Class("Person").Run(); database.Insert().Into("Person").Set("Name", $"John").Set("LastName", $"Doe").Set("Age", 99).Run(); Parallel.For(0, 1000000, (i) => { ODocument document = database.Insert().Into("Person").Set("Name", $"John{i}").Set("LastName", $"Doe{i}").Set("Age", i).Run(); //System.Console.WriteLine(document.ORID); }); } }
public static void DropTestDatabase() { if (_server.DatabaseExist(GlobalTestDatabaseName, OStorageType.PLocal)) { _server.DropDatabase(GlobalTestDatabaseName, OStorageType.PLocal); } }
public static void DropTestDatabase() { if (_server.DatabaseExist(GlobalTestDatabaseName)) { _server.DropDatabase(GlobalTestDatabaseName); } }
public static void DropTestDatabase() { var retry = 2; do { try { if (_server.DatabaseExist(GlobalTestDatabaseName, GlobalTestDatabaseStorageType)) { _server.DropDatabase(GlobalTestDatabaseName, GlobalTestDatabaseStorageType); } break; } catch { _server.Dispose(); _server = new OServer(_hostname, _port, _rootUserName, _rootUserParssword); } Thread.Sleep(100); }while (--retry > 0); if (_server.DatabaseExist(GlobalTestDatabaseName, GlobalTestDatabaseStorageType)) { Assert.True(false, "Cannot drop test database."); } }
public void DropTestDatabase() { if (_server.DatabaseExist(GLOBAL_TEST_DATABASE_NAME, OStorageType.Memory)) { _server.DropDatabase(GLOBAL_TEST_DATABASE_NAME, OStorageType.Memory); } }
private bool CreateDatabaseIfNotExists(string hostname, int port, string user, string password, string database) { using (var server = new OServer(hostname, port, user, password)) { if (!server.DatabaseExist(database, OStorageType.PLocal)) { var created = server.CreateDatabase(database, ODatabaseType.Graph, OStorageType.PLocal); using (var db = new ODatabase("localhost", 2424, "txgraph", ODatabaseType.Graph, "admin", "admin")) { db.Command("CREATE CLASS Transaction EXTENDS V"); db.Command("CREATE PROPERTY Transaction.Hash STRING"); db.Command("CREATE INDEX IndexForHash ON Transaction (Hash) UNIQUE_HASH_INDEX"); db.Command("CREATE PROPERTY Transaction.BlockTime DATETIME"); db.Command("CREATE PROPERTY Transaction.Coinbase BOOLEAN"); db.Command("ALTER PROPERTY Transaction.Coinbase DEFAULT False"); db.Command("CREATE PROPERTY Transaction.Unlinked BOOLEAN"); db.Command("ALTER PROPERTY Transaction.Unlinked DEFAULT True"); db.Command("CREATE CLASS Link EXTENDS E"); db.Command("CREATE PROPERTY Link.sTx STRING"); db.Command("CREATE PROPERTY Link.sN LONG"); db.Command("CREATE PROPERTY Link.tTx STRING"); db.Command("CREATE PROPERTY Link.tAddr STRING"); db.Command("CREATE PROPERTY Link.amount LONG"); } return(created); } else { return(true); } } }
public void DropTestDatabase() { var retry = 2; do { try { if (_server.DatabaseExist(GlobalTestDatabaseName, GlobalTestDatabaseStorageType)) { _server.DropDatabase(GlobalTestDatabaseName, GlobalTestDatabaseStorageType); } break; } catch { _server.Dispose(); _server = new OServer(_hostname, port, _rootUserName, _rootUserParssword); } }while (--retry > 0); }
static void Main(string[] args) { _server = new OServer(_hostname, _port, _rootUserName, _rootUserPassword); //If the DB already exists I delete it if (_server.DatabaseExist(_DBname, OStorageType.PLocal)) { _server.DropDatabase("TestDatabaseName", OStorageType.PLocal); Console.WriteLine("Database " + _DBname + " deleted"); } //Creating the new DB _server.CreateDatabase(_DBname, ODatabaseType.Graph, OStorageType.PLocal); Console.WriteLine("Database " + _DBname + " created"); //Connect to the DB and populate it OClient.CreateDatabasePool( "127.0.0.1", 2424, _DBname, ODatabaseType.Graph, _username, _password, 10, "myTestDatabaseAlias" ); Console.WriteLine("Connected to the DB " + _DBname); using (ODatabase database = new ODatabase("myTestDatabaseAlias")) { database .Create.Class("TestClass") .Extends <OVertex>() .Run(); OVertex createdVertex = database .Create.Vertex("TestClass") .Set("name", "LucaS") .Run(); Console.WriteLine("Created vertex with @rid " + createdVertex.ORID); } }
static void Main(string[] args) { _server = new OServer(_hostname, _port, _rootUserName, _rootUserPassword); if (!_server.DatabaseExist(_DBname, OStorageType.PLocal)) { _server.CreateDatabase(_DBname, ODatabaseType.Graph, OStorageType.PLocal); Console.WriteLine("Database " + _DBname + " created"); //Connect to the DB OClient.CreateDatabasePool( _hostname, _port, _DBname, ODatabaseType.Graph, _username, _password, 10, _aliasDB ); Console.WriteLine("Connected to the DB " + _DBname); using (ODatabase database = new ODatabase(_aliasDB)) { //Classes and properties creation database .Create .Class("Users") .Extends <OVertex>() .Run(); database .Create .Property("userID", OType.Integer) .Class("users") .Run(); //Populate the DB OVertex vertexUser = new OVertex(); vertexUser.OClassName = "Users"; vertexUser .SetField("userID", 1); OVertex createVertexUser = database .Create.Vertex(vertexUser) .Run(); Console.WriteLine("Created vertex " + createVertexUser.OClassName + " with @rid " + createVertexUser.ORID + " and userID " + createVertexUser.GetField <int>("userID")); } } else { //Connection OClient.CreateDatabasePool( _hostname, _port, _DBname, ODatabaseType.Graph, _username, _password, 10, _aliasDB ); Console.WriteLine("Connected to the DB " + _DBname); using (ODatabase database = new ODatabase(_aliasDB)) { database .Update() .Class("Users") .Set("userID", 2) .Upsert() .Where("userID") .Equals(2) .Run(); Console.WriteLine("Operation executed"); } } }
static void CreateDatabaseTestManualy() { var serverConnInfo = Configuration.GetSection("ConnectionStrings:DefaultConnection").GetChildren().ToDictionary(x => x.Key); using (var server = new OServer(serverConnInfo["Server"].Value, int.Parse(serverConnInfo["Port"].Value), serverConnInfo["Username"].Value, serverConnInfo["Password"].Value)) { var created = false; try { var exists = server.DatabaseExist("TestManualy", OStorageType.PLocal); if (exists) { server.DropDatabase("TestManualy", OStorageType.PLocal); } created = server.CreateDatabase("TestManualy", ODatabaseType.Document, OStorageType.PLocal); if (!created) { throw new Exception("Database not created"); } exists = server.DatabaseExist("TestManualy", OStorageType.PLocal); if (!exists) { throw new Exception("Database not exists"); } System.Console.WriteLine("Database created - get server configuration"); var config = server.ConfigList(); foreach (var item in config) { System.Console.WriteLine("{0} : {1}", item.Key, item.Value); } System.Console.WriteLine("try connect to the database and query"); OClient.CreateDatabasePool( serverConnInfo["Server"].Value, int.Parse(serverConnInfo["Port"].Value), "TestManualy", ODatabaseType.Graph, serverConnInfo["Username"].Value, serverConnInfo["Password"].Value, 10, "AppConnection" ); using (var database = new ODatabase("AppConnection")) { var documents = database.Query("select from OUser"); foreach (var item in documents) { System.Console.WriteLine("Name: {0} Status: {1}", item.GetField <string>("name"), item.GetField <string>("status")); } } OClient.DropDatabasePool("AppConnection"); } finally { if (created) { server.DropDatabase("TestManualy", OStorageType.PLocal); } } } }
static void CreateDatabaseTestManualy() { using (var server = new OServer("127.0.0.1", 2424, "root", "root")) { var created = false; try { created = server.CreateDatabase("TestManualy", ODatabaseType.Document, OStorageType.PLocal); if (!created) { throw new Exception("Database not created"); } var exists = server.DatabaseExist("TestManualy", OStorageType.PLocal); if (!exists) { throw new Exception("Database not exists"); } System.Console.WriteLine("Database created - get server configuration"); var config = server.ConfigList(); foreach (var item in config) { System.Console.WriteLine("{0} : {1}", item.Key, item.Value); } System.Console.WriteLine("try connect to the database and query"); OClient.CreateDatabasePool( "localhost", 2424, "TestManualy", ODatabaseType.Graph, "root", "root", 10, "AppConnection" ); using (var database = new ODatabase("AppConnection")) { var documents = database.Query("select from OUser"); foreach (var item in documents) { System.Console.WriteLine("Name: {0} Status: {1}", item.GetField <string>("name"), item.GetField <string>("status")); } } OClient.DropDatabasePool("AppConnection"); } finally { if (created) { server.DropDatabase("TestManualy", OStorageType.PLocal); } } } }