Exemple #1
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();
        }
Exemple #2
0
        /// <summary>
        /// Using Indexes
        /// </summary>
        public void Step11()
        {
            // Open the database
            ODB odb = null;

            try {
                odb = ODBFactory.Open(ODB_NAME);

                String[] fieldNames = { "name" };
                odb.GetClassRepresentation(typeof(Sport)).AddUniqueIndexOn("sport-index", fieldNames, true);
                odb.Close();

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

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

                Console.WriteLine("\nStep 11 : Using index");

                int i = 1;
                // display each object
                while (sports.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + sports.Next());
                }
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Exemple #3
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();
        }
Exemple #4
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();
                }
            }
        }
Exemple #5
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();
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #8
0
        public void DisplayGames(String label1)
        {
            // Open the database
            ODB odb = null;

            try
            {
                odb = ODBFactory.Open(ODB_NAME);
                // Get all object of type clazz
                Objects <Game> objects = odb.GetObjects <Game>();

                Console.WriteLine("\n Games : " + label1);

                int i = 1;
                // display each object
                while (objects.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + objects.Next());
                }
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// How to retrieve objects using Criteria queries
        /// </summary>
        public void Step3()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);
                IQuery           query   = new CriteriaQuery(Where.Equal("name", "olivier"));
                Objects <Player> players = odb.GetObjects <Player>(query);

                Console.WriteLine("\nStep 3 : Players with name olivier");

                int i = 1;
                // display each object
                while (players.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + players.Next());
                }
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Exemple #10
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();
        }
Exemple #11
0
        /**
         * How to retrieve objects using Criteria queries with Not
         *
         */
        /// <summary>
        /// How to retrieve objects using Criteria queries using object
        /// </summary>
        public void Step7()
        {
            ODB odb = null;

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

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

                Console.WriteLine("\nStep 7 : Players that don't play Volley-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();
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// How to retrieve objects using Criteria queries using object
        /// </summary>
        public void Step5()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);
                // retrieve the volley ball sport object
                IQuery query      = new CriteriaQuery(typeof(Sport), Where.Equal("name", "volley-ball"));
                Sport  volleyBall = odb.GetObjects <Sport>(query).GetFirst();

                // Now build a query to get all players that play volley ball, using
                // the volley ball object
                query = new CriteriaQuery(Where.Equal("favoriteSport", volleyBall));

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

                Console.WriteLine("\nStep 5: 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();
                }
            }
        }
Exemple #13
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();
                }
            }
        }
Exemple #14
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();
                }
            }
        }
Exemple #15
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();
        }
Exemple #16
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();
                }
            }
        }
Exemple #17
0
        /// <summary>
        /// How to delete Objects
        /// </summary>
        public void Step13()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);
                IQuery queryAll = new CriteriaQuery(typeof(Player));
                IQuery query    = new CriteriaQuery(typeof(Player), Where.Like("name", "%Agassi"));

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

                // Gets the first player (there is only one!)
                Player agassi = players.GetFirst();

                odb.Delete(agassi);

                odb.Close();

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

                Console.WriteLine("\nStep 13 : Deleting Agassi");

                int i = 1;
                // display each object
                while (players.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + players.Next());
                }
            } finally {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
Exemple #18
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();
        }
Exemple #19
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());
        }
Exemple #20
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();
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// How to retrieve objects using Native queries
        /// </summary>
        ///

        /*
         * public void step8()  {
         *  ODB odb = null;
         *
         *  try {
         *      // Open the database
         *      odb = ODBFactory.Open(ODB_NAME);
         *      IQuery query = new SimpleNativeQuery() {  public boolean match(Player player) {
         *              return player.getFavoriteSport().getName().toLowerCase().startsWith("volley");
         *          }
         *      };
         *
         *      Objects<Player> players = odb.GetObjects<Player>(query);
         *
         *      Console.WriteLine("\nStep 8 bis: Players that play Volley-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();
         *      }
         *  }
         * }
         */
        /**
         * Native query with Objects,
         *
         *
         * /// <summary>
         * /// How to retrieve objects using Criteria queries using object
         * /// </summary>
         * public void step9()  {
         *  ODB odb = null;
         *
         *  try {
         *      // Open the database
         *      odb = ODBFactory.Open(ODB_NAME);
         *
         *      // first retrieve the player Minh
         *      IQuery query = new CriteriaQuery(typeof(Player), Where.Equal("name", "minh"));
         *      Player minh = (Player) odb.GetObjects(query).getFirst();
         *
         *      // builds a query to get all teams where mihn plays
         *      query = new CriteriaQuery(typeof(Team), Where.contain("players", minh));
         *      Objects teams = odb.GetObjects(query);
         *
         *      Console.WriteLine("\nStep 9: Team where minh plays");
         *
         *      int i = 1;
         *      // display each object
         *      while (teams.HasNext()) {
         *          Console.WriteLine((i++) + "\t: " + teams.Next());
         *      }
         *
         *  } finally {
         *      if (odb != null) {
         *          // Close the database
         *          odb.Close();
         *      }
         *  }
         * }*/


        /// <summary>
        /// How to retrieve objects using order by
        /// </summary>
        public void Step10()
        {
            ODB odb = null;

            try {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);
                IQuery query = new CriteriaQuery(typeof(Player));
                query.OrderByAsc("name");

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

                Console.WriteLine("\nStep 10: Players ordered by name asc");

                int i = 1;
                // display each object
                while (players.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + players.Next());
                }

                query.OrderByDesc("name");

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

                Console.WriteLine("\nStep 10: Players ordered by name desc");

                i = 1;
                // display each object
                while (players.HasNext())
                {
                    Console.WriteLine((i++) + "\t: " + players.Next());
                }
            } finally {
                if (odb != null)
                {
                    odb.Close();
                }
            }
        }
Exemple #22
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();
                }
            }
        }