Пример #1
0
        public void bSyncDeletedDatabases()
        {
            using (SessionBase session = new SessionNoServer(s_sync1))
            {
                using (var trans = session.BeginUpdate())
                {
                    for (uint i = 10; i < 14; i++)
                    {
                        var database = session.OpenDatabase(i);
                        session.DeleteDatabase(database);
                    }
                    session.Commit();
                }
            }

            using (SessionBase readFromSession = new SessionNoServer(s_sync1))
            {
                using (SessionBase updateSession = new SessionNoServer(s_sync2))
                {
                    updateSession.SyncWith(readFromSession);
                }
            }

            using (SessionBase readFromSession = new SessionNoServer(s_sync1))
            {
                readFromSession.BeginRead();
                using (SessionBase updateSession = new SessionNoServer(s_sync2))
                {
                    using (var trans = updateSession.BeginRead())
                    {
                        Assert.AreEqual(updateSession.OpenAllDatabases().Count, readFromSession.OpenAllDatabases().Count - 1); // - 1 due to additional change tracking databases in original
                    }
                }
            }
        }
Пример #2
0
 public void TwoUpdaters1()
 {
   Assert.Throws<OptimisticLockingFailed>(() =>
   {
     UInt64 id;
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       session.BeginUpdate();
       Man man = new Man();
       man.Persist(session, man);
       id = man.Id;
       session.Commit();
       session.BeginUpdate();
       man.Age = ++man.Age;
       Database db = session.NewDatabase(3567);
       using (SessionNoServer session2 = new SessionNoServer(systemDir))
       {
         session2.BeginUpdate();
         Man man2 = (Man)session2.Open(id);
         Assert.Less(man2.Age, man.Age);
         man2.Age = ++man.Age;
         session2.Commit();
       }
       session.DeleteDatabase(db);
       session.Commit(); // OptimisticLockingFailed here
     }
   });
 }
Пример #3
0
 public void TwoUpdaters1()
 {
     Assert.Throws <OptimisticLockingFailed>(() =>
     {
         UInt64 id;
         using (SessionNoServer session = new SessionNoServer(systemDir))
         {
             session.BeginUpdate();
             Man man = new Man();
             man.Persist(session, man);
             id = man.Id;
             session.Commit();
             session.BeginUpdate();
             man.Age     = ++man.Age;
             Database db = session.NewDatabase(3567);
             using (SessionNoServer session2 = new SessionNoServer(systemDir))
             {
                 session2.BeginUpdate();
                 Man man2 = (Man)session2.Open(id);
                 Assert.Less(man2.Age, man.Age);
                 man2.Age = ++man.Age;
                 session2.Commit();
             }
             session.DeleteDatabase(db);
             session.Commit(); // OptimisticLockingFailed here
             session.Verify();
         }
     });
 }
Пример #4
0
 public void CreateLocationSameHost()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         DatabaseLocation remoteLocation = new DatabaseLocation(Dns.GetHostName(), location2Dir, locationStartDbNum, locationEndDbNum, session, PageInfo.compressionKind.LZ4, 0);
         remoteLocation = session.NewLocation(remoteLocation);
         Database database = session.NewDatabase(remoteLocation.StartDatabaseNumber);
         Assert.NotNull(database);
         session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         Database database = session.OpenDatabase(locationStartDbNum, false);
         Assert.NotNull(database);
         session.DeleteDatabase(database);
         session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         foreach (DatabaseLocation loc in session.DatabaseLocations)
         {
             Console.WriteLine(loc.ToStringDetails(session, false));
         }
         session.DeleteLocation(session.DatabaseLocations.LocationForDb(locationStartDbNum));
         foreach (DatabaseLocation loc in session.DatabaseLocations)
         {
             Console.WriteLine(loc.ToStringDetails(session, false));
         }
         session.Commit();
     }
 }
Пример #5
0
 public void License()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         Database database;
         session.BeginUpdate();
         for (uint i = 60000000; i < 60000010; i++)
         {
             database = session.NewDatabase(i);
             Assert.NotNull(database);
         }
         session.Commit();
         session.BeginUpdate();
         for (uint i = 60000000; i < 60000010; i++)
         {
             database = session.OpenDatabase(i);
             Assert.NotNull(database);
         }
         session.Commit();
         session.BeginUpdate();
         for (uint i = 60000000; i < 60000010; i++)
         {
             database = session.OpenDatabase(i);
             session.DeleteDatabase(database);
         }
         session.Commit();
     }
 }
 public void CreateLocationSameHost()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     DatabaseLocation remoteLocation = new DatabaseLocation(Dns.GetHostName(), location2Dir, locationStartDbNum, locationEndDbNum, session, PageInfo.compressionKind.LZ4, 0);
     remoteLocation = session.NewLocation(remoteLocation);
     Database database = session.NewDatabase(remoteLocation.StartDatabaseNumber);
     Assert.NotNull(database);
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     Database database = session.OpenDatabase(locationStartDbNum, false);
     Assert.NotNull(database);
     session.DeleteDatabase(database);
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     foreach (DatabaseLocation loc in session.DatabaseLocations)
       Console.WriteLine(loc.ToStringDetails(session, false));
     session.DeleteLocation(session.DatabaseLocations.LocationForDb(locationStartDbNum));
     foreach (DatabaseLocation loc in session.DatabaseLocations)
       Console.WriteLine(loc.ToStringDetails(session, false));
     session.Commit();
   }
 }
Пример #7
0
 public void cDeleteDatabases()
 {
   Database database;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     for (uint i = 50000000; i < 50001000; i++)
     {
       database = session.OpenDatabase(i);
       session.DeleteDatabase(database);
     }
     session.Commit();
   }
 }
Пример #8
0
        public void cDeleteDatabases()
        {
            Database database;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (uint i = 50000000; i < 50001000; i++)
                {
                    database = session.OpenDatabase(i);
                    session.DeleteDatabase(database);
                }
                session.Commit();
            }
        }
Пример #9
0
 public void Dispose()
 {
     using (SessionNoServer session = new SessionNoServer(SystemDir))
     {
         session.BeginUpdate();
         DatabaseLocation defaultLocation = session.DatabaseLocations.Default();
         List <Database>  dbList          = session.OpenLocationDatabases(defaultLocation, true);
         foreach (Database db in dbList)
         {
             if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers)
             {
                 session.DeleteDatabase(db);
             }
         }
         session.DeleteLocation(defaultLocation);
         session.Commit();
     }
 }
Пример #10
0
    static readonly string s_systemDir = "Indexes"; // appended to SessionBase.BaseDatabasePath

    static void Main(string[] args)
    {
      try
      {
        Trace.Listeners.Add(new ConsoleTraceListener());
        string brandName = "Toyota";
        string color = "Blue";
        int maxPassengers = 5;
        int fuelCapacity = 40;
        double litresPer100Kilometers = 5;
        DateTime modelYear = new DateTime(2003, 1, 1);
        string modelName = "Highlander";
        int maxSpeed = 200;
        int odometer = 100000;
        string registrationState = "Texas";
        string registrationPlate = "TX343434";
        string insurancePolicy = "CAA7878787";
        DriversLicense license = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0));
        Person person = new Person("Mats Persson", license);
        InsuranceCompany insuranceCompany = new InsuranceCompany("Allstate", "858727878");
        Car car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
          odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        { // cleanup data from a possible prior run
          session.BeginUpdate();
          foreach (Database db in session.OpenAllDatabases(true))
            if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber)
              session.DeleteDatabase(db);
          session.Commit();
          File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
          //session.AddToIndexInSeperateThread = false;
          session.BeginUpdate();
          session.Persist(car);
          registrationState = "Maine";
          car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
          odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
          session.Persist(car);
          color = "Red";
          maxPassengers = 5;
          fuelCapacity = 50;
          litresPer100Kilometers = 8;
          modelYear = new DateTime(2006, 1, 1);
          brandName = "Toyota";
          modelName = "Tacoma";
          maxSpeed = 210;
          odometer = 50000;
          registrationState = "Texas";
          registrationPlate = "TX343433";
          insurancePolicy = "CAA7878777";
          car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
            odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
          session.Persist(car);
          color = "Black";
          maxPassengers = 5;
          fuelCapacity = 60;
          litresPer100Kilometers = 3;
          modelYear = new DateTime(2001, 1, 1);
          brandName = "Lincoln";
          modelName = "Town Car";
          maxSpeed = 220;
          odometer = 250000;
          registrationState = "Texas";
          registrationPlate = "TX543433";
          insurancePolicy = "CAA7878775";
          car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
            odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
          session.Persist(car);
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.BeginRead();
          Console.WriteLine("Blue Cars");
          BTreeSet<Car> bTree = session.Index<Car>("color");
          foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Cars in fuel efficiency order");
          foreach (Car c in session.Index<Car>("litresPer100Kilometers"))
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color");
          foreach (Vehicle v in session.Index<Vehicle>())
            Console.WriteLine(v.ToStringDetails(session));
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          session.BeginUpdate();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Car c = (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar).First();
          c.Color = "Green";
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          session.BeginUpdate();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Car c = (from aCar in session.Index<Car>("color") where aCar.Color == "Green" select aCar).First();
          UInt64 id = c.Id;
          session.DeleteObject(id);
          session.Abort();
          session.BeginUpdate();
          session.DeleteObject(id);
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          for (int i = 0; i < 10000; i++)
          { // add some junk to make search harder
            car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i,
            odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy);
            session.Persist(car);
          }
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          Car c = (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar).First();
          c.Unpersist(session);
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          foreach (Car c in session.Index<Car>())
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>() where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          InsuranceCompany prior = insuranceCompany;
          try
          {
            for (int i = 0; i < 100000; i++)
            {
              insuranceCompany = new InsuranceCompany("AAA", "858787878");
              session.Persist(insuranceCompany);
            }
            Debug.Assert(false); // should not get here
          }
          catch (UniqueConstraintException)
          {
          }
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
          var q = from company in session.Index<InsuranceCompany>("name", db) where company.Name == "AAA" select company;
          foreach (InsuranceCompany company in q)
            Console.WriteLine(company.ToStringDetails(session)); // only one will match
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          Customer joe = new Customer("Joe");
          session.Persist(joe);
          Customer karim = new Customer("Karim");
          session.Persist(karim);
          Customer tony = new Customer("Tony");
          session.Persist(tony);
          Customer wayne = new Customer("Wayne");
          session.Persist(wayne);
          Order order = new Order(joe);
          Payment payment = new Payment(order);
          order = new Order(karim);
          payment = new Payment(order);
          payment = new Payment(order);
          payment = new Payment(order);
          order = new Order(tony);
          payment = new Payment(order);
          payment = new Payment(order);
          order = new Order(wayne);
          payment = new Payment(order);
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          var karim = (from customer in session.Index<Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
          var karimOrders = karim.Orders;
          var karimOrderFromOrders = (from order in session.Index<Order>("m_customer") where order.Customer == karim select order).ToArray();
          session.Commit();
          session.BeginUpdate();
          karim = (from customer in session.Index<Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
          karim.StreetAddress = "1623 Bonita Ave";
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }
Пример #11
0
        static readonly string s_systemDir     = "Indexes"; // appended to SessionBase.BaseDatabasePath

        static void Main(string[] args)
        {
            try
            {
                Trace.Listeners.Add(new ConsoleTraceListener());
                string           brandName              = "Toyota";
                string           color                  = "Blue";
                int              maxPassengers          = 5;
                int              fuelCapacity           = 40;
                double           litresPer100Kilometers = 5;
                DateTime         modelYear              = new DateTime(2003, 1, 1);
                string           modelName              = "Highlander";
                int              maxSpeed               = 200;
                int              odometer               = 100000;
                string           registrationState      = "Texas";
                string           registrationPlate      = "TX343434";
                string           insurancePolicy        = "CAA7878787";
                DriversLicense   license                = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0));
                Person           person                 = new Person("Mats Persson", license);
                InsuranceCompany insuranceCompany       = new InsuranceCompany("Allstate", "858727878");
                Car              car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                               odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                { // cleanup data from a possible prior run
                    session.BeginUpdate();
                    foreach (Database db in session.OpenAllDatabases(true))
                    {
                        if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber)
                        {
                            session.DeleteDatabase(db);
                        }
                    }
                    session.Commit();
                    File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
                    //session.AddToIndexInSeperateThread = false;
                    session.BeginUpdate();
                    session.Persist(car);
                    registrationState = "Maine";
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                  odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    color                  = "Red";
                    maxPassengers          = 5;
                    fuelCapacity           = 50;
                    litresPer100Kilometers = 8;
                    modelYear              = new DateTime(2006, 1, 1);
                    brandName              = "Toyota";
                    modelName              = "Tacoma";
                    maxSpeed               = 210;
                    odometer               = 50000;
                    registrationState      = "Texas";
                    registrationPlate      = "TX343433";
                    insurancePolicy        = "CAA7878777";
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                  odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    color                  = "Black";
                    maxPassengers          = 5;
                    fuelCapacity           = 60;
                    litresPer100Kilometers = 3;
                    modelYear              = new DateTime(2001, 1, 1);
                    brandName              = "Lincoln";
                    modelName              = "Town Car";
                    maxSpeed               = 220;
                    odometer               = 250000;
                    registrationState      = "Texas";
                    registrationPlate      = "TX543433";
                    insurancePolicy        = "CAA7878775";
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                  odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.BeginRead();
                    Console.WriteLine("Blue Cars");
                    BTreeSet <Car> bTree = session.Index <Car>("color");
                    foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    Console.WriteLine("Cars in fuel efficiency order");
                    foreach (Car c in session.Index <Car>("litresPer100Kilometers"))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color");
                    foreach (Vehicle v in session.Index <Vehicle>())
                    {
                        Console.WriteLine(v.ToStringDetails(session));
                    }
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    session.BeginUpdate();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                    c.Color = "Green";
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    session.BeginUpdate();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Car    c  = (from aCar in session.Index <Car>("color") where aCar.Color == "Green" select aCar).First();
                    UInt64 id = c.Id;
                    session.DeleteObject(id);
                    session.Abort();
                    session.BeginUpdate();
                    session.DeleteObject(id);
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Console.WriteLine("Blue Cars");
                    foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    for (int i = 0; i < 10000; i++)
                    { // add some junk to make search harder
                        car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i,
                                      odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy);
                        session.Persist(car);
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Console.WriteLine("Blue Cars");
                    foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                    c.Unpersist(session);
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    foreach (Car c in session.Index <Car>())
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    Console.WriteLine("Blue Cars");
                    foreach (Car c in (from aCar in session.Index <Car>() where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    InsuranceCompany prior = insuranceCompany;
                    try
                    {
                        for (int i = 0; i < 100000; i++)
                        {
                            insuranceCompany = new InsuranceCompany("AAA", "858787878");
                            session.Persist(insuranceCompany);
                        }
                        Debug.Assert(false); // should not get here
                    }
                    catch (UniqueConstraintException)
                    {
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
                    var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                    foreach (InsuranceCompany company in q)
                    {
                        Console.WriteLine(company.ToStringDetails(session)); // only one will match
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }

                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    Customer joe = new Customer("Joe");
                    session.Persist(joe);
                    Customer karim = new Customer("Karim");
                    session.Persist(karim);
                    Customer tony = new Customer("Tony");
                    session.Persist(tony);
                    Customer wayne = new Customer("Wayne");
                    session.Persist(wayne);
                    Order   order   = new Order(joe);
                    Payment payment = new Payment(order);
                    order   = new Order(karim);
                    payment = new Payment(order);
                    payment = new Payment(order);
                    payment = new Payment(order);
                    order   = new Order(tony);
                    payment = new Payment(order);
                    payment = new Payment(order);
                    order   = new Order(wayne);
                    payment = new Payment(order);
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }

                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    var karim                = (from customer in session.Index <Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
                    var karimOrders          = karim.Orders;
                    var karimOrderFromOrders = (from order in session.Index <Order>("m_customer") where order.Customer == karim select order).ToArray();
                    session.Commit();
                    session.BeginUpdate();
                    karim = (from customer in session.Index <Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
                    karim.StreetAddress = "1623 Bonita Ave";
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #12
0
        public void CreateDataAndIterateDb(int numObj)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.Verify();
                session.Commit();
                session.BeginUpdate();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
                Database db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
                db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.Verify();
                session.Commit();
                session.BeginUpdate();
                UInt32    dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                Placement place = new Placement(dbNum, 100);
                for (int i = 0; i < numObj; i++)
                {
                    NotSharingPage ns = new NotSharingPage();
                    session.Persist(ns);
                    SharingPageTypeA sA = new SharingPageTypeA();
                    session.Persist(sA);
                    SharingPageTypeB sB = new SharingPageTypeB();
                    if (i % 5 == 0)
                    {
                        sB.Persist(session, place);
                    }
                    else if (i % 1001 == 0)
                    {
                        sB.Persist(session, sA);
                    }
                    else if (i % 3001 == 0)
                    {
                        sB.Persist(session, ns);
                    }
                    else
                    {
                        session.Persist(sB);
                    }
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.Verify();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
                Database db    = session.OpenDatabase(dbNum);
                AllObjects <NotSharingPage> all = db.AllObjects <NotSharingPage>();
                int ct = all.Count();
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
                OfType ofType = db.OfType(typeof(NotSharingPage));
                int    ct2    = (int)ofType.Count;
                Assert.AreEqual(ct, ct2);
                Database dbA = session.OpenDatabase(dbNum);
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                Database dbB = session.OpenDatabase(dbNum);
                AllObjects <SharingPageTypeA> allA = dbA.AllObjects <SharingPageTypeA>();
                AllObjects <SharingPageTypeB> allB = dbB.AllObjects <SharingPageTypeB>();
                OfType           allA2             = dbA.OfType(typeof(SharingPageTypeA));
                int              start             = numObj / 2;
                NotSharingPage   ns  = all.ElementAt(numObj);
                SharingPageTypeA sA  = allA.ElementAt(numObj);
                SharingPageTypeA sA2 = (SharingPageTypeA)allA2.ElementAt(numObj);
                Assert.AreEqual(sA, sA2);
                sA  = allA.ElementAt(10);
                sA2 = (SharingPageTypeA)allA2.ElementAt(10);
                Assert.AreEqual(sA, sA2);
                //MethodInfo method = typeof(Database).GetMethod("AllObjects");
                //MethodInfo generic = method.MakeGenericMethod(sA.GetType());
                //dynamic itr = generic.Invoke(dbA, new object[]{ true });
                //SharingPageTypeA sAb = itr.ElementAt(numObj);
                //Assert.AreEqual(sA, sAb);
                //SharingPageTypeA sAc = itr.ElementAt(numObj);
                SharingPageTypeB        sB = allB.ElementAt(numObj);
                List <NotSharingPage>   notSharingPageList = all.Skip(100).ToList();
                List <SharingPageTypeA> sharingPageTypeA   = allA.Take(5).Skip(100).ToList();
                for (int i = start; i < numObj; i++)
                {
                    sA = allA.ElementAt(i);
                }
                for (int i = start; i < numObj; i += 5)
                {
                    ns = all.ElementAt(i);
                }
                for (int i = start; i < numObj; i += 5)
                {
                    sB = allB.ElementAt(i);
                }
                for (int i = 0; i < numObj; i += 45000)
                {
                    ns = all.ElementAt(i);
                }
                int allB_count = allB.Count();
                for (int i = 0; i < allB_count - 1; i++)
                {
                    Assert.NotNull(allB.ElementAt(i));
                }
                session.Commit();
                session.BeginUpdate();
                session.DeleteDatabase(db);
                session.DeleteDatabase(dbA);
                session.DeleteDatabase(dbB);
                session.Commit();
            }
        }
Пример #13
0
        public void CreateDataAndIterateSession(int numObj)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
                Database db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
                db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                db    = session.OpenDatabase(dbNum, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                UInt32    dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                Placement place = new Placement(dbNum, 100);
                for (int i = 0; i < numObj; i++)
                {
                    NotSharingPage ns = new NotSharingPage();
                    session.Persist(ns);
                    SharingPageTypeA sA = new SharingPageTypeA();
                    session.Persist(sA);
                    SharingPageTypeB sB = new SharingPageTypeB();
                    if (i % 5 == 0)
                    {
                        sB.Persist(session, place);
                    }
                    else if (i % 1001 == 0)
                    {
                        sB.Persist(session, sA);
                    }
                    else if (i % 3001 == 0)
                    {
                        sB.Persist(session, ns);
                    }
                    else
                    {
                        session.Persist(sB);
                    }
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
                Database db    = session.OpenDatabase(dbNum);
                AllObjects <NotSharingPage> all = session.AllObjects <NotSharingPage>(true, false);
                OfType all2 = session.OfType(typeof(NotSharingPage), true, false);
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
                Database dbA = session.OpenDatabase(dbNum);
                dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
                Database dbB = session.OpenDatabase(dbNum);
                AllObjects <SharingPageTypeA> allA = session.AllObjects <SharingPageTypeA>(true, false);
                AllObjects <SharingPageTypeB> allB = session.AllObjects <SharingPageTypeB>(true, false);
                int            start = numObj / 2;
                NotSharingPage ns    = all.ElementAt(numObj);
                NotSharingPage ns2   = (NotSharingPage)all2.ElementAt(numObj);
                Assert.AreEqual(ns, ns2);
                SharingPageTypeA sA = allA.ElementAt(15);
                SharingPageTypeB sB = allB.ElementAt(10);
                for (int i = start; i < numObj; i++)
                {
                    ns = all.ElementAt(i);
                }
                //for (int i = start; i < numObj; i++)
                //  ns = all.Skip(i).T
                //for (int i = start; i < numObj; i++)
                //  sA = allA.ElementAt(i);
                all.Skip(100);
                all2.Skip(100);
                for (int i = start; i < numObj; i += 5)
                {
                    ns  = all.ElementAt(i);
                    ns2 = (NotSharingPage)all2.ElementAt(i);
                    Assert.AreEqual(ns, ns2);
                }
                for (int i = 5; i < 100; i += 5)
                {
                    sB = allB.ElementAt(i);
                }
                for (int i = 0; i < numObj; i += 45000)
                {
                    ns = all.ElementAt(i);
                }
                session.Commit();
                session.BeginUpdate();
                session.DeleteDatabase(db);
                session.DeleteDatabase(dbA);
                session.DeleteDatabase(dbB);
                session.Commit();
            }
        }
Пример #14
0
    public void CreateDataAndIterateSession(int numObj)
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Placement place = new Placement(dbNum, 100);
        for (int i = 0; i < numObj; i++)
        {
          NotSharingPage ns = new NotSharingPage();
          session.Persist(ns);
          SharingPageTypeA sA = new SharingPageTypeA();
          session.Persist(sA);
          SharingPageTypeB sB = new SharingPageTypeB();
          if (i % 5 == 0)
            sB.Persist(session, place);
          else if (i % 1001 == 0)
            sB.Persist(session, sA);
          else if (i % 3001 == 0)
            sB.Persist(session, ns);
          else
            session.Persist(sB);
        }
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum);
        AllObjects<NotSharingPage> all = session.AllObjects<NotSharingPage>(true, false);
        OfType all2 = session.OfType(typeof(NotSharingPage), true, false);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        Database dbA = session.OpenDatabase(dbNum);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Database dbB = session.OpenDatabase(dbNum);
        AllObjects<SharingPageTypeA> allA = session.AllObjects<SharingPageTypeA>(true, false);
        AllObjects<SharingPageTypeB> allB = session.AllObjects<SharingPageTypeB>(true, false);
        int start = numObj / 2;
        NotSharingPage ns = all.ElementAt(numObj - 1); // zero based index so deduct one
        NotSharingPage ns2 = (NotSharingPage)all2.ElementAt(numObj - 1);
        Assert.AreEqual(ns, ns2);
        SharingPageTypeA sA = allA.ElementAt(15);
        SharingPageTypeB sB = allB.ElementAt(10);
        for (int i = start; i < numObj; i++)
          ns = all.ElementAt(i);
        //for (int i = start; i < numObj; i++)
        //  ns = all.Skip(i).T
        //for (int i = start; i < numObj; i++)
        //  sA = allA.ElementAt(i);
        all.Skip(100);
        all2.Skip(100);
        for (int i = start; i < numObj; i += 5)
        {
          ns = all.ElementAt(i);
          ns2 = (NotSharingPage)all2.ElementAt(i);
          Assert.AreEqual(ns, ns2);
        }
        for (int i = 5; i < 100; i += 5)
          sB = allB.ElementAt(i);
        for (int i = 0; i < numObj; i += 45000)
          ns = all.ElementAt(i);
        session.Commit();
        session.BeginUpdate();
        session.DeleteDatabase(db);
        session.DeleteDatabase(dbA);
        session.DeleteDatabase(dbB);
        session.Commit();
      }
    }
Пример #15
0
    public void CreateDataAndIterateDb(int numObj)
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.Verify();
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        db = session.OpenDatabase(dbNum, true, false);
        if (db != null)
          session.DeleteDatabase(db);
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.Verify();
        session.BeginUpdate();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Placement place = new Placement(dbNum, 100);
        for (int i = 0; i < numObj; i++)
        {
          NotSharingPage ns = new NotSharingPage();
          session.Persist(ns);
          SharingPageTypeA sA = new SharingPageTypeA();
          session.Persist(sA);
          SharingPageTypeB sB = new SharingPageTypeB();
          if (i % 5 == 0)
            sB.Persist(session, place);
          else if (i % 1001 == 0)
            sB.Persist(session, sA);
          else if (i % 3001 == 0)
            sB.Persist(session, ns);
          else
            session.Persist(sB);
        }
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        session.Verify();
        UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage));
        Database db = session.OpenDatabase(dbNum);
        AllObjects<NotSharingPage> all = db.AllObjects<NotSharingPage>();
        ulong ct = all.Count();
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA));
        OfType ofType = db.OfType(typeof(NotSharingPage));
        ulong ct2 = ofType.Count();
        Assert.AreEqual(ct, ct2);
        Database dbA = session.OpenDatabase(dbNum);
        dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB));
        Database dbB = session.OpenDatabase(dbNum);
        AllObjects<SharingPageTypeA> allA = dbA.AllObjects<SharingPageTypeA>();
        AllObjects<SharingPageTypeB> allB = dbB.AllObjects<SharingPageTypeB>();
        OfType allA2 = dbA.OfType(typeof(SharingPageTypeA));
        int start = numObj / 2;
        NotSharingPage ns = all.ElementAt(numObj);
        SharingPageTypeA sA = allA.ElementAt(numObj);
        SharingPageTypeA sA2 = (SharingPageTypeA)allA2.ElementAt(numObj);
        Assert.AreEqual(sA, sA2);
        sA = allA.ElementAt(10);
        sA2 = (SharingPageTypeA)allA2.ElementAt(10);
        Assert.AreEqual(sA, sA2);
        //MethodInfo method = typeof(Database).GetMethod("AllObjects");
        //MethodInfo generic = method.MakeGenericMethod(sA.GetType());
        //dynamic itr = generic.Invoke(dbA, new object[]{ true });
        //SharingPageTypeA sAb = itr.ElementAt(numObj);
        //Assert.AreEqual(sA, sAb);
        //SharingPageTypeA sAc = itr.ElementAt(numObj);
        SharingPageTypeB sB = allB.ElementAt(numObj);
        List<NotSharingPage> notSharingPageList = all.Skip(100).ToList();
        List<SharingPageTypeA> sharingPageTypeA = allA.Take(5).Skip(100).ToList();
        for (int i = start; i < numObj; i++)
          sA = allA.ElementAt(i);
        for (int i = start; i < numObj; i += 5)
          ns = all.ElementAt(i);
        for (int i = start; i < numObj; i += 5)
          sB = allB.ElementAt(i);
        for (int i = 0; i < numObj; i += 45000)
          ns = all.ElementAt(i);
        int allB_count = (int) allB.Count();
        for (int i = 0; i < allB_count - 1; i++)
        {
          Assert.NotNull(allB.ElementAt(i));
        }
        session.Commit();
        session.BeginUpdate();
        session.DeleteDatabase(db);
        session.DeleteDatabase(dbA);
        session.DeleteDatabase(dbB);
        session.Commit();
      }
    }
Пример #16
0
    public void bSyncDeletedDatabases()
    {
      using (SessionBase session = new SessionNoServer(s_sync1))
      {
        using (var trans = session.BeginUpdate())
        {
          for (uint i = 10; i < 14; i++)
          {
            var database = session.OpenDatabase(i);
            session.DeleteDatabase(database);
          }
          session.Commit();
        }
      }

      using (SessionBase readFromSession = new SessionNoServer(s_sync1))
      {
        using (SessionBase updateSession = new SessionNoServer(s_sync2))
        {
          updateSession.SyncWith(readFromSession);
        }
      }

      using (SessionBase readFromSession = new SessionNoServer(s_sync1))
      {
        readFromSession.BeginRead();
        using (SessionBase updateSession = new SessionNoServer(s_sync2))
        {
          using (var trans = updateSession.BeginRead())
          {
            Assert.AreEqual(updateSession.OpenAllDatabases().Count, readFromSession.OpenAllDatabases().Count - 1); // - 1 due to additional change tracking databases in original 
          }
        }
      }
    }
Пример #17
0
 [TestCase(false)] // test will fail if pessimistic locking is used
 public void SingleReaderSingleUpdater4(bool useReaderCommit)
 {
   using (SessionNoServer updater = new SessionNoServer(systemDir, 5000)) 
   using (SessionNoServer reader = new SessionNoServer(systemDir, 5000))
   {
     updater.SetTraceAllDbActivity();
     reader.SetTraceAllDbActivity();
     updater.BeginUpdate();
     UInt32 dbNum = updater.DatabaseNumberOf(typeof(Man));
     Database db = updater.OpenDatabase(dbNum, true, false);
     if (db != null)
       updater.DeleteDatabase(db);
     updater.Commit();
     updater.BeginUpdate();
     Man man = new Man();
     for (int i = 0; i < 100; i++)
     {
       man = new Man();
       updater.Persist(man);
     }
     updater.Commit();
     reader.BeginRead();
     updater.BeginUpdate();
     db = reader.OpenDatabase(dbNum);
     foreach (Page page in db)
       Assert.True(page.PageInfo.VersionNumber == 1);
     if (useReaderCommit)
       reader.Commit();
     if (useReaderCommit)
       reader.BeginRead();
     else
       reader.ForceDatabaseCacheValidation();
     for (int i = 1; i < 25; i++)
     {
       db = reader.OpenDatabase(dbNum);
       foreach (Page page in db)
       {
         if (page.PageNumber > 1) // skip AutoPlacemnt page
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       if (useReaderCommit)
       {
         reader.Commit();
         reader.BeginRead();
       }
       else
         reader.ForceDatabaseCacheValidation();
       updater.Commit();
       updater.BeginUpdate();
     }
     Database db2 = reader.OpenDatabase(dbNum);
     db = updater.OpenDatabase(dbNum);
     for (int i = 25; i < 50; i++)
     {
       foreach (Page page in db)
       {
         if (page.PageNumber > 1)
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       updater.Commit();
       updater.BeginUpdate();
       db2 = reader.OpenDatabase(dbNum);
       foreach (Page page in db2)
       {
         if (page.PageNumber > 1)
         {
           //Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
         }
       }
       reader.ClearPageCache();
       System.GC.Collect();
     }
     reader.Commit();
     updater.Commit();
   }
 }
Пример #18
0
 [TestCase(false)] // test will fail if pessimistic locking is used
 public void SingleReaderSingleUpdater4(bool useReaderCommit)
 {
     using (SessionNoServer updater = new SessionNoServer(systemDir, 5000))
         using (SessionNoServer reader = new SessionNoServer(systemDir, 5000))
         {
             updater.SetTraceAllDbActivity();
             reader.SetTraceAllDbActivity();
             updater.BeginUpdate();
             UInt32   dbNum = updater.DatabaseNumberOf(typeof(Man));
             Database db    = updater.OpenDatabase(dbNum, true, false);
             if (db != null)
             {
                 updater.DeleteDatabase(db);
             }
             updater.Commit();
             updater.BeginUpdate();
             Man man = new Man();
             for (int i = 0; i < 100; i++)
             {
                 man = new Man();
                 updater.Persist(man);
             }
             updater.Commit();
             reader.BeginRead();
             updater.BeginUpdate();
             db = reader.OpenDatabase(dbNum);
             foreach (Page page in db)
             {
                 Assert.True(page.PageInfo.VersionNumber == 1);
             }
             if (useReaderCommit)
             {
                 reader.Commit();
             }
             if (useReaderCommit)
             {
                 reader.BeginRead();
             }
             else
             {
                 reader.ForceDatabaseCacheValidation();
             }
             for (int i = 1; i < 25; i++)
             {
                 db = reader.OpenDatabase(dbNum);
                 foreach (Page page in db)
                 {
                     if (page.PageNumber > 1) // skip AutoPlacemnt page
                     {
                         Assert.True(page.PageInfo.VersionNumber == (ulong)i);
                         Man man2       = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
                         Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
                     }
                 }
                 if (useReaderCommit)
                 {
                     reader.Commit();
                     reader.BeginRead();
                 }
                 else
                 {
                     reader.ForceDatabaseCacheValidation();
                 }
                 updater.Commit();
                 updater.BeginUpdate();
             }
             Database db2 = reader.OpenDatabase(dbNum);
             db = updater.OpenDatabase(dbNum);
             for (int i = 25; i < 50; i++)
             {
                 foreach (Page page in db)
                 {
                     if (page.PageNumber > 1)
                     {
                         Assert.True(page.PageInfo.VersionNumber == (ulong)i);
                         Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
                     }
                 }
                 updater.Commit();
                 updater.BeginUpdate();
                 db2 = reader.OpenDatabase(dbNum);
                 foreach (Page page in db2)
                 {
                     if (page.PageNumber > 1)
                     {
                         //Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1);
                         Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
                     }
                 }
                 reader.ClearPageCache();
                 System.GC.Collect();
             }
             reader.Commit();
             updater.Commit();
         }
 }