コード例 #1
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }
コード例 #2
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #3
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /**
         * 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();
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }
コード例 #5
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        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();
                }
            }
        }
コード例 #6
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #7
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #8
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }
コード例 #11
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #12
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #13
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #14
0
ファイル: Tutorial.cs プロジェクト: ekicyou/pasta
        /// <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();
                }
            }
        }
コード例 #15
0
ファイル: TestEnum.cs プロジェクト: ekicyou/pasta
        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);
        }
コード例 #16
0
ファイル: TestEnum.cs プロジェクト: ekicyou/pasta
        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());
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: ekicyou/pasta
        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();
        }