Esempio n. 1
0
        static public void TestUpdate()
        {
            String baseName = "t1.neodatis";

            File.Delete(baseName);
            ODB odb = ODBFactory.Open(baseName);

            Function f = new Function("f1");

            odb.Store(f);
            odb.Close();

            odb = ODBFactory.Open(baseName);
            Objects <Function> functions = odb.GetObjects <Function>();

            Console.WriteLine(functions.Count + " functions");
            f = functions.GetFirst();
            f.SetName("function 1");
            odb.Store(f);
            odb.Close();

            odb       = ODBFactory.Open(baseName);
            functions = odb.GetObjects <Function>();
            Console.WriteLine(functions.Count + " functions after update");
            f = functions.GetFirst();
            Console.WriteLine(f.GetName());
            Console.ReadLine();
        }
Esempio n. 2
0
        /**
         * exporting to XML
         *
         *
         * /// <summary>
         * /// How to export the database
         * /// </summary>
         *
         * public void Step15()  {
         *  ODB odb = null;
         *
         *  try {
         *      // Open the database
         *      odb = ODBFactory.Open(ODB_NAME);
         *      // Creates the exporter
         *      XMLExporter exporter = new XMLExporter(odb);
         *
         *      // Actually export to current directory into the sports.xml file
         *      exporter.export(".", "sports.xml");
         *  } finally {
         *      if (odb != null) {
         *          // Close the database
         *          odb.Close();
         *      }
         *  }
         *  Console.WriteLine("\nStep 15 : exporting database to sports.xml");
         * }
         */
        /*
         * /// <summary>
         * /// How to import a database
         * /// </summary>
         * public void Step16()  {
         *  ODB odb = null;
         *
         *  try {
         *      // Delete database first
         *      File.Delete("imported-" + ODB_NAME);
         *
         *      // Open a database to receive imported data
         *      odb = ODBFactory.Open("imported-" + ODB_NAME);
         *      // Creates the exporter
         *      XMLImporter importer = new XMLImporter(odb);
         *
         *      // Actually import data from sports.xml file
         *      importer.importFile(".", "sports.xml");
         *
         *      // Closes the database
         *      odb.Close();
         *
         *      // Re Open the database
         *      odb = ODBFactory.Open("imported-" + ODB_NAME);
         *      // Now query the databas eto check the change
         *      Objects players = odb.GetObjects(typeof(Player));
         *
         *      Console.WriteLine("\nStep 16 : getting players of imported database");
         *
         *      int i = 1;
         *      // display each object
         *      while (players.HasNext()) {
         *          Console.WriteLine((i++) + "\t: " + players.Next());
         *      }
         *
         *  } catch (Exception e) {
         *      Console.WriteLine(e);
         *  } finally {
         *      if (odb != null) {
         *          // Close the database
         *          odb.Close();
         *      }
         *  }
         * }
         * */
        /// <summary>
        /// Database protected by user and password
        /// </summary>
        public void Step17()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME_2, "user", "password");
                odb.Store(new Sport("Tennis"));
                // Commits the changes
                odb.Close();

                try {
                    // try to Open the database without user/password
                    odb = ODBFactory.Open(ODB_NAME_2);
                } catch (ODBAuthenticationRuntimeException e) {
                    Console.WriteLine("\nStep 17 : invalid user/password : database could not be Opened");
                }
                // then Open the database with correct user/password
                odb = ODBFactory.Open(ODB_NAME_2, "user", "password");
                Console.WriteLine("\nStep 17 : user/password : database Opened");
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// How to retrieve objects using Criteria queries traversing relations
        /// </summary>
        public void Step4()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);
                // Let's insert a tennis player
                Player agassi = new Player("Andr\u00E9 Agassi", new DateTime(), new Sport("Tennis"));
                odb.Store(agassi);

                IQuery query = new CriteriaQuery(typeof(Player), Where.Equal("favoriteSport.name", "volley-ball"));

                Objects <Player> players = odb.GetObjects <Player>(query);

                Console.WriteLine("\nStep 4 : Players of Voller-ball");

                int i = 1;
                // display each object
                while (players.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + players.Next());
                }
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Esempio n. 4
0
        public static void test4()
        {
            //OdbConfiguration.SetDebugEnabled(true);
            OdbConfiguration.SetReconnectObjectsToSession(false);

            try
            {
                int    size = 1000;
                string file = "Test.NeoDatis";
                Console.WriteLine("Oi");
                IOUtil.DeleteFile(file);
                ODB odb = ODBFactory.Open(file);
                for (int i = 0; i < size; i++)
                {
                    OID oid = odb.Store(new Function("function " + i));
                }
                odb.Close();

                odb = ODBFactory.Open(file);
                Objects <Function> functions = odb.GetObjects <Function>(new CriteriaQuery(Where.Equal("name", "function 199")));
                Console.WriteLine(" Number of functions = " + functions.Count);

                odb.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
Esempio n. 5
0
        public static void test1()
        {
            //OdbConfiguration.SetDebugEnabled(true);
            OdbConfiguration.SetReconnectObjectsToSession(false);

            try
            {
                string file = "Test.NeoDatis";
                IOUtil.DeleteFile(file);
                ODB odb = ODBFactory.Open(file);
                OID oid = odb.Store(new Function("f1"));
                odb.Close();
                Console.WriteLine("Write Done!");

                odb = ODBFactory.Open(file);
                Objects <Function> functions = odb.GetObjects <Function>();
                Console.WriteLine(" Number of functions = " + functions.Count);
                Function f = (Function)odb.GetObjectFromId(oid);
                Console.WriteLine(f.ToString());
                odb.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
Esempio n. 6
0
        static public void Test4()
        {
            String baseName = "t2.neodatis";

            File.Delete(baseName);
            ODB odb = ODBFactory.Open(baseName);

            Console.WriteLine("oi");
            int  size = 10000;
            long now  = DateTime.Now.Ticks;

            for (int i = 0; i < size; i++)
            {
                Function f = new Function("f1 " + i);
                odb.Store(f);
            }
            odb.Close();
            long t2 = DateTime.Now.Ticks;

            Console.WriteLine("time for insert = " + (DateTime.Now.Ticks - now) / 10000);

            odb = ODBFactory.Open(baseName);

            //Objects<User> users = odb.GetObjects<User>(new CriteriaQuery(Where.Like("name", "user name")));
            Objects <Function> functions = odb.GetObjects <Function>();

            Console.WriteLine(functions.Count + " functions");
            Console.WriteLine(" Time = " + (DateTime.Now.Ticks - t2) / 10000);
            odb.Close();
            Console.ReadLine();
        }
Esempio n. 7
0
        public virtual void TestEnum1()
        {
            string        baseName = GetBaseName();
            ODB           odb      = Open(baseName);
            ClassWithEnum e        = new ClassWithEnum("enum1", ObjectType.Medium);

            odb.Store(e);
            odb.Close();
            odb = Open(baseName);
            Objects <ClassWithEnum> objects = odb.GetObjects <ClassWithEnum>();

            odb.Close();
            AssertEquals(1, objects.Count);
        }
Esempio n. 8
0
        public virtual void TestEnumUpdate()
        {
            string        baseName = GetBaseName();
            ODB           odb      = Open(baseName);
            ClassWithEnum e        = new ClassWithEnum("enum1", ObjectType.Medium);

            odb.Store(e);
            odb.Close();
            odb = Open(baseName);
            Objects <ClassWithEnum> objects = odb.GetObjects <ClassWithEnum>();
            ClassWithEnum           cwe     = objects.GetFirst();

            cwe.SetObjectType(ObjectType.Small);
            odb.Store(cwe);
            odb.Close();
            odb     = Open(baseName);
            objects = odb.GetObjects <ClassWithEnum>();
            AssertEquals(1, objects.Count);

            cwe = objects.GetFirst();
            odb.Close();
            AssertEquals(ObjectType.Small, cwe.GetObjectType());
        }
Esempio n. 9
0
        static public void Test1()
        {
            String   baseName = "test.neodatis";
            ODB      odb      = ODBFactory.Open(baseName);
            Function f        = new Function("f1");

            odb.Store(f);
            odb.Close();

            odb = ODBFactory.Open(baseName);
            Objects <Function> functions = odb.GetObjects <Function>(new CriteriaQuery(Where.Equal("name", "f1")));

            Console.WriteLine(functions.Count + " functions");
            odb.Close();
            Console.ReadLine();
        }
Esempio n. 10
0
        /// <summary>
        /// How to delete an object using OID
        /// </summary>
        public void Step14()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);

                Sport tennis = odb.GetObjects <Sport>(new CriteriaQuery(typeof(Sport), Where.Equal("name", "Tennis"))).GetFirst();
                // Firts re-create Agassi player - it has been deleted in step 13
                Player agassi = new Player("Andr\u00E9 Agassi", new DateTime(), tennis);
                odb.Store(agassi);
                odb.Commit();

                IQuery query = new CriteriaQuery(typeof(Player), Where.Like("name", "%Agassi"));

                Objects <Player> players = odb.GetObjects <Player>(query);

                // Gets the first player (there is only one!)
                agassi = players.GetFirst();
                OID agassiId = odb.GetObjectId(agassi);

                odb.DeleteObjectWithId(agassiId);

                odb.Close();

                odb = ODBFactory.Open(ODB_NAME);
                // Now query the databas eto check the change
                players = odb.GetObjects <Player>();

                Console.WriteLine("\nStep 14 : Deleting players");

                int i = 1;
                // display each object
                while (players.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + players.Next());
                }
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// How to insert a complex object in NeoDatis Database
        /// </summary>
        public void Step2()
        {
            // Create instance
            Sport volleyball = new Sport("volley-ball");

            // Create 4 players
            Player player1 = new Player("olivier", new DateTime(), volleyball);
            Player player2 = new Player("pierre", new DateTime(), volleyball);
            Player player3 = new Player("elohim", new DateTime(), volleyball);
            Player player4 = new Player("minh", new DateTime(), volleyball);

            // Create two teams
            Team team1 = new Team("Paris");
            Team team2 = new 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
            Game game = new Game(new DateTime(), volleyball, team1, team2);

            ODB odb = null;

            try
            {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);

                // Store the object
                odb.Store(game);
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Esempio n. 12
0
        static public void Test2()
        {
            String   baseName = "t1.neodatis";
            ODB      odb      = ODBFactory.Open(baseName);
            Function f        = new Function("f1");
            Profile  profile  = new Profile("profile1", f);
            User     user     = new User("user name", "email", profile);

            odb.Store(user);
            odb.Close();

            odb = ODBFactory.Open(baseName);
            Objects <User> users = odb.GetObjects <User>(new CriteriaQuery(Where.Equal("name", "user name")));

            Console.WriteLine(users.Count + " users");
            odb.Close();
            Console.ReadLine();
        }
Esempio n. 13
0
        /// <summary>
        /// How to update objects
        /// </summary>
        public void Step12()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);
                IQuery query = new CriteriaQuery(typeof(Sport), Where.Equal("name", "volley-ball"));

                Objects <Sport> sports = odb.GetObjects <Sport>(query);

                // Gets the first sport (there is only one!)
                Sport volley = sports.GetFirst();

                // Changes the name
                volley.SetName("Beach-Volley");

                // Actually updates the object
                odb.Store(volley);

                // Commits the changes
                odb.Close();

                odb = ODBFactory.Open(ODB_NAME);
                // Now query the database to check the change
                sports = odb.GetObjects <Sport>();

                Console.WriteLine("\nStep 12 : Updating sport");

                int i = 1;
                // display each object
                while (sports.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + sports.Next());
                }
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Esempio n. 14
0
        static public void Test3()
        {
            String baseName = "t2.neodatis";

            File.Delete(baseName);
            ODB odb = ODBFactory.Open(baseName);

            int      size = 10000;
            DateTime now  = DateTime.Now;

            for (int i = 0; i < size; i++)
            {
                Function f       = new Function("f1 " + i);
                Profile  profile = new Profile("profile1" + i, f);
                User     user    = new User("user name" + i, "email" + i, profile);
                odb.Store(user);
            }
            odb.Close();
            Console.WriteLine("time for insert = " + (DateTime.Now - now).Ticks / 10000);

            odb = ODBFactory.Open(baseName);

            long t0 = DateTime.Now.Ticks;
            //Objects<User> users = odb.GetObjects<User>(new CriteriaQuery(Where.Like("name", "user name")));
            Objects <User> users = odb.GetObjects <User>(false);
            long           t1    = DateTime.Now.Ticks;

            Console.WriteLine(users.Count + " users");
            while (users.HasNext())
            {
                users.Next();
            }
            long t2 = DateTime.Now.Ticks;

            Console.WriteLine("Get=" + (t1 - t0) / 10000 + "  - actual Get = " + (t2 - t1) / 10000);
            odb.Close();
            Console.ReadLine();
        }
Esempio n. 15
0
        /// <summary>
        ///  How to insert an object in NeoDatis database
        /// </summary>
        public void Step1()
        {
            // Create instance
            Sport sport = new Sport("volley-ball");

            ODB odb = null;

            try
            {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);

                // Store the object
                odb.Store(sport);
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }