Ejemplo n.º 1
0
        /// <exception cref="System.Exception"></exception>
        public virtual void TestInsertSimpleObjectODB()
        {
            bool inMemory = true;

            // Deletes the database file
            NeoDatis.Tool.IOUtil.DeleteFile(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;

            NeoDatis.Odb.ODB                odb = null;
            NeoDatis.Odb.Objects            l   = null;
            NeoDatis.Odb.Test.VO.Login.User so  = null;
            // Insert TEST_SIZE objects
            System.Console.Out.WriteLine("Inserting " + TestSize + " objects");
            t1  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName);
            odb.GetClassRepresentation(typeof(NeoDatis.Odb.Test.VO.Login.User)).AddFullInstantiationHelper
                (new NeoDatis.Odb.Test.Performance.UserFullInstantiationHelper());
            for (int i = 0; i < TestSize; i++)
            {
                object o = GetUserInstance(i);
                odb.Store(o);
            }
            t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // Closes the database
            odb.Close();
            t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            System.Console.Out.WriteLine("Retrieving " + TestSize + " objects");
            // Reopen the database
            odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName);
            // Gets retrieve the TEST_SIZE objects
            l  = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.User), inMemory);
            t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // Actually get objects
            while (l.HasNext())
            {
                object o = l.Next();
            }
            t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            System.Console.Out.WriteLine("Updating " + TestSize + " objects");
            so = null;
            l.Reset();
            // Actually get objects
            while (l.HasNext())
            {
                so = (NeoDatis.Odb.Test.VO.Login.User)l.Next();
                // so.setName(so.getName() + " updated");
                // so.setName(so.getName() + " updated-updated-updated-updated");
                so.GetProfile().SetName(so.GetName() + " updated-updated-updated");
                odb.Store(so);
            }
            t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb.Close();
            t7 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            System.Console.Out.WriteLine("Deleting " + TestSize + " objects");
            odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName);
            l   = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.User), inMemory);
            t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // Actually get objects
            while (l.HasNext())
            {
                so = (NeoDatis.Odb.Test.VO.Login.User)l.Next();
                odb.Delete(so);
            }
            odb.Close();
            t8  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = NeoDatis.Odb.ODBFactory.Open(OdbFileName);
            odb.Close();
            DisplayResult("ODB " + TestSize + " User objects ", t1, t2, t3, t4, t5, t6, t7, t77
                          , t8);
        }
Ejemplo n.º 2
0
        public virtual void Test14()
        {
            if (!isLocal)
            {
                return;
            }
            string baseName = GetBaseName();

            NeoDatis.Odb.ODB odb = null;
            odb = Open(baseName);
            Function f1 = new Function(
                "function1");
            Function f2 = new Function(
                "function2");
            Function f3 = new Function(
                "function3");
            Function f4 = new Function(
                "function4");
            Function f5 = new Function(
                "function5");

            odb.Store(f1);
            odb.Store(f2);
            odb.Store(f3);
            odb.Store(f4);
            odb.Store(f5);
            AssertEquals(5, odb.Count(new CriteriaQuery
                                          (typeof(Function))));
            odb.Close();
            try
            {
                odb = Open(baseName);
                Function f6 = new Function(
                    "function6");
                Function f7 = new Function(
                    "function7");
                odb.Store(f6);
                odb.Store(f7);
                AssertEquals(7, odb.Count(new CriteriaQuery
                                              (typeof(Function))));
                NeoDatis.Odb.Objects <Function> objects = odb.GetObjects <Function>();
                int i = 0;
                while (objects.HasNext() && i < 4)
                {
                    odb.Delete(objects.Next());
                    i++;
                }
                AssertEquals(3, odb.Count(new CriteriaQuery
                                              (typeof(Function))));
                odb.Close();
                odb = Open(baseName);
                AssertEquals(3, odb.Count(new CriteriaQuery
                                              (typeof(Function))));
                objects = odb.GetObjects <Function>();
                // println(objects);
                AssertEquals("function5", ((Function)objects.Next()).GetName
                                 ());
                AssertEquals("function6", ((Function)objects.Next()).GetName
                                 ());
                AssertEquals("function7", ((Function)objects.Next()).GetName
                                 ());
                odb.Close();
            }
            catch (NeoDatis.Odb.ODBRuntimeException e)
            {
                DeleteBase(baseName);
                throw;
            }
            DeleteBase(baseName);
        }
Ejemplo n.º 3
0
        public virtual void Test1WithCommit2()
        {
            if (!runAll)
            {
                return;
            }
            NeoDatis.Tool.StopWatch stopWatch = new NeoDatis.Tool.StopWatch();
            stopWatch.Start();
            int size        = 2;
            int size2       = 1;
            int nbFunctions = 1;

            DeleteBase(FileName);
            NeoDatis.Odb.ODB odb = Open(FileName);
            Function         f1  = new Function(
                "function 1");

            Println(odb.Count(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery(typeof(
                                                                                          User))));
            // Create Objects
            for (int i = 0; i < size; i++)
            {
                NeoDatis.Odb.Test.VO.Login.Profile p = new NeoDatis.Odb.Test.VO.Login.Profile("profile number "
                                                                                              + i, f1);
                for (int j = 0; j < nbFunctions; j++)
                {
                    p.AddFunction(new Function(" inner function of profile : number "
                                               + i + " - " + j));
                }
                User user = new User("user name "
                                     + i, "user email " + i, p);
                odb.Store(user);
                if (i % 100 == 0)
                {
                    Println("insert " + i);
                }
            }
            odb.Close();
            Println("created");
            // Updates 10 times the objects
            odb = Open(FileName);
            NeoDatis.Odb.Objects <User> objects = odb.GetObjects <User>();
            Println("got the object " + objects.Count);
            for (int k = 0; k < 3; k++)
            {
                objects.Reset();
                long start = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
                for (int i = 0; i < size; i++)
                {
                    User user = (User)objects.Next
                                    ();
                    user.GetProfile().SetName(user.GetProfile().GetName() + "-updated");
                    odb.Store(user);
                    if (i % 100 == 0)
                    {
                        Println("update " + i + " - " + k);
                    }
                }
                Println("Update " + k + " - " + (NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs
                                                     () - start) + " ms");
            }
            Println("updated");
            Println("deleted");
            odb.Close();
            // Check object count
            odb     = Open(FileName);
            objects = odb.GetObjects <User>();
            AssertEquals(objects.Count, size);
            // Check data of the objects
            int a = 0;

            while (objects.HasNext())
            {
                User user = (User)objects.Next
                                ();
                AssertEquals("user name " + a, user.GetName());
                AssertEquals("user email " + a, user.GetEmail());
                AssertEquals("profile number " + a + "-updated-updated-updated", user.GetProfile(
                                 ).GetName());
                a++;
            }
            Println("checked");
            for (int k = 0; k < 10; k++)
            {
                objects.Reset();
                for (int i = 0; i < size2; i++)
                {
                    User user = (User)objects.Next
                                    ();
                    user.GetProfile().SetName(user.GetProfile().GetName() + "-updated" + "-");
                    odb.Store(user);
                }
            }
            Println("re-updated");
            odb.Close();
            // delete objects
            odb     = Open(FileName);
            objects = odb.GetObjects <User>();
            a       = 0;
            while (objects.HasNext())
            {
                odb.Delete(objects.Next());
                a++;
            }
            AssertEquals(size, a);
            odb.Close();
            odb = Open(FileName);
            AssertEquals(0, odb.GetObjects <User>().Count);
            AssertEquals(0, odb.Count(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                          (typeof(User))));
            Println("deleted");
            odb.Close();
            stopWatch.End();
            Println("Total time 1 = " + stopWatch.GetDurationInMiliseconds());
            if (stopWatch.GetDurationInMiliseconds() > 90700)
            {
                Fail("time is > than " + 90700 + " = " + stopWatch.GetDurationInMiliseconds());
            }
        }
Ejemplo n.º 4
0
        public virtual void TestDeleteListElements2()
        {
            string baseName = GetBaseName();

            NeoDatis.Odb.ODB odb     = Open(baseName);
            Catalog          catalog = new Catalog
                                           ("Fnac");
            ProductCategory books = new ProductCategory
                                        ("Books");

            books.GetProducts().Add(new Product
                                        ("Book1", new System.Decimal(10.1)));
            books.GetProducts().Add(new Product
                                        ("Book2", new System.Decimal(10.2)));
            books.GetProducts().Add(new Product
                                        ("Book3", new System.Decimal(10.3)));
            ProductCategory computers = new ProductCategory
                                            ("Computers");

            computers.GetProducts().Add(new Product
                                            ("MacBook", new System.Decimal(1300.1)));
            computers.GetProducts().Add(new Product
                                            ("BookBookPro", new System.Decimal(2000.2)));
            computers.GetProducts().Add(new Product
                                            ("MacMini", new System.Decimal(1000.3)));
            catalog.GetCategories().Add(books);
            catalog.GetCategories().Add(computers);
            odb.Store(catalog);
            odb.Close();
            odb = Open(baseName);
            NeoDatis.Odb.Objects <Catalog> objects = odb.GetObjects <Catalog>();
            Println(objects.Count + " catalog(s)");
            while (objects.HasNext())
            {
                Catalog c = (Catalog
                             )objects.Next();
                System.Collections.Generic.IList <NeoDatis.Odb.Test.VO.Arraycollectionmap.Catalog.ProductCategory> pCategories = c.GetCategories();
                Println(c.GetCategories().Count + " product categories");
                for (int j = 0; j < pCategories.Count; j++)
                {
                    ProductCategory pc = (ProductCategory
                                          )pCategories[j];
                    Println("\tProduct Category : " + pc.GetName() + " : " + pc.GetProducts().Count +
                            " products");
                    for (int k = 0; k < pc.GetProducts().Count; k++)
                    {
                        Product p = pc.GetProducts()[k];
                        Println("\t\tProduct " + p.GetName());
                        odb.Delete(p);
                    }
                    odb.Delete(pc);
                }
                odb.Delete(c);
            }
            odb.Close();
            odb = Open(baseName);
            NeoDatis.Odb.Objects <Catalog>         catalogs          = odb.GetObjects <Catalog>();
            NeoDatis.Odb.Objects <ProductCategory> productCategories = odb.GetObjects <ProductCategory>();
            NeoDatis.Odb.Objects <Product>         products          = odb.GetObjects <Product>();
            AssertTrue(catalogs.Count == 0);
            AssertTrue(productCategories.Count == 0);
            AssertTrue(products.Count == 0);
            DeleteBase(baseName);
        }
Ejemplo n.º 5
0
        /// <exception cref="System.Exception"></exception>
        public virtual void T1estInsertSimpleObjectODB(int size)
        {
            OdbFileName = "perf-" + size + ".neodatis";
            TestSize    = size;
            bool doUpdate       = true;
            bool doDelete       = true;
            int  commitInterval = 100;
            // Configuration.setUseLazyCache(true);
            bool inMemory = true;

            // Configuration.monitorMemory(true);
            // Configuration.setUseModifiedClass(true);
            // Deletes the database file
            DeleteBase(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;

            NeoDatis.Odb.ODB odb = null;
            NeoDatis.Odb.Objects <SimpleObject> l = null;
            SimpleObject so = null;

            // Insert TEST_SIZE objects
            Println("Inserting " + TestSize + " objects");
            t1  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            string[] fields = new string[] { "name" };
            odb.GetClassRepresentation(typeof(SimpleObject)).AddUniqueIndexOn
                ("index1", fields, true);
            for (int i = 0; i < TestSize; i++)
            {
                object o = GetSimpleObjectInstance(i);
                odb.Store(o);
                if (i % 10000 == 0)
                {
                    // println("i="+i);
                    NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory(string.Empty + i, false
                                                                              );
                }
            }
            // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString());
            t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // Closes the database
            odb.Close();
            // if(true)return;
            t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            Println("Retrieving " + TestSize + " objects");
            // Reopen the database
            odb = Open(OdbFileName);
            // Gets the TEST_SIZE objects
            t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            NeoDatis.Odb.Core.Query.IQuery q = null;
            for (int j = 0; j < TestSize; j++)
            {
                // println("Bonjour, comment allez vous?" + j);
                q = new CriteriaQuery(Where.Equal("name", "Bonjour, comment allez vous?" + j));
                NeoDatis.Odb.Objects <SimpleObject> objects = odb.GetObjects <SimpleObject>(q);
                AssertTrue(q.GetExecutionPlan().UseIndex());
                so = objects.GetFirst();
                if (!so.GetName().Equals("Bonjour, comment allez vous?" + j))
                {
                    throw new System.Exception("error while getting object : expected = " + "Bonjour, comment allez vous?"
                                               + j + " / actual = " + so.GetName());
                }
                if (j % 1000 == 0)
                {
                    Println("got " + j + " objects");
                }
            }
            t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb.Close();
            odb = Open(OdbFileName);
            if (doUpdate)
            {
                Println("Updating " + TestSize + " objects");
                so = null;
                l  = odb.GetObjects <SimpleObject>(inMemory);
                while (l.HasNext())
                {
                    so = (SimpleObject)l.Next();
                    so.SetName(so.GetName().ToUpper());
                    odb.Store(so);
                }
            }
            t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb.Close();
            // if(true)return;
            t7 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            if (doDelete)
            {
                Println("Deleting " + TestSize + " objects");
                odb = Open(OdbFileName);
                Println("After open - before delete");
                l   = odb.GetObjects <SimpleObject>(inMemory);
                t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
                Println("After getting objects - before delete");
                int i = 0;
                while (l.HasNext())
                {
                    so = (SimpleObject)l.Next();
                    if (!so.GetName().StartsWith("BONJOUR"))
                    {
                        throw new System.Exception("Update  not ok for " + so.GetName());
                    }
                    odb.Delete(so);
                    if (i % 10000 == 0)
                    {
                        Println("s=" + i);
                    }
                    // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString());
                    i++;
                }
                odb.Close();
            }
            t8 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // t4 2 times
            DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t4, t4, t5, t6
                          , t7, t77, t8);
        }
Ejemplo n.º 6
0
        public virtual void Test1WithoutCommit()
        {
            if (!runAll)
            {
                return;
            }
            NeoDatis.Tool.StopWatch stopWatch = new NeoDatis.Tool.StopWatch();
            stopWatch.Start();
            int size        = 10000;
            int size2       = 5000;
            int nbFunctions = 10;

            DeleteBase(FileName);
            NeoDatis.Odb.ODB odb = Open(FileName);
            Function         f1  = new Function(
                "function 1");

            // Create Objects
            for (int i = 0; i < size; i++)
            {
                NeoDatis.Odb.Test.VO.Login.Profile p = new NeoDatis.Odb.Test.VO.Login.Profile("profile number "
                                                                                              + i, f1);
                for (int j = 0; j < nbFunctions; j++)
                {
                    p.AddFunction(new Function(" inner function of profile : number "
                                               + i + " - " + j));
                }
                User user = new User("user name "
                                     + i, "user email " + i, p);
                odb.Store(user);
            }
            Println("created");
            // Updates 10 times the objects
            NeoDatis.Odb.Objects <User> objects = odb.GetObjects <User>();
            for (int k = 0; k < 10; k++)
            {
                objects.Reset();
                for (int i = 0; i < size2; i++)
                {
                    User user = (User)objects.Next
                                    ();
                    user.GetProfile().SetName(user.GetProfile().GetName() + "-updated");
                    odb.Store(user);
                }
            }
            Println("updated");
            // Delete the rest of the objects
            for (int i = size2; i < size; i++)
            {
                odb.Delete(objects.Next());
            }
            Println("deleted");
            // Check object count
            objects = odb.GetObjects <User>();
            AssertEquals(size2, objects.Count);
            // Check data of the objects
            int a = 0;

            while (objects.HasNext())
            {
                User user = (User)objects.Next
                                ();
                AssertEquals("user name " + a, user.GetName());
                AssertEquals("user email " + a, user.GetEmail());
                AssertEquals("profile number " + a + "-updated-updated-updated-updated-updated-updated-updated-updated-updated-updated"
                             , user.GetProfile().GetName());
                a++;
            }
            Println("checked");
            for (int k = 0; k < 10; k++)
            {
                objects.Reset();
                for (int i = 0; i < size2; i++)
                {
                    User user = (User)objects.Next
                                    ();
                    user.GetProfile().SetName(user.GetProfile().GetName() + "-updated" + "-");
                    odb.Store(user);
                }
            }
            Println("re-updated");
            objects = odb.GetObjects <User>();
            NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy
                                                                    .GetEngine(odb);
            NeoDatis.Odb.Core.Layers.Layer2.Meta.CIZoneInfo uncommited = engine.GetSession(true
                                                                                           ).GetMetaModel().GetClassInfo(typeof(User).FullName,
                                                                                                                         true).GetUncommittedZoneInfo();
            NeoDatis.Odb.Core.Layers.Layer2.Meta.CIZoneInfo commited = engine.GetSession(true
                                                                                         ).GetMetaModel().GetClassInfo(typeof(User).FullName,
                                                                                                                       true).GetCommitedZoneInfo();
            Println("Before commit : uncommited=" + uncommited);
            Println("Before commit : commited=" + commited);
            a = 0;
            while (objects.HasNext())
            {
                // println("a="+a);
                odb.Delete(objects.Next());
                a++;
            }
            AssertEquals(size2, a);
            AssertEquals(0, odb.GetObjects <User>().Count);
            AssertEquals(0, odb.Count(new CriteriaQuery(typeof(User))));
            Println("deleted");
            odb.Close();
            stopWatch.End();
            Println("Total time 2 = " + stopWatch.GetDurationInMiliseconds());
            if (stopWatch.GetDurationInMiliseconds() > 108438)
            {
                Fail("time is > than " + 108438 + " = " + stopWatch.GetDurationInMiliseconds());
            }
        }
Ejemplo n.º 7
0
 /// <summary>Test select objects that are not yet commited</summary>
 /// <exception cref="System.Exception">System.Exception</exception>
 public virtual void TestSelectUnCommitedObject4()
 {
     DeleteBase(BaseName);
     // Create instance
     NeoDatis.Odb.Test.VO.Sport.Sport sport = new NeoDatis.Odb.Test.VO.Sport.Sport("volley-ball"
                                                                                   );
     NeoDatis.Odb.ODB odb = null;
     try
     {
         // Open the database
         odb = Open(BaseName);
         // Store the object
         odb.Store(sport);
     }
     finally
     {
         if (odb != null)
         {
             // Close the database
             odb.Close();
         }
     }
     // Create instance
     NeoDatis.Odb.Test.VO.Sport.Sport volleyball = new NeoDatis.Odb.Test.VO.Sport.Sport
                                                       ("volley-ball");
     // Create 4 players
     NeoDatis.Odb.Test.VO.Sport.Player player1 = new NeoDatis.Odb.Test.VO.Sport.Player
                                                     ("olivier", new System.DateTime(), volleyball);
     NeoDatis.Odb.Test.VO.Sport.Player player2 = new NeoDatis.Odb.Test.VO.Sport.Player
                                                     ("pierre", new System.DateTime(), volleyball);
     NeoDatis.Odb.Test.VO.Sport.Player player3 = new NeoDatis.Odb.Test.VO.Sport.Player
                                                     ("elohim", new System.DateTime(), volleyball);
     NeoDatis.Odb.Test.VO.Sport.Player player4 = new NeoDatis.Odb.Test.VO.Sport.Player
                                                     ("minh", new System.DateTime(), volleyball);
     // Create two teams
     NeoDatis.Odb.Test.VO.Sport.Team team1 = new NeoDatis.Odb.Test.VO.Sport.Team("Paris"
                                                                                 );
     NeoDatis.Odb.Test.VO.Sport.Team team2 = new NeoDatis.Odb.Test.VO.Sport.Team("Montpellier"
                                                                                 );
     // Set players for team1
     team1.AddPlayer(player1);
     team1.AddPlayer(player2);
     // Set players for team2
     team2.AddPlayer(player3);
     team2.AddPlayer(player4);
     // Then create a volley ball game for the two teams
     NeoDatis.Odb.Test.VO.Sport.Game game = new NeoDatis.Odb.Test.VO.Sport.Game(new System.DateTime
                                                                                    (), volleyball, team1, team2);
     odb = null;
     try
     {
         // Open the database
         odb = Open(BaseName);
         // Store the object
         odb.Store(game);
     }
     finally
     {
         if (odb != null)
         {
             // Close the database
             odb.Close();
         }
     }
     try
     {
         // Open the database
         odb = Open(BaseName);
         NeoDatis.Odb.Core.Query.IQuery query = new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                    (typeof(NeoDatis.Odb.Test.VO.Sport.Player), NeoDatis.Odb.Core.Query.Criteria.Where
                                                    .Equal("name", "olivier"));
         NeoDatis.Odb.Objects players = odb.GetObjects(query);
         Println("\nStep 3 : Players with name olivier");
         int i = 1;
         // display each object
         while (players.HasNext())
         {
             Println((i++) + "\t: " + players.Next());
         }
     }
     finally
     {
         if (odb != null)
         {
             // Close the database
             odb.Close();
         }
     }
     try
     {
         // Open the database
         odb = Open(BaseName);
         // Let's insert a tennis player
         NeoDatis.Odb.Test.VO.Sport.Player agassi = new NeoDatis.Odb.Test.VO.Sport.Player(
             "André Agassi", new System.DateTime(), new NeoDatis.Odb.Test.VO.Sport.Sport("Tennis"
                                                                                          ));
         NeoDatis.Odb.OID oid = odb.Store(agassi);
         NeoDatis.Odb.Core.Query.IQuery query = new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                    (typeof(NeoDatis.Odb.Test.VO.Sport.Player), NeoDatis.Odb.Core.Query.Criteria.Where
                                                    .Equal("favoriteSport.name", "volley-ball"));
         NeoDatis.Odb.Objects players = odb.GetObjects(query);
         Println("\nStep 4 : Players of Voller-ball");
         int i = 1;
         // display each object
         while (players.HasNext())
         {
             Println((i++) + "\t: " + players.Next());
         }
     }
     finally
     {
         if (odb != null)
         {
             // Close the database
             odb.Close();
         }
     }
     DeleteBase(BaseName);
 }
Ejemplo n.º 8
0
        public virtual void TestInsertSimpleObjectODB(bool force)
        {
            if (!force && !runAll)
            {
                return;
            }
            bool reconnectStatus = NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession();
            //OdbConfiguration.setReconnectObjectsToSession(false);
            // Thread.sleep(20000);
            bool doUpdate = true;
            bool doDelete = true;
            // Configuration.setDatabaseCharacterEncoding(null);
            // LogUtil.logOn(FileSystemInterface.LOG_ID,true);
            // LogUtil.logOn(ObjectReader.LOG_ID,true);
            // Configuration.setUseLazyCache(true);
            bool inMemory = true;

            // Configuration.monitorMemory(true);
            // Configuration.setUseModifiedClass(true);
            // Deletes the database file
            DeleteBase(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;

            NeoDatis.Odb.ODB odb = null;
            NeoDatis.Odb.Objects <SimpleObject>        l  = null;
            NeoDatis.Odb.Test.Performance.SimpleObject so = null;
            // Insert TEST_SIZE objects
            Println("Inserting " + TestSize + " objects");
            t1  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            int i = 0;

            // odb.getClassRepresentation(SimpleObject.class).addFullInstantiationHelper(new
            // SimpleObjectFullInstantiationHelper());
            for (i = 0; i < TestSize; i++)
            {
                object o = GetSimpleObjectInstance(i);
                odb.Store(o);
                if (i % 10000 == 0)
                {
                }
            }
            // println("i="+i);
            // Monitor.displayCurrentMemory(""+i,true);
            // println("Cache="+Dummy.getEngine(odb).getSession().getCache().toString());
            t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // Closes the database
            odb.Close();
            // if(true)return;
            t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            Println("Retrieving " + TestSize + " objects");
            // Reopen the database
            odb = Open(OdbFileName);
            // Gets the TEST_SIZE objects
            l  = odb.GetObjects <SimpleObject>(inMemory);
            t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            i  = 0;
            while (l.HasNext())
            {
                object o = l.Next();
                if (i % 10000 == 0)
                {
                }
                // Monitor.displayCurrentMemory("select "+i,true);
                i++;
            }
            t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            if (doUpdate)
            {
                Println("Updating " + TestSize + " objects");
                i  = 0;
                so = null;
                l.Reset();
                while (l.HasNext())
                {
                    so = (NeoDatis.Odb.Test.Performance.SimpleObject)l.Next();
                    so.SetName(so.GetName() + " updated");
                    odb.Store(so);
                    if (i % 10000 == 0)
                    {
                    }
                    // Monitor.displayCurrentMemory(""+i);
                    i++;
                }
            }
            t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb.Close();
            t7 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            if (doDelete)
            {
                Println("Deleting " + TestSize + " objects");
                odb = Open(OdbFileName);
                l   = odb.GetObjects <SimpleObject>(inMemory);
                t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
                // println("After getting objects - before delete");
                i = 0;
                while (l.HasNext())
                {
                    so = (NeoDatis.Odb.Test.Performance.SimpleObject)l.Next();
                    if (!so.GetName().EndsWith("updated"))
                    {
                        throw new System.Exception("Update  not ok for " + so.GetName());
                    }
                    odb.Delete(so);
                    if (i % 10000 == 0)
                    {
                    }
                    // println("s="+i);
                    i++;
                }
                odb.Close();
            }
            Thread.Sleep(500);

            t8 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            NeoDatis.Odb.OdbConfiguration.SetReconnectObjectsToSession(reconnectStatus);
            DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t3, t4, t5, t6
                          , t7, t77, t8);
        }
Ejemplo n.º 9
0
        public virtual void TestInsertUserODB()
        {
            DeleteBase(OdbFileName);
            long t1;
            long t2;
            long t3;
            long t4;
            long t5;
            long t6;
            long t7;
            long t77;
            long t8;

            t1 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            NeoDatis.Odb.ODB odb = Open(OdbFileName);
            for (int i = 0; i < TestSize; i++)
            {
                object o = GetUserInstance();
                odb.Store(o);
                if (i % 1000 == 0)
                {
                    System.Console.Out.Write(".");
                }
            }
            t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // assertEquals(TEST_SIZE,
            // odb.getSession().getCache().getNumberOfObjects ());
            NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy
                                                                    .GetEngine(odb);
            if (isLocal)
            {
                Println("NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions
                            ());
            }
            odb.Commit();
            t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            Println("end of insert");
            NeoDatis.Odb.Objects <User> l = odb.GetObjects <User>(false);
            t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            int nbObjects = l.Count;

            Println(nbObjects + " objects ");
            User user = null;

            while (l.HasNext())
            {
                // println(i);
                user = (User)l.Next();
            }
            // assertEquals(TEST_SIZE,
            // odb.getSession().getCache().getNumberOfObjects ());
            Println("end of real get objects");
            t5   = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            user = null;
            int j = 0;

            l.Reset();
            while (l.HasNext())
            {
                // println(i);
                user = (User)l.Next();
                user.SetName(user.GetName() + " updated" + j);
                odb.Store(user);
                j++;
            }
            t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            Println("end of update");
            odb.Close();
            t7  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            l   = odb.GetObjects <User>();
            t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            j   = 0;
            while (l.HasNext())
            {
                user = (User)l.Next();
                Println(j + " " + user.GetName());
                AssertTrue(user.GetName().EndsWith("updated" + j));
                odb.Delete(user);
                j++;
            }
            odb.Close();
            t8  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            AssertEquals(0, odb.GetObjects <User>().Count);
            odb.Close();
            DisplayResult("ODB " + TestSize + " User objects ", t1, t2, t3, t4, t5, t6, t7, t77
                          , t8);
            DeleteBase(OdbFileName);
        }
Ejemplo n.º 10
0
        public virtual void TestInsertSimpleObjectODB()
        {
            DeleteBase(OdbFileName);
            long t1  = 0;
            long t2  = 0;
            long t3  = 0;
            long t4  = 0;
            long t5  = 0;
            long t6  = 0;
            long t7  = 0;
            long t77 = 0;
            long t8  = 0;

            NeoDatis.Odb.ODB odb = null;
            NeoDatis.Odb.Objects <SimpleObject> l = null;
            SimpleObject so = null;

            t1  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            for (int i = 0; i < TestSize; i++)
            {
                object o = GetSimpleObjectInstance(i);
                odb.Store(o);
                if (i % 20000 == 0)
                {
                    System.Console.Out.Write(".");
                    Println("After insert=" + NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy.GetEngine
                                (odb).GetSession(true).GetCache().ToString());
                }
            }
            //
            NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine = NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy
                                                                    .GetEngine(odb);
            if (isLocal)
            {
                // println("NB WA="+WriteAction.count);
                Println("NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions
                            ());
            }
            t2 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb.Commit();
            if (isLocal)
            {
                Println("after commit : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions
                            ());
            }
            // if(true)return;
            // println("After commit="+Dummy.getEngine(odb).getSession().getCache().toString());
            // println("NB WA="+WriteAction.count);
            t3 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // println("end of insert");
            l = odb.GetObjects <SimpleObject>(false);
            // println("end of getObjects ");
            t4 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            // println("After getObjects ="+Dummy.getEngine(odb).getSession().getCache().toString());
            // println("NB WA="+WriteAction.count);
            if (isLocal)
            {
                Println("after select : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions
                            ());
            }
            int nbObjects = l.Count;

            Println(nbObjects + " objects ");
            int k = 0;

            while (l.HasNext())
            {
                object o = l.Next();
                if (k % 9999 == 0)
                {
                    Println(((SimpleObject)o).GetName());
                }
                k++;
            }
            // println("end of real get ");
            t5 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            Println("select " + (t5 - t3) + " - " + (t5 - t4));
            so = null;
            k  = 0;
            l.Reset();
            while (l.HasNext())
            {
                so = (SimpleObject)l.Next();
                so.SetName(so.GetName() + " updated");
                odb.Store(so);
                if (k % 10000 == 0)
                {
                    Println("update " + k);
                    if (isLocal)
                    {
                        Println("after update : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions
                                    ());
                        Println("After update=" + NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.Dummy.GetEngine
                                    (odb).GetSession(true).GetCache().ToString());
                    }
                }
                k++;
            }
            if (isLocal)
            {
                Println("after update : NB WAs=" + engine.GetSession(true).GetTransaction().GetNumberOfWriteActions
                            ());
            }
            t6 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb.Close();
            t7  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            l   = odb.GetObjects <SimpleObject>(false);
            t77 = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            int j = 0;

            while (l.HasNext())
            {
                so = (SimpleObject)l.Next();
                AssertTrue(so.GetName().EndsWith("updated"));
                odb.Delete(so);
                if (j % 10000 == 0)
                {
                    Println("delete " + j);
                }
                j++;
            }
            odb.Close();
            t8  = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            odb = Open(OdbFileName);
            AssertEquals(0, odb.GetObjects <SimpleObject>().Count);
            odb.Close();
            DisplayResult("ODB " + TestSize + " SimpleObject objects ", t1, t2, t3, t4, t5, t6
                          , t7, t77, t8);
        }
Ejemplo n.º 11
0
        /// <exception cref="System.Exception"></exception>
        public virtual void Test8()
        {
            int size1 = 1000;
            int size2 = 1000;

            if (!runAll)
            {
                return;
            }
            string baseName = GetBaseName();

            NeoDatis.Odb.ODB     odb = null;
            NeoDatis.Odb.Objects os  = null;
            for (int i = 0; i < size1; i++)
            {
                odb = Open(baseName);
                for (int j = 0; j < size2; j++)
                {
                    NeoDatis.Odb.Test.VO.Login.Function f = new NeoDatis.Odb.Test.VO.Login.Function("function "
                                                                                                    + j);
                    odb.Store(f);
                }
                odb.Close();
                odb = Open(baseName);
                os  = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.Function));
                while (os.HasNext())
                {
                    NeoDatis.Odb.Test.VO.Login.Function f = (NeoDatis.Odb.Test.VO.Login.Function)os.Next
                                                                ();
                    odb.Delete(f);
                }
                odb.Close();
                if (i % 100 == 0)
                {
                    Println(i + "/" + size1);
                }
            }
            odb = Open(baseName);
            os  = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.Function));
            AssertEquals(0, os.Count);
            odb.Close();
            Println("step2");
            for (int i = 0; i < size1; i++)
            {
                odb = Open(baseName);
                os  = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.Function));
                while (os.HasNext())
                {
                    NeoDatis.Odb.Test.VO.Login.Function f = (NeoDatis.Odb.Test.VO.Login.Function)os.Next
                                                                ();
                    odb.Delete(f);
                }
                odb.Close();
                odb = Open(baseName);
                for (int j = 0; j < size2; j++)
                {
                    NeoDatis.Odb.Test.VO.Login.Function f = new NeoDatis.Odb.Test.VO.Login.Function("function "
                                                                                                    + j);
                    odb.Store(f);
                }
                odb.Close();
                if (i % 100 == 0)
                {
                    Println(i + "/" + size1);
                }
            }
            odb = Open(baseName);
            os  = odb.GetObjects(typeof(NeoDatis.Odb.Test.VO.Login.Function));
            AssertEquals(size2, os.Count);
            odb.Close();
            DeleteBase(baseName);
        }
        public virtual void DefragmentTo(string newFileName)
        {
            long start          = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            long totalNbObjects = 0;

            NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine newStorage = NeoDatis.Odb.OdbConfiguration
                                                                        .GetCoreProvider().GetClientStorageEngine(new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter
                                                                                                                      (newFileName, true, baseIdentification.GetUserName(), baseIdentification.GetPassword
                                                                                                                          ()));
            NeoDatis.Odb.Objects <object> defragObjects = null;
            int j = 0;

            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
            // User classes
            System.Collections.IEnumerator iterator = GetMetaModel().GetUserClasses().GetEnumerator
                                                          ();
            while (iterator.MoveNext())
            {
                ci = (NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator.Current;
                if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                {
                    NeoDatis.Tool.DLogger.Debug("Reading " + ci.GetCommitedZoneInfo().GetNbObjects()
                                                + " objects of type " + ci.GetFullClassName());
                }
                defragObjects = GetObjects <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                        (ci.GetFullClassName()), true, -1, -1);
                while (defragObjects.HasNext())
                {
                    newStorage.Store(defragObjects.Next());
                    totalNbObjects++;
                    if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                    {
                        if (j % 10000 == 0)
                        {
                            NeoDatis.Tool.DLogger.Info("\n" + totalNbObjects + " objects saved.");
                        }
                    }
                    j++;
                }
            }
            // System classes
            iterator = GetMetaModel().GetSystemClasses().GetEnumerator();
            while (iterator.MoveNext())
            {
                ci = (NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator.Current;
                if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                {
                    NeoDatis.Tool.DLogger.Debug("Reading " + ci.GetCommitedZoneInfo().GetNbObjects()
                                                + " objects of type " + ci.GetFullClassName());
                }
                defragObjects = GetObjects <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                        (ci.GetFullClassName()), true, -1, -1);
                while (defragObjects.HasNext())
                {
                    newStorage.Store(defragObjects.Next());
                    totalNbObjects++;
                    if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                    {
                        if (j % 10000 == 0)
                        {
                            NeoDatis.Tool.DLogger.Info("\n" + totalNbObjects + " objects saved.");
                        }
                    }
                    j++;
                }
            }
            newStorage.Commit();
            newStorage.Close();
            long time = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs() - start;

            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Info("New storage " + newFileName + " created with " + totalNbObjects
                                           + " objects in " + time + " ms.");
            }
        }
        public virtual void AddIndexOn(string className, string indexName, string[] indexFields
                                       , bool verbose, bool acceptMultipleValuesForSameKey)
        {
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo = GetMetaModel().GetClassInfo
                                                                           (className, true);
            if (classInfo.HasIndex(indexName))
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexAlreadyExist
                                                           .AddParameter(indexName).AddParameter(className));
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex cii = classInfo.AddIndexOn(indexName
                                                                                           , indexFields, acceptMultipleValuesForSameKey);
            NeoDatis.Btree.IBTree btree = null;
            if (acceptMultipleValuesForSameKey)
            {
                btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeMultiple(className, NeoDatis.Odb.OdbConfiguration
                                                                          .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                                              (this));
            }
            else
            {
                btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeSingle(className, NeoDatis.Odb.OdbConfiguration
                                                                        .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                                            (this));
            }
            cii.SetBTree(btree);
            Store(cii);
            // Now The index must be updated with all existing objects.
            if (classInfo.GetNumberOfObjects() == 0)
            {
                // There are no objects. Nothing to do
                return;
            }
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info("Creating index " + indexName + " on class " + className
                                           + " - Class has already " + classInfo.GetNumberOfObjects() + " Objects. Updating index"
                                           );
            }
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info(indexName + " : loading " + classInfo.GetNumberOfObjects
                                               () + " objects from database");
            }
            // We must load all objects and insert them in the index!
            NeoDatis.Odb.Objects <object> objects = GetObjectInfos <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                                                (className), false, -1, -1, false);
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info(indexName + " : " + classInfo.GetNumberOfObjects() + " objects loaded"
                                           );
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = null;
            int  i             = 0;
            bool monitorMemory = NeoDatis.Odb.OdbConfiguration.IsMonitoringMemory();

            while (objects.HasNext())
            {
                nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)objects.Next();
                btree.Insert(cii.ComputeKey(nnoi), nnoi.GetOid());
                if (verbose && i % 1000 == 0)
                {
                    if (monitorMemory)
                    {
                        NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("Index " + indexName +
                                                                                  " " + i + " objects inserted", true);
                    }
                }
                i++;
            }
            if (verbose)
            {
                NeoDatis.Tool.DLogger.Info(indexName + " created!");
            }
        }