Example #1
0
 static void createInvertedIndex()
 {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         session.BeginUpdate();
         session.EnableAutoPageFlush = false; // so that threads don't stomb on each other
         Console.WriteLine(DateTime.Now.ToString() + ", start creating inverted index");
         ParallelOptions pOptions = new ParallelOptions();
         pOptions.MaxDegreeOfParallelism = 2; // set to what is appropriate for your computer (cores & memory size)
         //pOptions.MaxDegreeOfParallelism = 1; // appears to work best with only 16GB of memory
         IndexRoot           indexRoot   = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
         BTreeSet <Document> documentSet = indexRoot.repository.documentSet;
         List <Database>     dbs         = session.OpenAllDatabases(true);
         Parallel.ForEach <Database>(dbs, pOptions,
                                     (Database db, ParallelLoopState loop) => // method invoked by the loop on each iteration
         {
             if (db.DatabaseNumber >= Document.PlaceInDatabase)
             {
                 createDocumentInvertedIndex(session, db, documentSet);
             }
         });
         session.Commit();
         Console.WriteLine(DateTime.Now.ToString() + ", done creating inverted index");
     }
 }
Example #2
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
                    }
                }
            }
        }
 /// <summary>
 /// Get a list of all <see cref="Database"/> used.
 /// </summary>
 /// <param name="path">Path to database directory on server relative to server setting <see cref="SessionBase.BaseDatabasePath"/></param>
 /// <returns>All databases in use</returns>
 public IEnumerable<string> Get(string path)
 {
   using (SessionNoServer session = new SessionNoServer(path))
   {
     session.BeginRead();
     List<Database> dbList = session.OpenAllDatabases();
     foreach (Database db in dbList)
       yield return db.ToString();
     session.Commit();
   }
 }
Example #4
0
 /// <summary>
 /// Get a list of all <see cref="Database"/> used.
 /// </summary>
 /// <param name="path">Path to database directory on server relative to server setting <see cref="SessionBase.BaseDatabasePath"/></param>
 /// <returns>All databases in use</returns>
 public IEnumerable <string> Get(string path)
 {
     using (SessionNoServer session = new SessionNoServer(path))
     {
         session.BeginRead();
         List <Database> dbList = session.OpenAllDatabases();
         foreach (Database db in dbList)
         {
             yield return(db.ToString());
         }
         session.Commit();
     }
 }
Example #5
0
    public void aSyncNewDatabases()
    {
      using (SessionBase session = new SessionNoServer(s_sync1))
      {
        session.EnableSyncByTrackingChanges = true;
        using (var trans = session.BeginUpdate())
        {
          for (uint i = 10; i < 50; i++)
          {
            var database = session.NewDatabase(i);
            Assert.NotNull(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 
          }
        }
      }
    }
Example #6
0
        public void aSyncNewDatabases()
        {
            using (var session = new SessionNoServerShared(s_sync1))
            {
                session.EnableSyncByTrackingChanges = true;
                using (var trans = session.BeginUpdate())
                {
                    for (uint i = 10; i < 50; i++)
                    {
                        var database = session.NewDatabase(i);
                        Assert.NotNull(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
                    }
                }
            }
        }
Example #7
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 
          }
        }
      }
    }
Example #8
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("ERROR, no boot path specified. Restart Verify and add bootup database path as a command line parameter");
                return(1);
            }
            int ct = 0;

            try
            {
                using (SessionNoServer session = new SessionNoServer(args[0]))
                {
                    DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case
                    session.BeginRead();
                    List <Database> dbList = session.OpenAllDatabases();
                    foreach (Database db in dbList)
                    {
                        foreach (Page page in db)
                        {
                            foreach (IOptimizedPersistable iPers in page)
                            {
                                object obj = iPers.GetWrappedObject();
                                ++ct;
                                if (iPers.GetWrappedObject() is IOptimizedPersistable)
                                {
                                    UInt64 id = iPers.Id;
                                    OptimizedPersistable pObj = iPers as OptimizedPersistable;
                                    if (pObj != null)
                                    {
                                        session.LoadFields(pObj);
                                        foreach (OptimizedPersistable fObj in pObj.OptimizedPersistableFieldValues())
                                        {
                                            session.LoadFields(fObj);
                                        }
                                        foreach (object value in pObj.GetFieldValues())
                                        {
                                            WeakIOptimizedPersistableReferenceBase weakRef = value as WeakIOptimizedPersistableReferenceBase;
                                            if (weakRef != null)
                                            {
                                                if (session.Open(weakRef.Id) == null)
                                                {
                                                    throw new UnexpectedException("WeakRefence object is null");
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (obj is string)
                                {
                                    continue;
                                }
                                else if (obj is Array)
                                {
                                    continue;
                                }
                                IEnumerable anEnum = obj as IEnumerable;
                                if (anEnum != null)
                                {
                                    foreach (object o in anEnum)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    session.Commit();
                }
                Console.WriteLine("OK, verfied " + ct + " objects");
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("FAILED, verfied " + ct + " objects");
                Console.WriteLine(ex.ToString());
                return(-1);
            }
        }
Example #9
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());
            }
        }
Example #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());
      }
    }
Example #11
0
 static int Main(string[] args)
 {
   if (args.Length == 0)
   {
     System.Console.WriteLine("ERROR, no boot path specified. Restart Verify and add bootup database path as a command line parameter");
     return 1;
   }
   int ct = 0;
   try
   {
     using (SessionNoServer session = new SessionNoServer(args[0]))
     {
       DataCache.MaximumMemoryUse = 5000000000; // 5 GB, set this to what fits your case
       session.BeginRead();
       List<Database> dbList = session.OpenAllDatabases();
       foreach (Database db in dbList)
         foreach (Page page in db)
           foreach (IOptimizedPersistable iPers in page)
           {
             object obj = iPers.WrappedObject;
             ++ct;
             if (iPers.WrappedObject is IOptimizedPersistable)
             {
               UInt64 id = iPers.Id;
               OptimizedPersistable pObj = iPers as OptimizedPersistable;
               if (pObj != null)
               {
                 pObj.LoadFields();
                 foreach (OptimizedPersistable fObj in pObj.OptimizedPersistableFieldValues())
                 {
                   fObj.LoadFields();
                 }
                 foreach (object value in pObj.GetFieldValues())
                 {
                   WeakIOptimizedPersistableReferenceBase weakRef = value as WeakIOptimizedPersistableReferenceBase;
                   if (weakRef != null)
                     if (session.Open(weakRef.Id) == null)
                       throw new UnexpectedException("WeakRefence object is null");
                 }
               }
             }
             else if (obj is string)
               continue;
             else if (obj is Array)
               continue;
             IEnumerable anEnum = obj as IEnumerable;
             if (anEnum != null)
               foreach (object o in anEnum)
               {
               }
           }
       session.Commit();
     }
     Console.WriteLine("OK, verfied " + ct + " objects");
     return 0;
   }
   catch (Exception ex)
   {
     Console.WriteLine("FAILED, verfied " + ct + " objects");
     Console.WriteLine(ex.ToString());
     return -1;
   }
 }
Example #12
0
 static void createInvertedIndex()
 {
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginUpdate();
     session.EnableAutoPageFlush = false; // so that threads don't stomb on each other
     Console.WriteLine(DateTime.Now.ToString() + ", start creating inverted index");
     ParallelOptions pOptions = new ParallelOptions();
     pOptions.MaxDegreeOfParallelism = 2; // set to what is appropriate for your computer (cores & memory size)
     //pOptions.MaxDegreeOfParallelism = 1; // appears to work best with only 16GB of memory
     IndexRoot indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
     BTreeSet<Document> documentSet = indexRoot.repository.documentSet;
     List<Database> dbs = session.OpenAllDatabases(true);
     Parallel.ForEach<Database>(dbs, pOptions,
       (Database db, ParallelLoopState loop) => // method invoked by the loop on each iteration
       {
         if (db.DatabaseNumber >= Document.PlaceInDatabase)
           createDocumentInvertedIndex(session, db, documentSet);
       });
     session.Commit();
     Console.WriteLine(DateTime.Now.ToString() + ", done creating inverted index");
   }
 }