Exemplo n.º 1
0
        public void textToWords(Document doc, IndexRoot indexRoot, string docTextString)
        {
            DocumentText docText = new DocumentText(docTextString, doc);

            session.Persist(doc);
            doc.Page.Database.Name = doc.Name;
            session.Persist(docText);
            indexRoot.Repository.DocumentSet.Add(doc);
            doc.Content   = docText;
            docTextString = docTextString.ToLower();
            string[] excludedWords = new string[] { "and", "the" };
            char[]   splitChars    = new char[] { ' ', '\n', '(', '"', '!', ',', '(', ')', '\t' };
            string[] words         = docTextString.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
            int      i             = 0;
            string   aWord;

            char[] trimEndChars   = new char[] { ';', '.', '"', ',', '\r', ':', ']', '!', '?', '+', '(', ')', '\'', '{', '}', '-', '`', '/', '=' };
            char[] trimStartChars = new char[] { ';', '&', '-', '#', '*', '[', '.', '"', ',', '\r', ')', '(', '\'', '{', '}', '-', '`' };
            foreach (string wordStr in words)
            {
                i++;
                aWord = wordStr.TrimEnd(trimEndChars);
                aWord = aWord.TrimStart(trimStartChars);
                if (aWord.Length > 1 && excludedWords.Contains(aWord) == false)
                {
                    indexRoot.Lexicon.PossiblyAddToken(aWord, doc);
                }
            }
        }
Exemplo n.º 2
0
        void DictionaryTestTony()
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                Test test1 = new Test("def", 1);
                session.Persist(test1);
                Test test = new Test("abc", 2);
                session.Persist(test);
                var res = test.Field3.Equals(test1.Field3);
                foreach (var test_value in session.AllObjects <Test>()) // this works
                {
                    Trace.WriteLine(test_value);
                }
                Test2 t2 = new Test2("xxxx");
                session.Persist(t2);
                t2.Dict_Field.Add(test1, 1);
                t2.Dict_Field.Add(test, 2);
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                foreach (var test_value in session.AllObjects <Test2>()) // this fails
                {
                    Trace.WriteLine(test_value);
                }
                session.Commit();
            }
        }
Exemplo n.º 3
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());
   }
 }    
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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;
    }
Exemplo n.º 6
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();
   }
 }
Exemplo n.º 7
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();
                }
            }
Exemplo n.º 8
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();
      }
    }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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());
     }
 }
Exemplo n.º 11
0
        static readonly string systemDir = "RelationsCore"; // appended to SessionBase.BaseDatabasePath

        static int Main(string[] args)
        {
            using (var session = new SessionNoServer(systemDir))
            {
                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
                Console.WriteLine($"Running with databases in directory: {session.SystemDirectory}");
                try
                {
                    session.BeginUpdate();
                    var user = new User {
                        Name = "Mats", Surame = "Persson"
                    };
                    var user2 = new User {
                        Name = "Robin", Surame = "Persson"
                    };
                    session.Persist(user);
                    session.Persist(user2);
                    user.Backup = user2;
                    var customer = new Customer {
                        Name = "Ben", Balance = 0
                    };
                    session.Persist(customer);
                    var interaction = new Interaction(customer, user, session);
                    session.Commit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            using (var session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                try
                {
                    foreach (var user in session.AllObjects <User>())
                    {
                        user.Backup = null; // remove all backup relations (see what happens if you don't !)
                    }
                    foreach (var user in session.AllObjects <User>())
                    {
                        user.Unpersist(session);
                    }
                    foreach (var customer in session.AllObjects <Customer>())
                    {
                        customer.Unpersist(session);
                    }
                    foreach (var customer in session.AllObjects <Interaction>())
                    {
                        throw new UnexpectedException("should not exist any longer");
                    }
                    session.Commit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(0);
        }
Exemplo n.º 12
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();
     }
 }
Exemplo n.º 13
0
    static readonly string systemDir = "Sample1"; // appended to SessionBase.BaseDatabasePath

    static int Main(string[] args)
    {
      SessionNoServer session = new SessionNoServer(systemDir);
      Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
      session.BeginUpdate();
      Person person = new Person("Robin", "Hood", 30);
      session.Persist(person);
      person = new Person("Bill", "Gates", 56);
      session.Persist(person);
      person = new Person("Steve", "Jobs", 56);
      session.Persist(person);
      session.Commit();
      return 0;
    }
Exemplo n.º 14
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();
   }
 }
Exemplo n.º 15
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;
            }
        }
Exemplo n.º 16
0
        public void cSyncNewPages()
        {
            using (SessionBase session = new SessionNoServer(s_sync1))
            {
                using (var trans = session.BeginUpdate())
                {
                    for (uint i = 0; i < 100; i++)
                    {
                        FourPerPage fourPerPage = new FourPerPage(i);
                        session.Persist(fourPerPage);
                    }
                    session.Commit();
                }
            }

            using (SessionBase readFromSession = new SessionNoServer(s_sync1))
            {
                using (var updateSession = new SessionNoServerShared(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.AllObjects <FourPerPage>().Count, readFromSession.AllObjects <FourPerPage>().Count);
                    }
                }
            }
        }
Exemplo n.º 17
0
 private void loadButton_Click(object sender, RoutedEventArgs e)
 {
     errorMessage.Content = null;
     try
     {
         using (SessionNoServer session = new SessionNoServer(s_systemDir))
         {
             session.BeginUpdate();
             string line;
             using (StreamReader stream = new StreamReader(worldCitiesTextFile.Text, true))
             {
                 line = stream.ReadLine(); // heading title line
                 while ((line = stream.ReadLine()) != null)
                 {
                     string[] fields = line.Split(',');
                     City     city   = new City(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5], fields[6]);
                     session.Persist(city);
                 }
             }
             loadCities(session);
             session.Commit();
         }
     }
     catch (Exception ex)
     {
         errorMessage.Content = ex.Message == null?ex.ToString() : ex.Message;
     }
 }
Exemplo n.º 18
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());
      }
    }
Exemplo n.º 19
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 ");
   }
 }
Exemplo n.º 20
0
        public void VelocityDB_SaveKunde_Test()
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                try
                {
                    session.BeginUpdate();
                    var kunde = new KundeVelocityDB();
                    kunde.Kto          = "4711";
                    kunde.KtoFoerderer = "4712";
                    kunde.Periode      = 2016006;
                    session.Persist(kunde);
                    session.Commit();
                }
                catch (Exception e)
                {
                    session.Abort();
                }
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();

                var kunden = session.AllObjects <KundeVelocityDB>();
                var query  = from k in kunden
                             where k.Kto.Contains("4711")
                             select k;

                Assert.AreEqual("4711", query.First()?.Kto);
                Assert.AreEqual("4712", query.First()?.KtoFoerderer);
                Assert.AreEqual(2016006, query.First()?.Periode);
            }
        }
Exemplo n.º 21
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();
     }
   });
 }
Exemplo n.º 22
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();
     }
 }
Exemplo n.º 23
0
        public void GermanString()
        {
            UInt64 id = 0;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                VelocityDbSchema.Person person = new VelocityDbSchema.Person();
                person.LastName = "Med vänliga hälsningar";
                id = session.Persist(person);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                VelocityDbSchema.Person person = session.Open <VelocityDbSchema.Person>(id);
                person.LastName = "Mit freundlichen Grüßen";
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                VelocityDbSchema.Person person = session.Open <VelocityDbSchema.Person>(id);
                person.LastName = "Med vänliga hälsningar";
                session.Commit();
            }
        }
Exemplo n.º 24
0
        static readonly string systemDir = "Sample3Core"; // 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();
                    session.RegisterClass(typeof(List <Person>));
                    //session.Commit();
                    //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());
            }
        }
Exemplo n.º 25
0
        public void DictionaryTest()
        {
            ulong id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                Dictionary <string, int> dict = new Dictionary <string, int>();
                dict.Add("Mats", 52);
                dict.Add("Robin", 16);
                dict.Add("Kinga", 53);
                id = session.Persist(dict);
                var comp = dict.Comparer;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                object dictObj = session.Open(id);
                Dictionary <string, int> dict = (Dictionary <string, int>)dictObj;
                var comp = dict.Comparer;
                if (dict["Mats"] != 52)
                {
                    throw new Exception("failed");
                }
                session.Commit();
            }
        }
Exemplo n.º 26
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();
                }
            }
        }
Exemplo n.º 27
0
        public void AutoPlacementDbRollover(int howMany)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                FourPerPage f;
                for (UInt64 i = 0; i < 1000000; i++)
                {
                    f = new FourPerPage(i);
                    session.Persist(f);
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                UInt32   dbNum = session.DatabaseNumberOf(typeof(FourPerPage));
                Database db    = session.OpenDatabase(dbNum);
                int      ct    = 0;
                foreach (FourPerPage f in db.AllObjects <FourPerPage>())
                {
                    ct++;
                }
                Assert.AreEqual(ct, howMany);
                session.Commit();
            }
        }
Exemplo n.º 28
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 ");
            }
        }
Exemplo n.º 29
0
        static readonly string systemDir = "Sample1"; // appended to SessionBase.BaseDatabasePath

        static int Main(string[] args)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
                session.BeginUpdate();
                Person person = new Person("Robin", "Hood", 30);
                session.Persist(person);
                person = new Person("Bill", "Gates", 56);
                session.Persist(person);
                person = new Person("Steve", "Jobs", 56);
                session.Persist(person);
                session.Commit();
            }
            return(0);
        }
Exemplo n.º 30
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());
      }
    }
Exemplo n.º 31
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());
            }
        }
Exemplo n.º 32
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();
     }
   }
 }
Exemplo n.º 33
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);
     }
 }
Exemplo n.º 34
0
        public void SortedObjectsSample()
        {
            Oid bTreeId;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                const UInt32 numberOfPersons              = 100000;
                const ushort nodeMaxSize                  = 5000;
                const ushort comparisonByteArraySize      = sizeof(UInt64); // enough room to hold entire idNumber of a Person
                const bool   comparisonArrayIsCompleteKey = true;
                const bool   addIdCompareIfEqual          = false;
                VelocityDbSchema.Samples.AllSupportedSample.Person person;
                session.BeginUpdate();
                //mySession.SetTraceAllDbActivity();
                CompareByField <VelocityDbSchema.Samples.AllSupportedSample.Person> compareByField = new CompareByField <VelocityDbSchema.Samples.AllSupportedSample.Person>("m_idNumber", session, addIdCompareIfEqual);
                BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>       bTree          = new BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey);
                session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low
                for (int i = 0; i < numberOfPersons; i++)
                {
                    person = new VelocityDbSchema.Samples.AllSupportedSample.Person();
                    session.Persist(person);
                    bTree.Add(person);
                }
                bTreeId = bTree.Oid;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person> bTree = (BTreeSet <VelocityDbSchema.Samples.AllSupportedSample.Person>)session.Open(bTreeId);
                foreach (VelocityDbSchema.Samples.AllSupportedSample.Person person in (IEnumerable <VelocityDbSchema.Samples.AllSupportedSample.Person>)bTree)
                {
                    if (person.IdNumber > 196988888791402)
                    {
                        Console.WriteLine(person);
                        break;
                    }
                }
                session.Commit();
                session.BeginRead();
                // this LINQ statement will trigger a binary search lookup (not a linear serach) of the matching Person objects in the BTreeSet
                Console.WriteLine((from person in bTree where person.IdNumber > 196988888791402 select person).First());
                session.Commit();
            }
        }
Exemplo n.º 35
0
 public void NewClaim(MitchellClaimType claim)
 {
     using (SessionBase session = new SessionNoServer(s_systemDir))
     {
         session.BeginUpdate();
         session.Persist(claim);
         session.Commit();
     }
 }
Exemplo n.º 36
0
    static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath

    static int Main(string[] args)
    {
      SessionNoServer session = new SessionNoServer(systemDir);
      Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
      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();
      Retrieve();
      return 0;
    }
Exemplo n.º 37
0
 public void CompareString(int compArraySize)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         AllSupported obj = new AllSupported(1, session);
         CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("aString", session);
         BTreeSet <AllSupported>       sortedSet      = new BTreeSet <AllSupported>(compareByField, session, 1000, (ushort)compArraySize);
         session.Persist(sortedSet);
         for (int i = 0; i < 11000; i++)
         {
             obj         = new AllSupported(1, session);
             obj.aString = RandomString(10);
             sortedSet.AddFast(obj);
         }
         obj         = new AllSupported(1, session);
         obj.aString = null;
         session.Persist(obj);
         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();
     }
 }
Exemplo n.º 38
0
        public void AddCity(City city)
        {
            using (SessionNoServer session = new SessionNoServer(SystemDir))
            {
                session.BeginUpdate();

                session.Persist(city);

                session.Commit();
            }
        }
Exemplo n.º 39
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();
 }
Exemplo n.º 40
0
 public void AddCity(IList <City> citys)
 {
     using (SessionNoServer session = new SessionNoServer(SystemDir))
     {
         session.BeginUpdate();
         foreach (var city in citys)
         {
             session.Persist(city);
         }
         session.Commit();
     }
 }
Exemplo n.º 41
0
        static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath

        static int Main(string[] args)
        {
            SessionNoServer session = new SessionNoServer(systemDir);

            Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
            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();
            Retrieve();
            return(0);
        }
Exemplo n.º 42
0
        public void HashSetAddNonPersisted()
        {
            UInt64 id;
            Person person = null;

            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                session.BeginUpdate();
                var hashSet = new HashSet <Person>();
                for (int i = 0; i < 100; i++)
                {
                    var p = new Person();
                    session.Persist(p);
                    hashSet.Add(p);
                    if (i == 47)
                    {
                        person = p;
                        Assert.IsFalse(hashSet.Add(person));
                    }
                }
                id = session.Persist(hashSet);
                Assert.IsTrue(hashSet.Contains(person));
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                session.BeginRead();
                var hashSet = session.Open <HashSet <Person> >(id);
                Assert.AreEqual(100, hashSet.Count);
                int ct = 0;
                foreach (Person p in hashSet)
                {
                    ct++;
                }
                Assert.IsTrue(hashSet.Contains(person));
                Assert.IsFalse(hashSet.Add(person));
                Assert.AreEqual(100, ct);
                session.Commit();
            }
        }
Exemplo n.º 43
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();
     }
 }
Exemplo n.º 44
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();
   }
 }
Exemplo n.º 45
0
 public void HashSetAddNonPersisted()
 {
   UInt64 id;
   Person person = null;
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginUpdate();
     var hashSet = new HashSet<Person>();
     for (int i = 0; i < 100; i++)
     {
       var p = new Person();
       session.Persist(p);
       hashSet.Add(p);
       if (i == 47)
       {
         person = p;
         Assert.IsFalse(hashSet.Add(person));
       }
     }
     id = session.Persist(hashSet);
     Assert.IsTrue(hashSet.Contains(person));
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginRead();
     var hashSet = session.Open<HashSet<Person>>(id);
     Assert.AreEqual(100, hashSet.Count);
     int ct = 0;
     foreach (Person p in hashSet)
       ct++;
     Assert.IsTrue(hashSet.Contains(person));
     Assert.IsFalse(hashSet.Add(person));
     Assert.AreEqual(100, ct);
     session.Commit();
   }
 }
Exemplo n.º 46
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
     const UInt32 numberOfPersons = 10000;
     const ushort nodeMaxSize = 5000;
     const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person
     const bool comparisonArrayIsCompleteKey = true;
     const bool addIdCompareIfEqual = false;
     Person person;
     session.BeginUpdate();
     session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
     //mySession.SetTraceAllDbActivity();
     BTreeSet<string> stringSet = new BTreeSet<string>(null, session);
     BTreeSetOidShort<string> stringSetShort = new BTreeSetOidShort<string>(null, session);
     BTreeMap<string, string> stringMap = new BTreeMap<string, string>(null, session);
     BTreeMapOidShort<string, string> stringMapShort = new BTreeMapOidShort<string, string>(null, session);
     CompareByField<Person> compareByField = new CompareByField<Person>("idNumber", session, addIdCompareIfEqual);
     BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey);
     session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low
     for (int i = 0; i < numberOfPersons; i++)
     {
       person = new Person();
       // session.Persist(person);
       bTree.AddFast(person);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.UseExternalStorageApi = true;
     session.BeginRead();
     BTreeSet<Person> bTree = session.AllObjects<BTreeSet<Person>>().First();
     foreach (Person person in (IEnumerable<Person>)bTree)
     {
       if (person.IdNumber > 196988888791402)
       {
         Console.WriteLine(person);
         break;
       }
     }
     session.Commit();
   }
 }
Exemplo n.º 47
0
 static int Main(string[] args)
 {
   UInt64 id;
   AllSupported allSupported, allSupported2;
   AllSuportedSub4 sub4;
   try
   {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
       session.BeginUpdate();
       File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true);
       sub4 = new AllSuportedSub4();
       session.Persist(sub4);
       id = sub4.Id;
       session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginRead();
       sub4 = (AllSuportedSub4)session.Open(id);
       session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginUpdate();
       allSupported = new AllSupported(3);
       session.Persist(allSupported);
       id = allSupported.Id;
      session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginRead();
       allSupported2 = (AllSupported)session.Open(id);
       session.Commit();
     }
   }
   catch (Exception ex)
   {
     Console.WriteLine(ex.ToString());
     return 1;
   }
   return 0;
 }
Exemplo n.º 48
0
 static void Main(string[] args)
 {
   try
   {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       DatabaseLocation localLocation = new DatabaseLocation(Dns.GetHostName(), Path.Combine(session.SystemDirectory, "desEncryptedLocation"), desEncryptedStartDatabaseNumber, UInt32.MaxValue,
         session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.desEncrypted);
       session.BeginUpdate();
       session.NewLocation(localLocation);
       localLocation.DesKey = SessionBase.TextEncoding.GetBytes("5d9nndwy"); // Des keys are 8 bytes long
       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();
     }
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     { // Des keys are not persisted in DatabaseLocation (for safety). Instead they are stored as *.des files
       // in the users document directory of the user that created the DatabaseLocation. These files can be copied
       // to other user's document directory when acccess is desired for other users. 
       // Path to user document dir is given by C#: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
       session.BeginRead();
       var allPersonsEnum = session.AllObjects<Person>();
       foreach (Person obj in allPersonsEnum)
       {
         Person person = obj as Person;
         if (person != null)
           Console.WriteLine(person.FirstName);
       }
       session.Commit();
     }
   }
   catch (Exception ex)
   {
     Console.WriteLine(ex.ToString());
   }
 }
Exemplo n.º 49
0
 public void OneMillionCreate()
 {
   Int32 recordsTocreate = 1000000;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     ComputerFileData velrecord;
     for (int i = 0; i < recordsTocreate; i++)
     {
       velrecord = (new ComputerFileData()
              {
                FullPath = @"c:\test\file" + i,
                ItemDeleted = true,
                PackagingErrors = "",
                PackagedSuccessfully = false,
                FileSelected = true,
                WDSSelected = false,
                FPPSearchSelected = false,
                RegexSelected = false,
                SharepointSelected = false,
                SharepointIndexedSearchSelected = false,
                WebSelected = false,
                DateFilterExcluded = false,
                IncludeFilterExcluded = false,
                ExcludeFilterExcluded = false,
                ContainerID = 1,
                FolderID = 1,
                FileID = i,
                ParentFileID = null,
                //ParentFileID = 0,
                Category = "cat",
                ResourceImageType = "",
                FolderPath = "",
                LastAccessTime = DateTime.Now,
                LastWriteTime = DateTime.Now,
                CreationTime = DateTime.Now,
                Size = 40000,
              });
       session.Persist(velrecord);
     }
     session.Commit();
   }
 }
Exemplo n.º 50
0
    static readonly string s_systemDir = "OneDbPerClass"; // appended to SessionBase.BaseDatabasePath

    public void AddRaceCar()
    {
      try
      {
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
          session.BeginUpdate();
          RaceCar raceCar = new RaceCar();
          raceCar.Speed = 1976.7;
          session.Persist(raceCar);
          session.Commit();
        }      
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }    
Exemplo n.º 51
0
 public void Create3Versions(int numberOfVersions)
 {
   ProductVersion version = null;
   ProductVersion priorVersion = null;
   for (int i = 0; i < numberOfVersions; i++)
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       session.BeginUpdate();
       IssueTracker issueTracker = session.AllObjects<IssueTracker>(false).FirstOrDefault();
       User user = issueTracker.UserSet.Keys[rand.Next(issueTracker.UserSet.Keys.Count - 1)];
       string v = "version" + i.ToString();
       string d = "vdescription" + i.ToString();
       version = new ProductVersion(user, v, d, null);
       session.Persist(version);
       issueTracker.VersionSet.Add(version);
       priorVersion = version;
       session.Commit();
     }
 }
Exemplo n.º 52
0
 public void Create2Users(int numberOfUsers)
 {
   User user = null;
   User priorUser = null;
   for (int i = 0; i < numberOfUsers; i++)
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       session.BeginUpdate();
       IssueTracker issueTracker = session.AllObjects<IssueTracker>(false).FirstOrDefault();
       string email = i.ToString() + "@gmail.com";
       string first = "first" + i.ToString();
       string last = "last" + i.ToString();
       string userName = "******" + i.ToString();
       user = new User(user, email, first, last, userName);
       session.Persist(user);
       issueTracker.UserSet.Add(user);
       priorUser = user;
       session.Commit();
     }
 }
Exemplo n.º 53
0
 public void ListWrapperTest()
 {
   // max length of an array is int.MaxValue, objects on a page are serialized to a single byte[] so this array must have a length < int.MaxValue
   UInt64 id;
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginUpdate();
     var f = new FourPerPage(1);
     id = session.Persist(f);
     Assert.True(f.IsOK());
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginRead();
     var f = session.Open<FourPerPage>(id);
     Assert.True(f.IsOK());
     session.Commit();
   }
 }
Exemplo n.º 54
0
 public void LargeObject()
 {
   // max length of an array is int.MaxValue, objects on a page are serialized to a single byte[] so this array must have a length < int.MaxValue
   UInt64 id;
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginUpdate(); 
     var large = new LargeObject((int) Math.Pow(2, 25)); // Math.Pow(2, 27) too large to handle with ToBase64String for csv export
     id = session.Persist(large);
     Assert.True(large.IsOK());
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginRead();
     var large = session.Open<LargeObject>(id);
     Assert.True(large.IsOK());
     session.Commit();
   }
 }
Exemplo n.º 55
0
    public void LazyLoadProperty()
    {
      UInt64 id;
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        LazyLoadPropertyClass lazy = null;
        for (uint i = 1; i <= 10000; i++)
          lazy = new LazyLoadPropertyClass(i, lazy);
        session.Persist(lazy);
        id = lazy.Id;
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        UInt32 ct = 10000;
        session.BeginRead();
        LazyLoadPropertyClass lazy = (LazyLoadPropertyClass)session.Open(id);
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);
        lazy = lazy.MyRef;
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);
        lazy = lazy.MyRef;
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);        
        lazy = lazy.MyRef;
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);
        session.Commit();
      }
    }
Exemplo n.º 56
0
    public void LazyLoadDepth()
    {
      UInt64 id;
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        LazyLoadByDepth lazy = null;
        for (uint i = 1; i <= 100; i++)
          lazy = new LazyLoadByDepth(i, lazy);
        session.Persist(lazy);
        id = lazy.Id;
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        UInt32 ct = 100;
        session.BeginRead();
        LazyLoadByDepth lazy = (LazyLoadByDepth)session.Open(id, false, false, 0); // load only the root of the object graph
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);
        lazy = lazy.MyRef;
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);
        lazy = lazy.MyRef;
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);        
        lazy = lazy.MyRef;
        Assert.AreEqual(ct--, lazy.MyCt);
        Assert.IsNull(lazy.MyRefPeek);
        Assert.NotNull(lazy.MyRef);
        Assert.NotNull(lazy.MyRefPeek);
        session.Commit();
      }
    }
Exemplo n.º 57
0
    static readonly string s_systemDir = "UpdateClass"; // appended to SessionBase.BaseDatabasePath

    static int Main(string[] args)
    {
      try
      {
        UpdatedClass updatedClassObject;
        int ct1 = 0;
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.BeginUpdate();
          session.UpdateClass(typeof(UpdatedClass)); // call this when you have updated the class since first storing instances of this type or since last call to UpdateClass
          UInt32 dbNum = session.DatabaseNumberOf(typeof(UpdatedClass));
          foreach (UpdatedClass obj in session.AllObjects<UpdatedClass>())
          {
            Console.Write(obj.ToString() + " has members: ");
            foreach (DataMember member in obj.GetDataMembers())
            {
              Console.Write(member.ToString() + " ");
            }
            Console.WriteLine();
            obj.UpdateTypeVersion(); // comment out if you DO NOT want to migrate this object to the latest version of the class
            ct1++;
          }
          int ct2 = 0;
          Database db = session.OpenDatabase(dbNum, true, false);
          if (db != null)
            foreach (UpdatedClass obj in db.AllObjects<UpdatedClass>())
              ct2++;
          Debug.Assert(ct1 == ct2);         
          updatedClassObject = new UpdatedClass();
          session.Persist(updatedClassObject);
          session.Commit();
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
        return 1;
      }
      return 0;
    }
Exemplo n.º 58
0
 public void TooLargeObject()
 {
   Assert.Throws<OverflowException>(() =>
   {
     UInt64 id;
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginUpdate();
       var large = new LargeObject((int)Math.Pow(2, 28));
       id = session.Persist(large);
       Assert.True(large.IsOK());
       session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       session.BeginRead();
       var large = session.Open<LargeObject>(id);
       Assert.True(large.IsOK());
       session.Commit();
     }
   });
 }
Exemplo n.º 59
0
 const long numberOfPersons = 10000000000; // a billion Person objects - let's say it is more than we can fit in memory
 static void Main(string[] args)
 {
   try
   {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
       Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
       session.BeginUpdate();
       Person person = new Person();
       for (long i = 0; i < numberOfPersons; i++)
       {
         // Each WeakIOptimizedPersistableReference require a persisted object (non null Oid) so that object reference can be substituted with an Oid.
         session.Persist(person);
         // create new Person and make prior Person his/her friend (see constructor of Person)
         person = new Person(person);
       }
       session.Commit();
     }
   }
   catch (Exception ex)
   {
     Console.WriteLine(ex.ToString());
   }
 }
    static readonly string s_licenseDbFile = "c:/4.odb"; // (download from https://www.velocitydb.com/Secure/Download.aspx)

    static void CreateGraph()
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        if (Directory.Exists(session.SystemDirectory))
          Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
        // Start an update transaction
        session.BeginUpdate();
        // Copy VelocityDB license database to this database directory
        File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
        Graph g = new Graph(session);
        session.Persist(g);

        // Add a node type for the movies, with a unique identifier and two indexed Propertys
        VertexType movieType = g.NewVertexType("Movie");
        PropertyType movieTitleType = g.NewVertexProperty(movieType, "title", DataType.String, PropertyKind.Indexed);
        PropertyType movieYearType = g.NewVertexProperty(movieType, "year", DataType.Integer, PropertyKind.Indexed);

        // Add a node type for the actor
        VertexType actorType = g.NewVertexType("Actor");
        PropertyType actorNameType = g.NewVertexProperty(actorType, "name", DataType.String, PropertyKind.Indexed);

        // Add a directed edge type with a Property for the cast of a movie
        EdgeType castType = g.NewEdgeType("ACTS_IN", false);
        PropertyType castCharacterType = g.NewEdgeProperty(castType, "role", DataType.String, PropertyKind.Indexed);

        // Add some Movies
        Vertex matrix1 = movieType.NewVertex();
        matrix1.SetProperty(movieTitleType, "The Matrix");
        matrix1.SetProperty(movieYearType, (int)1999);

        Vertex matrix2 = movieType.NewVertex();
        matrix2.SetProperty(movieTitleType, "The Matrix Reloaded");
        matrix2.SetProperty(movieYearType, (int)2003);

        Vertex matrix3 = movieType.NewVertex();
        matrix3.SetProperty(movieTitleType, "The Matrix  Revolutions");
        matrix3.SetProperty(movieYearType, (int)2003);

        // Add some Actors
        Vertex keanu = actorType.NewVertex();
        keanu.SetProperty(actorNameType, "Keanu Reeves");

        Vertex laurence = actorType.NewVertex();
        laurence.SetProperty(actorNameType, "Laurence Fishburne");

        Vertex carrieanne = actorType.NewVertex();
        carrieanne.SetProperty(actorNameType, "Carrie-Anne Moss");

        // Add some edges
        Edge keanuAsNeo = castType.NewEdge(keanu, matrix1);
        keanuAsNeo.SetProperty(castCharacterType, "Neo");
        keanuAsNeo = castType.NewEdge(keanu, matrix2);
        keanuAsNeo.SetProperty(castCharacterType, "Neo");
        keanuAsNeo = castType.NewEdge(keanu, matrix3);
        keanuAsNeo.SetProperty(castCharacterType, "Neo");

        Edge laurenceAsMorpheus = castType.NewEdge(laurence, matrix1);
        laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
        laurenceAsMorpheus = castType.NewEdge(laurence, matrix2);
        laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
        laurenceAsMorpheus = castType.NewEdge(laurence, matrix3);
        laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");

        Edge carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix1);
        carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
        carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix2);
        carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
        carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix3);
        carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");

        // Commit the transaction
        session.Commit();
      }
    }