Пример #1
0
    static readonly string s_systemDir = "JsonExportImport"; // appended to SessionBase.BaseDatabasePath

    static void Main(string[] args)
    {
      try
      {
        int personCt = 0;
        using (SessionBase session = new SessionNoServer(s_systemDirToImport))
        {
          session.BeginRead();
          IEnumerable<string> personStringEnum = session.ExportToJson<Person>();
          using (SessionBase sessionImport = new SessionNoServer(s_systemDir))
          {
            sessionImport.BeginUpdate();
            foreach (string json in personStringEnum)
            {
              Person person = sessionImport.ImportJson<Person>(json);
              sessionImport.Persist(person);
              personCt++;
            }
            session.Commit();
            sessionImport.Commit();
            Console.WriteLine("Imported " + personCt + " from Json strings");
          }
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }
Пример #2
0
        public void aaaE_Chris()
        {
            var person = new PersonChris()
            {
                Name    = "John",
                Address = "123 Blah St"
            };

            using (var session1 = new SessionNoServer(s_systemDir))
            {
                // Persist instance of Person within transaction
                session1.BeginUpdate();
                session1.Persist(person);
                session1.Commit();

                // Create new transaction and make changes to Person and add child object Job
                session1.BeginUpdate();
                person.Name = "Bob";
                person.Jobs.Add(new Job {
                    Name = "clean house"
                });

                // Do not commit previous transaction (keep open) and attempt to read person using another session and a read transaction
                using (var session2 = new SessionNoServer(s_systemDir))
                {
                    session2.BeginRead();
                    uint     dbNum   = session2.DatabaseNumberOf(typeof(PersonChris));
                    Database db      = session2.OpenDatabase(dbNum);
                    var      person1 = db.AllObjects <PersonChris>().First(); // IOException is thrown here
                    session2.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();
   }
 }
Пример #4
0
 public void SingleReaderSingleUpdater1()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     Man man = new Man();
     man.Persist(session, man);
     session.Commit();
   }
   UInt64 id;
   using (SessionNoServer session = new SessionNoServer(systemDir, 5000))
   {
     session.BeginUpdate();
     Man man = new Man();
     man.Persist(session, man);
     id = man.Id;
     using (SessionNoServer session2 = new SessionNoServer(systemDir))
     {
       session2.BeginRead();
       Man man2 = (Man)session2.Open(id);
       Assert.Null(man2);
       session2.Commit();
     }
     session.Commit();
   }
 }
Пример #5
0
 public MainWindow()
 {
   InitializeComponent();
   if (Directory.Exists(systemDir))
     Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
   try
   {
     session = new SessionBase[4];
     thread = new Thread[4];
     session[0] = new SessionNoServer(systemDir, int.Parse(session1LockTimeout.Text));
     session[1] = new SessionNoServer(systemDir, int.Parse(session2LockTimeout.Text));
     session[2] = new SessionNoServer(systemDir, int.Parse(session3LockTimeout.Text));
     session[3] = new SessionNoServer(systemDir, int.Parse(session4LockTimeout.Text));
     session[0].BeginUpdate();
     Placement place = new Placement(10);
     Number number = new Number();
     session[0].Persist(place, number);
     number = new Number(2);
     place = new Placement(11);
     session[0].Persist(place, number);
     number = new Number(3);
     place = new Placement(12);
     session[0].Persist(place, number);
     session[0].Commit();
   }
   catch (Exception ex)
   {
     session1messages.Content = ex.Message;
   }
 }
Пример #6
0
 static void Main(string[] args)
 {
   CreateData();
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginRead();
     int ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 10000).Count;
     Console.WriteLine($@"GeoObj located in San Diego by 10000 meter radius: {ct}");
     ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 100000).Count;
     Console.WriteLine($@"GeoObj located in San Diego by 100000 meter radius: {ct}");
     ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 10000).Count;
     Console.WriteLine($@"GeoObj located in New York City by 10000 meter radius: {ct}");
     ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 100000).Count;
     Console.WriteLine($@"GeoObj located in New York City by 100000 meter radius: {ct}");
     // Sweden bounding box
     ct = GeoHashQuery.SearchGeoHashIndex(session, 55.34, 10.96, 69.06, 24.17).Count;
     Console.WriteLine($@"GeoObj located in Sweden: {ct}");
     // Alaska bounding box
     ct = GeoHashQuery.SearchGeoHashIndex(session, 51.21, -169.01, 71.39, -129.99).Count;
     Console.WriteLine($@"GeoObj located in Alaska: {ct}");
     // California bounding box
     ct = GeoHashQuery.SearchGeoHashIndex(session, 32.53, -124.42, 42.01, -114.13).Count;
     Console.WriteLine($@"GeoObj located in California: {ct}");
     // USA bounding box
     //GeoHashQuery.SearchGeoHashIndex(session, 18.9, -67.0, 71.4, 172.4);
     //Console.WriteLine($@"Persons located in USA: {ct}");
   }
 }
Пример #7
0
 static void CreateData()
 {
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     bool dirExist = Directory.Exists(session.SystemDirectory);
     if (dirExist)
       Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
     Directory.CreateDirectory(session.SystemDirectory);
     File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
     DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case
     SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
     session.BeginUpdate();
     BTreeMap<Int64, VelocityDbList<Person>> btreeMap = new BTreeMap<Int64, VelocityDbList<Person>>(null, session);
     session.Persist(btreeMap);
     for (int i = 0; i < 100000; i++)
     {
       Person p = new Person();
       GeoHash geohash = GeoHash.WithBitPrecision(p.Lattitude, p.Longitude);
       VelocityDbList<Person> personList;
       if (btreeMap.TryGetValue(geohash.LongValue, out personList))
         personList.Add(p);
       else
       {
         personList = new VelocityDbList<Person>(1);
         //session.Persist(p);
         personList.Add(p);
         session.Persist(personList);
         btreeMap.Add(geohash.LongValue, personList);
       }
     }
     session.Commit();
   }
 }
Пример #8
0
 static void CreateData()
 {
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     bool dirExist = Directory.Exists(session.SystemDirectory);
     if (dirExist)
     {
       return;
       Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
     }
     Directory.CreateDirectory(session.SystemDirectory);
     File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
     SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
     session.BeginUpdate();
     CompareGeoObj comparer = new CompareGeoObj();
     var btreeSet = new BTreeSet<GeoObj>(comparer, session, 1000);
     for (int i = 0; i < s_numberOfSamples; i++)
     {
       var g = new GeoObj();
       btreeSet.Add(g);
     }
     session.Persist(btreeSet);
     session.Commit();
     Console.Out.WriteLine($@"Done creating {s_numberOfSamples} GeoHashSample GeoObj ");
   }
 }
Пример #9
0
 public void QuerySomeBicycles()
 {
     try
     {
         using (SessionNoServer session = new SessionNoServer(s_systemDir))
         {
             session.BeginRead();
             Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(Bicycle)));
             Bicycle  b1 = db.AllObjects <Bicycle>().ElementAt(50005);
             Bicycle  b2 = db.AllObjects <Bicycle>().ElementAt <Bicycle>(50005);
             if (b1 != b2)
             {
                 throw new UnexpectedException("b1 != b2");
             }
             var src = from Bicycle bike in db.AllObjects <Bicycle>() where bike.Color == "blue" select bike;
             foreach (Bicycle bike in src)
             {
                 Console.WriteLine(bike.ToStringDetails(session));
             }
             session.Commit();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Пример #10
0
        void BtnOkClick(object pSender, RoutedEventArgs pEvents)
        {
            m_federationInfo.UsesServerClient      = (bool)RadioServer.IsChecked;
            m_federationInfo.ClassesFilenames      = (from ListViewItem lItem in AssemblyList.Items select(string) lItem.Content).ToArray();
            m_federationInfo.DependencyFiles       = (from ListViewItem lItem in DependencyList.Items select(string) lItem.Content).ToArray();
            m_federationInfo.SystemDbsPath         = DBDirTextBox.Text;
            m_federationInfo.HostName              = HostTextBox.Text;
            m_federationInfo.UsePessimisticLocking = (bool)PessimisticBox.IsChecked;
            m_federationInfo.WindowsAuthentication = (bool)WindowsAuthenticationBox.IsChecked;
            bool createNew = (bool)CreateNewBox.IsChecked;

            if (createNew)
            {
                SessionBase session;
                if (m_federationInfo.UsesServerClient || (m_federationInfo.HostName.Length > 0 && m_federationInfo.HostName != Dns.GetHostName()))
                {
                    session = new ServerClientSession(m_federationInfo.SystemDbsPath, m_federationInfo.HostName);
                }
                else
                {
                    session = new SessionNoServer(m_federationInfo.SystemDbsPath);
                }
                session.BeginUpdate();
                session.Commit();
            }
            DialogResult = true;
        }
Пример #11
0
 public void CompareString(int compArraySize)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     AllSupported obj = new AllSupported(1);
     CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("aString", session);
     BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, (ushort) compArraySize);
     for (int i = 0; i < 10000; i++)
     {
       obj = new AllSupported(1);
       obj.aString = RandomString(10);
       sortedSet.Add(obj);
     }
     obj = new AllSupported(1);
     obj.aString = null;
     sortedSet.Add(obj);
     int ct = 0;
     AllSupported prior = null;
     foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
     {
       if (prior != null)
       {
         if (prior.aString != null)
           if (currentObj.aString == null)
             Assert.Fail("Null is < than a non NULL");
           else
             Assert.Less(prior.aString, currentObj.aString);
       }
       prior = currentObj;
       ct++;
     }
     session.Commit();
   }
 }
Пример #12
0
            private void Save <T>()
                where T : DynamicDictionary, new()
            {
                using (SessionNoServer session = new SessionNoServer(SystemDir))
                {
                    dynamic person  = CreatePerson <T>();
                    dynamic person2 = CreatePerson2 <T>(person);

                    OutputProperties("Person", person);

                    OutputProperties("Person2", person2);

                    session.BeginUpdate();

                    _personId  = session.Persist(person);
                    _person2Id = session.Persist(person2);

                    if (typeof(T) == typeof(PersistableDynamicDictionary))
                    {
                        session.Persist(new PersistableDynamicDictionary()
                        {
                            TypeName = "Test", ["Test"] = "Hello"
                        });
                        session.Persist(new PersistableDynamicDictionary()
                        {
                            TypeName = "Test", ["Test"] = "World"
                        });
                    }

                    session.Commit();
                }
            }
Пример #13
0
            private void LoadByDynamicQuery()
            {
                using (SessionNoServer session = new SessionNoServer(SystemDir))
                {
                    Console.WriteLine("\nDynamic Query");

                    session.BeginRead();

                    // Query on the Dynamic Property, Iterates over AllObjects<T>
                    //  Note: This will throw an Exception if FirstName and LastName are not both defined on every DynamicDictionary.
                    dynamic dynamicQuery1 =
                        session.AllObjects <DynamicDictionary>()
                        .FirstOrDefault(x => x["FirstName"] == "Ellen" && x["LastName"] == "Adams");

                    // Avoids Exception but still Iterates over AllObjects<T>
                    dynamic dynamicQuery2 =
                        session.AllObjects <DynamicDictionary>()
                        .FirstOrDefault((x) =>
                    {
                        dynamic dynX = x;
                        return(dynX.ContainsProperty("FirstName") && dynX.ContainsProperty("LastName") &&
                               dynX.FirstName == "John" && dynX.LastName == "Doe");
                    });

                    // Dynamic Query Asserts
                    AssertPerson(dynamicQuery1);
                    AssertPerson2(dynamicQuery2);
                }
            }
Пример #14
0
    public void LocalDateTest()
    {
      LocalDate d1 = new LocalDate(2016, 1, 10);
      LocalDate d2 = new LocalDate(2016, 1, 1);
      LocalDate d1other = new LocalDate(2016, 1, 10);
      Assert.AreNotEqual(d1, d2);
      Assert.AreEqual(d1, d1other);

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        LocalDateField test1 = new LocalDateField("def", d1);
        session.Persist(test1);
        LocalDateField test = new LocalDateField("abc", d2);
        session.Persist(test);
        var result1 = session.AllObjects<LocalDateField>().First(t => t.Field2.Equals(d2)); // this works
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        var result2 = session.AllObjects<LocalDateField>().First(t => 
        {
          var l = t.Field2;
          return l.Equals(d2);
        }); // this should work and doesnt
        session.Commit();
      }
    }
Пример #15
0
 public void AddSomeBicycles()
 {
     try
     {
         using (SessionNoServer session = new SessionNoServer(s_systemDir))
         {
             session.BeginUpdate();
             for (int i = 0; i < 1000000; i++)
             {
                 Bicycle bicycle = new Bicycle();
                 bicycle.Color = "red";
                 session.Persist(bicycle);
             }
             for (int i = 0; i < 10; i++)
             {
                 Bicycle bicycle = new Bicycle();
                 bicycle.Color = "blue";
                 session.Persist(bicycle);
             }
             for (int i = 0; i < 10; i++)
             {
                 Bicycle bicycle = new Bicycle();
                 bicycle.Color = "yellow";
                 session.Persist(bicycle);
             }
             session.Commit();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Пример #16
0
 public void CompareInt64()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(2, session);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int64", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int64), true);
         for (int i = 0; i < 100000; i++)
         {
             obj       = new AllSupported(1, session);
             obj.int64 = randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next();
             sortedSet.Add(obj);
         }
         int ct = 0;
         //foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
         // {
         //  Console.WriteLine(currentObj.int32);
         //   ct++;
         // }
         AllSupported prior = null;
         ct = 0;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Less(prior.int64, currentObj.int64);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
Пример #17
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();
         }
     });
 }
Пример #18
0
 public void AddSomeBicycles()
 {
   try
   {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginUpdate();
       for (int i = 0; i < 1000000; i++)
       {
         Bicycle bicycle = new Bicycle();
         bicycle.Color = "red";
         session.Persist(bicycle);
       }
       for (int i = 0; i < 10; i++)
       {
         Bicycle bicycle = new Bicycle();
         bicycle.Color = "blue";
         session.Persist(bicycle);
       }
       for (int i = 0; i < 10; i++)
       {
         Bicycle bicycle = new Bicycle();
         bicycle.Color = "yellow";
         session.Persist(bicycle);
       }
       session.Commit();
     }      
   }
   catch (Exception ex)
   {
     Console.WriteLine(ex.ToString());
   }
 }    
Пример #19
0
    static readonly string systemDir = "Sample3"; // appended to SessionBase.BaseDatabasePath

    static void Main(string[] args)
    {
      try
      {
        using (SessionNoServer session = new SessionNoServer(systemDir))
        {
          Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
          session.BeginUpdate();
          Person robinHood = new Person("Robin", "Hood", 30);
          Person billGates = new Person("Bill", "Gates", 56, robinHood);
          Person steveJobs = new Person("Steve", "Jobs", 56, billGates);
          robinHood.BestFriend = billGates;
          session.Persist(steveJobs);
          steveJobs.Friends.Add(billGates);
          steveJobs.Friends.Add(robinHood);
          billGates.Friends.Add(billGates);
          robinHood.Friends.Add(steveJobs);
          session.Commit();
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }
Пример #20
0
 public void UnpersistCompareFields(int bTreeDatabaseNumber)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         BTreeSet <Person>         bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
         BTreeSetIterator <Person> itr   = bTree.Iterator();
         itr.GoToLast();
         itr.Remove();
         session.Abort();
         session.BeginUpdate();
         bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
         bTree.Unpersist(session);
         session.Commit();
         session.BeginRead();
         Database db = session.OpenDatabase((uint)bTreeDatabaseNumber, false);
         foreach (Page page in db)
         {
             foreach (OptimizedPersistable obj in page)
             {
                 if (obj.PageNumber > 0)
                 {
                     Assert.Fail("No objects should remain in this database");
                 }
             }
         }
         session.Commit();
     }
 }
Пример #21
0
        public void hashCodeComparerStringTest()
        {
            Oid id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                session.Compact();
                session.BeginUpdate();
                HashCodeComparer <string> hashCodeComparer = new HashCodeComparer <string>();
                BTreeSet <string>         bTree            = new BTreeSet <string>(hashCodeComparer, session);
                bTree.Persist(place, session);
                id = bTree.Oid;
                for (int i = 0; i < 100000; i++)
                {
                    bTree.Add(i.ToString());
                }
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSet <string> bTree = (BTreeSet <string>)session.Open(id);
                int count = 0;
                foreach (string str in bTree)
                {
                    count++;
                }
                Assert.True(100000 == count);
                session.Commit();
            }
        }
Пример #22
0
 public void LookupCompareFields(int bTreeDatabaseNumber)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         Person personPrior = null, person;
         session.BeginRead();
         BTreeSet <Person>         bTree = (BTreeSet <Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
         BTreeSetIterator <Person> itr   = bTree.Iterator();
         int ct = 0;
         while ((person = itr.Next()) != null)
         {
             if (personPrior != null)
             {
                 Assert.LessOrEqual(personPrior.FirstName, person.FirstName);
             }
             ct++;
             personPrior = person;
         }
         int ct2 = 0;
         personPrior = null;
         foreach (Person pers in (IEnumerable <Person>)bTree)
         {
             if (personPrior != null)
             {
                 Assert.LessOrEqual(personPrior.FirstName, pers.FirstName);
             }
             ct2++;
             personPrior = pers;
         }
         session.Commit();
         Assert.AreEqual(ct, ct2);
     }
 }
Пример #23
0
 public void CreateTicksCompareFields(int numberOfTicks, int nodeSize)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir, 2000, false))
     {
         //session.SetTraceAllDbActivity();
         session.BeginUpdate();
         CompareByField <Tick> compareByField = new CompareByField <Tick>("<Bid>k__BackingField", session, true);
         //compareByField.AddFieldToCompare("<Timestamp>k__BackingField");
         BTreeSet <Tick> bTree      = new BTreeSet <Tick>(compareByField, session, (UInt16)nodeSize, sizeof(double) + sizeof(UInt64), true);
         Placement       place      = new Placement((UInt32)numberOfTicks, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
         Placement       ticksPlace = new Placement((UInt32)numberOfTicks, 10000, 1, UInt16.MaxValue, UInt16.MaxValue);
         bTree.Persist(place, session);
         int i          = 0;
         int dublicates = 0;
         foreach (var record in Tick.GenerateRandom((ulong)numberOfTicks))
         {
             session.Persist(record, ticksPlace);
             if (bTree.Add(record))
             {
                 i++;
             }
             else
             {
                 dublicates++;
             }
         }
         session.Commit();
         Console.WriteLine("Done creating and sorting with BTreeSet<Tick> " + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates);
     }
 }
Пример #24
0
        public void CreateCompareStruct(int number)
        {
            Oid id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                session.BeginUpdate();
                BTreeSetOidShort <Oid> bTree = new BTreeSetOidShort <Oid>(null, session);
                bTree.Persist(place, session);
                id = bTree.Oid;
                for (int i = 0; i < number; i++)
                {
                    bTree.Add(new Oid((ulong)i));
                }
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSetOidShort <Oid> bTree = (BTreeSetOidShort <Oid>)session.Open(id);
                int count = 0;
                int prior = 0;
                foreach (Oid oid in bTree)
                {
                    count++;
                    Assert.True(oid.Id == (ulong)prior++);
                }
                Assert.True(number == count);
                session.Commit();
            }
        }
Пример #25
0
 public void CompareInt16()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     AllSupported obj = new AllSupported(1);
     CompareByField<AllSupported> compareByField = new CompareByField<AllSupported>("int16", session);
     BTreeSet<AllSupported> sortedSet = new BTreeSet<AllSupported>(compareByField, session, 1000, sizeof(Int16), true);
     for (int i = 0; i < 100000; i++)
     {
       obj = new AllSupported(1);
       obj.int16 = (Int16) randGen.Next(Int16.MinValue, Int16.MaxValue);
       sortedSet.Add(obj);
     }
     int ct = 0;
     AllSupported prior = null;
     foreach (AllSupported currentObj in (IEnumerable<AllSupported>)sortedSet)
     {
       if (prior != null)
         Assert.Less(prior.int16, currentObj.int16);
       prior = currentObj;
       ct++;
     }
     session.Commit();
   }
 }
Пример #26
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");
     }
 }
Пример #27
0
 public void CompareInt32Descending()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(2, session);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000);
         for (int i = 0; i < 100000; i++)
         {
             obj       = new AllSupported(1, session);
             obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue);
             sortedSet.Add(obj);
         }
         int          ct    = 0;
         AllSupported prior = null;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Greater(prior.int32, currentObj.int32);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
Пример #28
0
 static void createTopLevelInvertedIndex()
 {
     Console.WriteLine(DateTime.Now.ToString() + ", start creating top level inverted index");
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         Placement wordPlacement = new Placement(Lexicon.PlaceInDatabase, 2, 1, 1000, 50000, true, false, UInt32.MaxValue, false);
         session.BeginUpdate();
         IndexRoot indexRoot                 = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
         BTreeSetOidShort <Word> wordSet     = indexRoot.lexicon.WordSet;
         BTreeSet <Document>     documentSet = indexRoot.repository.documentSet;
         Word existingWord = null;
         foreach (Document doc in documentSet)
         {
             foreach (Word word in doc.WordSet)
             {
                 WordHit wordHit = doc.WordHit[word];
                 if (wordSet.TryGetKey(word, ref existingWord))
                 {
                     existingWord.GlobalCount = existingWord.GlobalCount + (uint)wordHit.Count;
                 }
                 else
                 {
                     existingWord = new WordGlobal(word.aWord, session, (uint)wordHit.Count);
                     existingWord.Persist(wordPlacement, session);
                     indexRoot.lexicon.WordSet.Add(existingWord);
                 }
                 existingWord.DocumentHit.AddFast(doc);
             }
             doc.Indexed = true;
         }
         session.Commit();
         Console.WriteLine(DateTime.Now.ToString() + ", done creating top level inverted index");
     }
 }
Пример #29
0
        static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath

        static int Main(string[] args)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
                try
                {
                    session.BeginUpdate();
                    Company company = new Company();
                    company.Name = "MyCompany";
                    session.Persist(company);
                    Employee employee1 = new Employee();
                    employee1.Employer  = company;
                    employee1.FirstName = "John";
                    employee1.LastName  = "Walter";
                    session.Persist(employee1);
                    session.Commit();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                    session.Abort();
                }
            }
            Retrieve();
            return(0);
        }
Пример #30
0
    static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath

    static int Main(string[] args)
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
        try
        {
          session.BeginUpdate();
          Company company = new Company();
          company.Name = "MyCompany";
          session.Persist(company);
          Employee employee1 = new Employee();
          employee1.Employer = company;
          employee1.FirstName = "John";
          employee1.LastName = "Walter";
          session.Persist(employee1);
          session.Commit();
        }
        catch (Exception ex)
        {
          Trace.WriteLine(ex.Message);
          session.Abort();
        }
      }
      Retrieve();
      return 0;
    }
Пример #31
0
 public void aaaFakeLicenseDatabase()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         Database  database;
         License   license = new License("Mats", 1, null, null, null, 99999, DateTime.MaxValue, 9999, 99, 9999);
         Placement placer  = new Placement(License.PlaceInDatabase, 1, 1, 1);
         license.Persist(placer, session);
         for (uint i = 10; i < 20; i++)
         {
             database = session.NewDatabase(i);
             Assert.NotNull(database);
         }
         session.Commit();
         File.Copy(Path.Combine(systemDir, "20.odb"), Path.Combine(systemDir, "4.odb"));
         session.BeginUpdate();
         for (uint i = 21; i < 30; i++)
         {
             database = session.NewDatabase(i);
             Assert.NotNull(database);
         }
         session.RegisterClass(typeof(VelocityDbSchema.Samples.Sample1.Person));
         Graph g = new Graph(session);
         session.Persist(g);
         session.Commit();
     }
 }
Пример #32
0
 public void TwoUpdaters3()
 {
     Assert.Throws <OptimisticLockingFailed>(() =>
     {
         UInt64 id;
         try
         {
             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;
                 session.FlushUpdates(); // fStream set for updated databases will cause other write sessions to fail updating these databases
                 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(); // OptimisticLockingFailed here
                 }
                 session.Commit();
                 session.Verify();
             }
         }
         finally
         {
             System.GC.Collect();
         }
     });
 }
Пример #33
0
 public void aaaFakeLicenseDatabase()
 {
   Assert.Throws<NoValidVelocityDBLicenseFoundException>(() =>
   {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       session.BeginUpdate();
       Database database;
       License license = new License("Mats", 1, null, null, null, 99999, DateTime.MaxValue, 9999, 99, 9999);
       Placement placer = new Placement(License.PlaceInDatabase, 1, 1, 1);
       license.Persist(placer, session);
       for (uint i = 10; i < 20; i++)
       {
         database = session.NewDatabase(i);
         Assert.NotNull(database);
       }
       session.Commit();
       File.Copy(Path.Combine(systemDir, "20.odb"), Path.Combine(systemDir, "4.odb"));
       session.BeginUpdate();
       for (uint i = 21; i < 30; i++)
       {
         database = session.NewDatabase(i);
         Assert.NotNull(database);
       }
       session.RegisterClass(typeof(VelocityDbSchema.Samples.Sample1.Person));
       Graph g = new Graph(session);
       session.Persist(g);
       session.Commit();
     }
   });
 }
Пример #34
0
        static void Main(string[] args)
        {
            SessionBase.BaseDatabasePath = @"d:/Databases";
            bool dirExist = Directory.Exists(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir));

            if (!dirExist)
            {
                ImdbImport.ImprortImdb(s_systemDir);
            }
            KevinBaconNumbers kevinBaconNumbers = new KevinBaconNumbers();

            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                try
                {
                    session.BeginRead();
                    kevinBaconNumbers.calculateNumbers(session);
                    kevinBaconNumbers.printResults();
                    session.Commit();
                }
                catch (Exception e)
                {
                    session.Abort();
                    Console.WriteLine(e.ToString());
                }
            }
        }
Пример #35
0
        public void LocalDateTest()
        {
            LocalDate d1      = new LocalDate(2016, 1, 10);
            LocalDate d2      = new LocalDate(2016, 1, 1);
            LocalDate d1other = new LocalDate(2016, 1, 10);

            Assert.AreNotEqual(d1, d2);
            Assert.AreEqual(d1, d1other);

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                LocalDateField test1 = new LocalDateField("def", d1);
                session.Persist(test1);
                LocalDateField test = new LocalDateField("abc", d2);
                session.Persist(test);
                var result1 = session.AllObjects <LocalDateField>().First(t => t.Field2.Equals(d2)); // this works
                session.Commit();
            }

            using (var session = new SessionNoServerShared(systemDir))
            {
                session.BeginRead();
                var result2 = session.AllObjects <LocalDateField>().First(t =>
                {
                    var l = t.Field2;
                    return(l.Equals(d2));
                }); // this should work and doesnt
                session.Commit();
            }
        }
Пример #36
0
 static void Main(string[] args)
 {
     CreateData();
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         session.BeginRead();
         int ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 10000).Count;
         Console.WriteLine($@"GeoObj located in San Diego by 10000 meter radius: {ct}");
         ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 100000).Count;
         Console.WriteLine($@"GeoObj located in San Diego by 100000 meter radius: {ct}");
         ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 10000).Count;
         Console.WriteLine($@"GeoObj located in New York City by 10000 meter radius: {ct}");
         ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 100000).Count;
         Console.WriteLine($@"GeoObj located in New York City by 100000 meter radius: {ct}");
         // Sweden bounding box
         ct = GeoHashQuery.SearchGeoHashIndex(session, 55.34, 10.96, 69.06, 24.17).Count;
         Console.WriteLine($@"GeoObj located in Sweden: {ct}");
         // Alaska bounding box
         ct = GeoHashQuery.SearchGeoHashIndex(session, 51.21, -169.01, 71.39, -129.99).Count;
         Console.WriteLine($@"GeoObj located in Alaska: {ct}");
         // California bounding box
         ct = GeoHashQuery.SearchGeoHashIndex(session, 32.53, -124.42, 42.01, -114.13).Count;
         Console.WriteLine($@"GeoObj located in California: {ct}");
         // USA bounding box
         //GeoHashQuery.SearchGeoHashIndex(session, 18.9, -67.0, 71.4, 172.4);
         //Console.WriteLine($@"Persons located in USA: {ct}");
     }
 }
Пример #37
0
 public void hashCodeComparerStringTest()
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.Compact();
     session.BeginUpdate();
     HashCodeComparer<string> hashCodeComparer = new HashCodeComparer<string>();
     BTreeSet<string> bTree = new BTreeSet<string>(hashCodeComparer, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     for (int i = 0; i < 100000; i++)
     {
       bTree.Add(i.ToString());
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeSet<string> bTree= (BTreeSet<string>)session.Open(id);
     int count = 0;
     foreach (string str in bTree)
     {
       count++;
     }
     Assert.True(100000 == count);
     session.Commit();
   }
 }
Пример #38
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
     }
   });
 }
Пример #39
0
 public void GermanString()
 {
   UInt64 id = 0;
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     using (var trans = new TransactionScope())
     {
       session.BeginUpdate();
       VelocityDbSchema.Person person = new VelocityDbSchema.Person();
       person.LastName = "Med vänliga hälsningar";
       id = session.Persist(person);
       trans.Complete();
     }
   }
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     using (var trans = new TransactionScope())
     {
       session.BeginUpdate();
       VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
       person.LastName = "Mit freundlichen Grüßen";
       trans.Complete();
     }
   }
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     using (var trans = new TransactionScope())
     {
       session.BeginUpdate();
       VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
       person.LastName = "Med vänliga hälsningar";
       trans.Complete();
     }
   }
 }
Пример #40
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 
          }
        }
      }
    }
Пример #41
0
 public void TwoUpdaters2()
 {
     Assert.Throws <OpenDatabaseException>(() =>
     {
         UInt64 id;
         try
         {
             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;
                 session.FlushUpdates();
                 using (SessionNoServer session2 = new SessionNoServer(systemDir))
                 {
                     session2.BeginRead();
                     Man man2 = (Man)session2.Open(id);
                     Assert.Less(man2.Age, man.Age);
                     man2.Age = ++man.Age; // We'll get the OpenDatabase exception here since we are not in an update transaction
                     session2.Commit();
                 }
                 session.Commit();
             }
         }
         finally
         {
             System.GC.Collect();
         }
     });
 }
Пример #42
0
        private void SyncFederationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem            menuItem = (MenuItem)sender;
            FederationViewModel view     = (FederationViewModel)menuItem.DataContext;
            FederationInfo      info     = view.Federationinfo;
            SessionBase         session  = view.Session;
            var lDialog = new System.Windows.Forms.FolderBrowserDialog()
            {
                Description = "Choose Federation Sync Destination Folder",
            };

            if (lDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string destdir = lDialog.SelectedPath;
                if (session.InTransaction)
                {
                    session.Commit(); // must not be in transaction while copying databases
                }
                using (SessionBase sessionDestination = new SessionNoServer(destdir))
                {
                    sessionDestination.SyncWith(session);
                }
                m_viewModel      = new AllFederationsViewModel();
                base.DataContext = m_viewModel;
                MessageBox.Show("Databases synced with " + destdir + " at " + DateTime.Now);
            }
        }
Пример #43
0
 public void CompareInt16()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(1);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int16", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int16), true);
         for (int i = 0; i < 100000; i++)
         {
             obj       = new AllSupported(1);
             obj.int16 = (Int16)randGen.Next(Int16.MinValue, Int16.MaxValue);
             sortedSet.Add(obj);
         }
         int          ct    = 0;
         AllSupported prior = null;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Less(prior.int16, currentObj.int16);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
Пример #44
0
        public void MultipleThreadsAdding()
        {
            bool doClearAll = SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase;

            SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase = false;
            try
            {
                using (SessionNoServer session = new SessionNoServer(systemDir))
                {
                    session.BeginUpdate();
                    session.RegisterClass(typeof(AutoPlacement)); // build in type but not yet registered as a one
                    session.RegisterClass(typeof(ObservableList <int>));
                    session.RegisterClass(typeof(Dokument));
                    UInt32   dbNum = session.DatabaseNumberOf(typeof(Dokument));
                    Database db    = session.OpenDatabase(dbNum, false, false);
                    if (db == null)
                    {
                        db = session.NewDatabase(dbNum, 0, typeof(Dokument).ToGenericTypeString());
                    }
                    Dokument doc = new Dokument();
                    session.Persist(doc);
                    session.Commit();
                }
                using (ServerClientSessionShared sharedReadSession = new ServerClientSessionShared(systemDir))
                {
                    sharedReadSession.BeginRead();
                    Parallel.ForEach(Enumerable.Range(1, 3), (num) => LockConflict(sharedReadSession));
                }
            }
            finally
            {
                SessionBase.ClearAllCachedObjectsWhenDetectingUpdatedDatabase = doClearAll;
            }
        }
Пример #45
0
        public void CompareInt32DescendingComparisonArray()
        {
#if DEBUG
            Assert.Throws <NotImplementedException>(() =>
            {
                using (SessionNoServer session = new SessionNoServer(systemDir))
                {
                    session.BeginUpdate();
                    AllSupported obj = new AllSupported(2);
                    CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false);
                    BTreeSet <AllSupported> sortedSet            = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int32), true);
                    for (int i = 0; i < 100000; i++)
                    {
                        obj       = new AllSupported(1);
                        obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue);
                        sortedSet.Add(obj);
                    }
                    int ct             = 0;
                    AllSupported prior = null;
                    foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
                    {
                        if (prior != null)
                        {
                            Assert.Greater(prior.int32, currentObj.int32);
                        }
                        prior = currentObj;
                        ct++;
                    }
                    session.Commit();
                }
            });
#endif
        }
Пример #46
0
 public void CompareDateTime()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj;
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("dateTime", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(long), true);
         for (int i = 0; i < 20000; i++)
         {
             obj          = new AllSupported(1);
             obj.dateTime = DateTime.FromBinary(randGen.Next(Int32.MinValue, Int32.MaxValue) * randGen.Next());
             sortedSet.Add(obj);
         }
         int          ct    = 0;
         AllSupported prior = null;
         foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet)
         {
             if (prior != null)
             {
                 Assert.Less(prior.dateTime, currentObj.dateTime);
             }
             prior = currentObj;
             ct++;
         }
         session.Commit();
     }
 }
Пример #47
0
        static void CreateData()
        {
            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                bool dirExist = Directory.Exists(session.SystemDirectory);
                if (dirExist)
                {
                    return;

                    Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
                }
                Directory.CreateDirectory(session.SystemDirectory);
                File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
                SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4;
                session.BeginUpdate();
                CompareGeoObj comparer = new CompareGeoObj();
                var           btreeSet = new BTreeSet <GeoObj>(comparer, session, 1000);
                for (int i = 0; i < s_numberOfSamples; i++)
                {
                    var g = new GeoObj();
                    btreeSet.Add(g);
                }
                session.Persist(btreeSet);
                session.Commit();
                Console.Out.WriteLine($@"Done creating {s_numberOfSamples} GeoHashSample GeoObj ");
            }
        }
Пример #48
0
        static readonly string s_systemDir         = "JsonExportImport"; // appended to SessionBase.BaseDatabasePath

        static void Main(string[] args)
        {
            try
            {
                int personCt = 0;
                using (SessionBase session = new SessionNoServer(s_systemDirToImport))
                {
                    session.BeginRead();
                    IEnumerable <string> personStringEnum = session.ExportToJson <Person>();
                    using (SessionBase sessionImport = new SessionNoServer(s_systemDir))
                    {
                        sessionImport.BeginUpdate();
                        foreach (string json in personStringEnum)
                        {
                            Person person = sessionImport.ImportJson <Person>(json);
                            sessionImport.Persist(person);
                            personCt++;
                        }
                        session.Commit();
                        sessionImport.Commit();
                        Console.WriteLine("Imported " + personCt + " from Json strings");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #49
0
 static VelocityDB()
 {
     string systemDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VelocityDB", "Databases", "MvCSample");
     if (Directory.Exists(systemDir))
       Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
     Session = new SessionNoServer(systemDir);
     Session.BeginUpdate();
     Session.Commit();
 }
Пример #50
0
 public void Verify(string dir)
 {
   using (SessionNoServer session = new SessionNoServer(dir))
   {
     session.BeginRead();
     session.Verify();
     session.Commit();
   }
 }
Пример #51
0
 public void CsvImport()
 {
   using (SessionNoServer session = new SessionNoServer(systemDirCvsImport))
   {
     session.BeginUpdate();
     session.ImportFromCSV(csvExportDir);
     session.Commit();
   }
   Verify(systemDirCvsImport);
 }
Пример #52
0
 public void CsvExport()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.Compact();
     session.BeginRead();
     session.ExportToCSV(csvExportDir);
     session.Commit();
   }
 }
Пример #53
0
 static VelocityDBStatic()
 {
     string systemDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VelocityDB", "Databases", "MvCSample");
     foreach (string f in Directory.EnumerateFiles(systemDir))
       if (f.Contains("4.odb") == false)
         File.Delete(f);
     Session = new SessionNoServer(systemDir);
     Session.BeginUpdate();
     Session.Commit();
 }
Пример #54
0
 static void Main(string[] args)
 {
   SessionNoServer session = new SessionNoServer(systemDir);
   session.BeginUpdate();
   Person robinHood = new Person("Robin", "Hood", 30);
   Person billGates = new Person("Bill", "Gates", 56, robinHood);
   Person steveJobs = new Person("Steve", "Jobs", 56, billGates);
   robinHood.BestFriend = billGates;
   session.Persist(steveJobs); // the other persons will be persisted implicetly by reachability from "Steve Jobs" person object
   session.Commit();
 }
Пример #55
0
 public void OneMillionFindSingleRecordInTheMiddle()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     var result = (from ComputerFileData computerFileData in session.AllObjects<ComputerFileData>()
                   where computerFileData.FileID == 500000
                   select computerFileData).First();
     session.Commit();
   }
 }
Пример #56
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();
   }
 }
Пример #57
0
 // GET api/database/suppliertracking/15
 public string Get(string path, UInt32 id)
 {
   using (SessionNoServer session = new SessionNoServer(path))
   {
     session.BeginRead();
     Database db = session.OpenDatabase(id);
     string dbName = db.ToString();
     session.Commit();
     return dbName;
   }
 }
Пример #58
0
 public void DoFileFolderTest()
 {
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.NotifyBeforeCommit = NotifyBeforeCommit;
     session.BeginUpdate();
     DirectoryInfo dirInfo = new DirectoryInfo(s_sampleFolder);
     Folder folder = new Folder(dirInfo.Name, null, session);
     CreateDirectoriesAndFiles(dirInfo, folder, session);
     session.Persist(folder);
     session.Commit();
   }
 }
Пример #59
0
 public string Get(string path, int id = 0)
 {
   using (SessionNoServer session = new SessionNoServer(path))
   {
     session.BeginRead();
     Graph graph = Graph.Open(session, id);
     using (MemoryStream ms = new MemoryStream())
     {
       graph.ExportToGraphJson(ms);
       session.Commit();
       return Encoding.UTF8.GetString(ms.ToArray());
     }
   }
 }
Пример #60
0
 public void Create1Root()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     IssueTracker issueTracker = new IssueTracker(10, session);
     User user = new User(null, "*****@*****.**", "Mats", "Persson", "matspca");
     session.Persist(user);
     PermissionScheme permissions = new PermissionScheme(user);
     issueTracker.Permissions = permissions;
     session.Persist(issueTracker);
     session.Commit();
   }
 }