/// <exception cref="System.Exception"></exception> public virtual void TestConcurrentObjectVersion() { // LogUtil.allOn(true); int port = Port + 8; NeoDatis.Tool.IOUtil.DeleteFile(Directory + "exta1"); NeoDatis.Odb.ODBServer server = NeoDatis.Odb.ODBFactory.OpenServer(port); server.StartServer(true); NeoDatis.Odb.ODB odb = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); NeoDatis.Odb.OID oid = odb.Store(new NeoDatis.Odb.Test.VO.Login.Function("f1")); int version = odb.Ext().GetObjectVersion(oid); Println(version); odb.Close(); NeoDatis.Odb.ODB odb1 = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); NeoDatis.Odb.ODB odb2 = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); int v1 = odb1.Ext().GetObjectVersion(oid); int v2 = odb2.Ext().GetObjectVersion(oid); AssertEquals(1, v1); AssertEquals(1, v2); Println("v1=" + v1 + "- v2=" + v2); NeoDatis.Odb.Test.VO.Login.Function f1 = (NeoDatis.Odb.Test.VO.Login.Function)odb1 .GetObjectFromId(oid); NeoDatis.Odb.Test.VO.Login.Function f2 = (NeoDatis.Odb.Test.VO.Login.Function)odb2 .GetObjectFromId(oid); f1.SetName("function 1"); odb1.Store(f1); v1 = odb1.Ext().GetObjectVersion(oid); Println("after update odb1 , v1=" + v1); odb1.Close(); NeoDatis.Odb.ODB odb3 = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); // Check committed object value NeoDatis.Odb.Test.VO.Login.Function f3 = (NeoDatis.Odb.Test.VO.Login.Function)odb3 .GetObjectFromId(oid); AssertEquals(f1.GetName(), f3.GetName()); AssertEquals(2, odb3.Ext().GetObjectVersion(oid)); odb3.Close(); AssertEquals(2, v1); f2.SetName("function 2"); odb2.Store(f2); v2 = odb2.Ext().GetObjectVersion(oid); Println("after update odb2 , v2=" + v2); odb2.Close(); AssertEquals(3, v2); NeoDatis.Odb.ODB odb4 = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); // Check committed object value NeoDatis.Odb.Test.VO.Login.Function f4 = (NeoDatis.Odb.Test.VO.Login.Function)odb4 .GetObjectFromId(oid); AssertEquals(f2.GetName(), f4.GetName()); AssertEquals(3, odb4.Ext().GetObjectVersion(oid)); odb4.Close(); server.Close(); }
/// <exception cref="System.Exception"></exception> public virtual void TestConcurrentObjectVersion2() { // LogUtil.allOn(true); int port = Port + 8; NeoDatis.Tool.IOUtil.DeleteFile(Directory + "exta1"); NeoDatis.Odb.ODBServer server = NeoDatis.Odb.ODBFactory.OpenServer(port); server.StartServer(true); NeoDatis.Odb.ODB odb = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); NeoDatis.Odb.OID oid = odb.Store(new NeoDatis.Odb.Test.VO.Login.Function("f1")); int version = odb.Ext().GetObjectVersion(oid); Println(version); odb.Close(); int nbThreads = 100; NeoDatis.Odb.ODB[] odbs = new NeoDatis.Odb.ODB[nbThreads]; int[] versions = new int[nbThreads]; NeoDatis.Odb.Test.VO.Login.Function[] functions = new NeoDatis.Odb.Test.VO.Login.Function [nbThreads]; // Open all Odbs and get the object for (int i = 0; i < nbThreads; i++) { odbs[i] = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1" ); versions[i] = odbs[i].Ext().GetObjectVersion(oid); functions[i] = (NeoDatis.Odb.Test.VO.Login.Function)odbs[i].GetObjectFromId(oid); AssertEquals(1, versions[i]); AssertEquals("f1", functions[i].GetName()); } // Open all Odbs and get the object for (int i = 0; i < nbThreads; i++) { functions[i].SetName("function " + i); odbs[i].Store(functions[i]); versions[i] = odbs[i].Ext().GetObjectVersion(oid); Println("Function with name " + functions[i].GetName() + " has version " + versions [i]); odbs[i].Close(); AssertEquals(i + 2, versions[i]); // Just to check the version number after commit odb = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); int committedVersionNumber = odb.Ext().GetObjectVersion(oid); Println("After commit = " + committedVersionNumber); AssertEquals(i + 2, committedVersionNumber); odb.Close(); } NeoDatis.Odb.ODB odb4 = NeoDatis.Odb.ODBFactory.OpenClient("localhost", port, Directory + "exta1"); // Check committed object value NeoDatis.Odb.Test.VO.Login.Function f4 = (NeoDatis.Odb.Test.VO.Login.Function)odb4 .GetObjectFromId(oid); AssertEquals("function " + (nbThreads - 1), f4.GetName()); AssertEquals(nbThreads + 1, odb4.Ext().GetObjectVersion(oid)); odb4.Close(); server.Close(); }
public virtual void Test2_ClientServer() { string baseName = GetBaseName(); Println(baseName); string currentEncoding = NeoDatis.Odb.OdbConfiguration.GetDatabaseCharacterEncoding (); NeoDatis.Odb.OdbConfiguration.SetDatabaseCharacterEncoding("ISO8859-5"); NeoDatis.Odb.ODBServer server = null; try { server = NeoDatis.Odb.ODBFactory.OpenServer(NeoDatis.Odb.Test.ODBTest.PORT + 1); server.AddBase(baseName, baseName); server.StartServer(true); Thread.Sleep(200); NeoDatis.Odb.ODB odb = NeoDatis.Odb.ODBFactory.OpenClient("localhost", NeoDatis.Odb.Test.ODBTest .PORT + 1, baseName); string nameWithCyrillicCharacters = "\u0410 \u0430 \u0431 \u0448 \u0429"; NeoDatis.Odb.Test.VO.Login.Function f = new NeoDatis.Odb.Test.VO.Login.Function(nameWithCyrillicCharacters ); NeoDatis.Odb.OID oid = odb.Store(f); odb.Close(); Println(f); odb = NeoDatis.Odb.ODBFactory.OpenClient("localhost", NeoDatis.Odb.Test.ODBTest.PORT + 1, baseName); NeoDatis.Odb.Test.VO.Login.Function f2 = (NeoDatis.Odb.Test.VO.Login.Function)odb .GetObjectFromId(oid); odb.Close(); AssertEquals(nameWithCyrillicCharacters, f2.GetName()); AssertEquals('\u0410', f2.GetName()[0]); AssertEquals('\u0430', f2.GetName()[2]); AssertEquals('\u0431', f2.GetName()[4]); AssertEquals('\u0448', f2.GetName()[6]); AssertEquals('\u0429', f2.GetName()[8]); } finally { NeoDatis.Odb.OdbConfiguration.SetDatabaseCharacterEncoding(currentEncoding); if (server != null) { server.Close(); } } }
/// <exception cref="System.Exception"></exception> public virtual void Step20() { // Create instance NeoDatis.Odb.Test.Tutorial.Sport sport = new NeoDatis.Odb.Test.Tutorial.Sport("volley-ball" ); NeoDatis.Odb.ODB odb = null; NeoDatis.Odb.ODBServer server = null; try { // Creates the server on port 8000 server = OpenServer(8000); // Tells the server to manage base 'base1' that points to the file // tutorial2.odb server.AddBase("base1", OdbName); // Then starts the server to run in background server.StartServer(true); // Open the databse client on the localhost on port 8000 and specify // which database instance odb = OpenClient("localhost", 8000, "base1"); // Store the object odb.Store(sport); } finally { if (odb != null) { // First close the client odb.Close(); } if (server != null) { // Then close the database server server.Close(); } } }
public virtual void Close() { serverImpl.Close(); }