Ejemplo n.º 1
0
    public static void Test_OneToOneDelete()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

      Nation nation = new Nation
                        {
                          code = "ROM",
                          name = "Romania",
                          capital = "Bucharest",
                          continent = "Europe",
                          Athletes = new List<AthleteOneToMany>()
                        };

      Stadium stadium = new Stadium
                          {
                            code = 30141,
                            nation_code = "ROM",
                            name = "National Arena",
                            area = (decimal)120400.00,
                            seats = 55000,
                            address = "Bucharest, Romania"
                          };

      Event game_event = new Event
                           {
                             code = 20422,
                             sports = "Football",
                             name = "UEFA Europa League",
                             gender = "M",
                             players = 11
                           };

      AthleteOneToOne athlete = new AthleteOneToOne
                                  {
                                    name = "Raul Rusescu",
                                    gender = "M",
                                    nation_code = "ROM",
                                    athlete_event = "Football",
                                  };

      Game game = new Game
                    {
                      host_year = 2012,
                      medal = "G",
                      game_date = new DateTime(2012, 5, 8),
                      Athlete = athlete,
                      Event = game_event,
                      Stadium = stadium,
                      Nation = nation
                    };

      int count = 0;
      ISessionFactory sessionFactory = cfg.BuildSessionFactory();
      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Game> games = session.Query<Game>().GetEnumerator();
        while (games.MoveNext())
        {
          count++;
        }
        Debug.Assert(count == 8653);
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Save(game);
          tx.Commit();
        }
      }

      count = 0;
      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Game> games = session.Query<Game>().GetEnumerator();
        while (games.MoveNext())
        {
          count++;
        }
        Debug.Assert(count == 8654);
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Delete(game);
          tx.Commit();
        }
      }

      count = 0;
      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Game> games = session.Query<Game>().GetEnumerator();
        while (games.MoveNext())
        {
          count++;
        }
        Debug.Assert(count == 8653);
      }
    }
Ejemplo n.º 2
0
    public static void Test_OneToOneUpdate()
    {
      Configuration cfg = (new Configuration()).Configure().AddAssembly(typeof(TestCUBRIDBlobType).Assembly);

      Nation nation = new Nation
                        {
                          code = "ROM",
                          name = "Romania",
                          capital = "Bucharest",
                          continent = "Europe",
                          Athletes = new List<AthleteOneToMany>()
                        };

      Stadium stadium = new Stadium
                          {
                            code = 30141,
                            nation_code = "ROM",
                            name = "National Arena",
                            area = (decimal)120400.00,
                            seats = 55000,
                            address = "Bucharest, Romania"
                          };

      Event game_event = new Event
                           {
                             code = 20422,
                             sports = "Football",
                             name = "UEFA Europa League",
                             gender = "M",
                             players = 11
                           };

      AthleteOneToOne athlete = new AthleteOneToOne
                                  {
                                    name = "Raul Rusescu",
                                    gender = "M",
                                    nation_code = "ROM",
                                    athlete_event = "Football",
                                  };

      Game game = new Game
                    {
                      host_year = 2012,
                      medal = "G",
                      game_date = new DateTime(2012, 5, 8),
                      Athlete = athlete,
                      Event = game_event,
                      Stadium = stadium,
                      Nation = nation
                    };

      ISessionFactory sessionFactory = cfg.BuildSessionFactory();
      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Save(game);
          tx.Commit();
        }
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Game> games = session.Query<Game>().GetEnumerator();
        while (games.MoveNext())
        {
          if (games.Current.host_year == 2012)
          {
            List<object> gameValues = GetTableValues("game", 8654, new string[] { "host_year", "medal", "game_date" });
            List<object> athleteValues = GetTableValues("athlete", 6678, new string[] { "code", "name", "gender", "nation_code", "event" });
            List<object> nationValues = GetTableValues("nation", 216, new string[] { "code", "name", "capital" });
            List<object> stadiumValues = GetTableValues("stadium", 142, new string[] { "code", "nation_code", "name", "area", "seats", "address" });
            List<object> eventValues = GetTableValues("event", 423, new string[] { "code", "name", "sports", "gender", "players" });
            Debug.Assert(games.Current.host_year == (int)gameValues[0]);
            Debug.Assert(games.Current.medal == (string)gameValues[1]);
            Debug.Assert(games.Current.game_date == (DateTime)gameValues[2]);
            Debug.Assert(games.Current.Nation.code == (string)nationValues[0]);
            Debug.Assert(games.Current.Nation.name == (string)nationValues[1]);
            Debug.Assert(games.Current.Nation.capital == (string)nationValues[2]);
            Debug.Assert(games.Current.Athlete.name == (string)athleteValues[1]);
            Debug.Assert(games.Current.Athlete.gender == (string)athleteValues[2]);
            Debug.Assert(games.Current.Stadium.code == (int)stadiumValues[0]);
            Debug.Assert(games.Current.Stadium.nation_code == (string)stadiumValues[1]);
            Debug.Assert(games.Current.Stadium.name == (string)stadiumValues[2]);
            Debug.Assert(games.Current.Stadium.area == (decimal)stadiumValues[3]);
            Debug.Assert(games.Current.Stadium.seats == (int)stadiumValues[4]);
            Debug.Assert(games.Current.Stadium.address == (string)stadiumValues[5]);
            Debug.Assert(games.Current.Event.code == (int)eventValues[0]);
            Debug.Assert(games.Current.Event.name == (string)eventValues[1]);
            Debug.Assert(games.Current.Event.sports == (string)eventValues[2]);
            Debug.Assert(games.Current.Event.gender == (string)eventValues[3]);
            Debug.Assert(games.Current.Event.players == (int)eventValues[4]);
          }
        }
      }

      game.game_date = new DateTime(2013, 4, 19);
      game.Athlete.name = "Ciprian Tatarusanu";
      game.Nation.capital = "Bucuresti";
      game.Stadium.name = "Bucuresti Arena";
      game.Event.name = "UEFA Europa League Final";

      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Update(game);
          tx.Commit();
        }
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        IEnumerator<Game> games = session.Query<Game>().GetEnumerator();
        while (games.MoveNext())
        {
          if (games.Current.host_year == 2012)
          {
            List<object> gameValues = GetTableValues("game", 8654, new string[] { "host_year", "medal", "game_date" });
            List<object> athleteValues = GetTableValues("athlete", 6678, new string[] { "code", "name", "gender", "nation_code", "event" });
            List<object> nationValues = GetTableValues("nation", 216, new string[] { "code", "name", "capital" });
            List<object> stadiumValues = GetTableValues("stadium", 142, new string[] { "code", "nation_code", "name", "area", "seats", "address" });
            List<object> eventValues = GetTableValues("event", 423, new string[] { "code", "name", "sports", "gender", "players" });
            Debug.Assert(games.Current.host_year == (int)gameValues[0]);
            Debug.Assert(games.Current.medal == (string)gameValues[1]);
            Debug.Assert(games.Current.game_date == (DateTime)gameValues[2]);
            Debug.Assert(games.Current.Nation.code == (string)nationValues[0]);
            Debug.Assert(games.Current.Nation.name == (string)nationValues[1]);
            Debug.Assert(games.Current.Nation.capital == (string)nationValues[2]);
            Debug.Assert(games.Current.Athlete.name == (string)athleteValues[1]);
            Debug.Assert(games.Current.Athlete.gender == (string)athleteValues[2]);
            Debug.Assert(games.Current.Stadium.code == (int)stadiumValues[0]);
            Debug.Assert(games.Current.Stadium.nation_code == (string)stadiumValues[1]);
            Debug.Assert(games.Current.Stadium.name == (string)stadiumValues[2]);
            Debug.Assert(games.Current.Stadium.area == (decimal)stadiumValues[3]);
            Debug.Assert(games.Current.Stadium.seats == (int)stadiumValues[4]);
            Debug.Assert(games.Current.Stadium.address == (string)stadiumValues[5]);
            Debug.Assert(games.Current.Event.code == (int)eventValues[0]);
            Debug.Assert(games.Current.Event.name == (string)eventValues[1]);
            Debug.Assert(games.Current.Event.sports == (string)eventValues[2]);
            Debug.Assert(games.Current.Event.gender == (string)eventValues[3]);
            Debug.Assert(games.Current.Event.players == (int)eventValues[4]);
          }
        }
      }

      using (ISession session = sessionFactory.OpenSession())
      {
        using (ITransaction tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
        {
          session.Delete(game);
          tx.Commit();
        }
      }
    }