Exemplo n.º 1
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.º 2
0
 public void TwoUpdaters1()
 {
   Assert.Throws<OptimisticLockingFailed>(() =>
   {
     UInt64 id;
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       session.BeginUpdate();
       Man man = new Man();
       man.Persist(session, man);
       id = man.Id;
       session.Commit();
       session.BeginUpdate();
       man.Age = ++man.Age;
       Database db = session.NewDatabase(3567);
       using (SessionNoServer session2 = new SessionNoServer(systemDir))
       {
         session2.BeginUpdate();
         Man man2 = (Man)session2.Open(id);
         Assert.Less(man2.Age, man.Age);
         man2.Age = ++man.Age;
         session2.Commit();
       }
       session.DeleteDatabase(db);
       session.Commit(); // OptimisticLockingFailed here
     }
   });
 }
Exemplo n.º 3
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.º 4
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 
          }
        }
      }
    }
Exemplo n.º 5
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();
   }
 }
Exemplo n.º 6
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();
   }
 }
Exemplo n.º 7
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.º 8
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());
      }
    }
 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();
   }
 }
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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();
   }
 }
Exemplo n.º 15
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();
   }
 }
Exemplo n.º 16
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.º 17
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();
 }
Exemplo n.º 18
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();
 }
Exemplo n.º 19
0
 public void CsvImport()
 {
   using (SessionNoServer session = new SessionNoServer(systemDirCvsImport))
   {
     session.BeginUpdate();
     session.ImportFromCSV(csvExportDir);
     session.Commit();
   }
   Verify(systemDirCvsImport);
 }
Exemplo n.º 20
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.º 21
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.º 22
0
 public void cDeleteDatabases()
 {
   Database database;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     for (uint i = 50000000; i < 50001000; i++)
     {
       database = session.OpenDatabase(i);
       session.DeleteDatabase(database);
     }
     session.Commit();
   }
 }
Exemplo n.º 23
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.º 24
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.º 25
0
 public void SingleReaderSingleUpdater3()
 {
   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;
     session.FlushUpdates();
     using (SessionNoServer session2 = new SessionNoServer(systemDir))
     {
       session2.BeginRead();
       Man man2 = (Man)session2.Open(id);
       Assert.Less(man2.Age, man.Age);
       session2.Commit();
     }
     session.Commit();
   }
 }
Exemplo n.º 26
0
        public void SingleReaderSingleUpdater2()
        {
            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;
                using (var session2 = new SessionNoServerShared(systemDir))
                {
                    session2.BeginRead();
                    Man man2 = (Man)session2.Open(id);
                    Assert.Less(man2.Age, man.Age);
                    session2.Commit();
                }
                session.Commit();
            }
            System.GC.Collect();
        }
Exemplo n.º 27
0
        public void cDeleteDatabases()
        {
            Database database;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (uint i = 50000000; i < 50001000; i++)
                {
                    database = session.OpenDatabase(i);
                    session.DeleteDatabase(database);
                }
                session.Commit();
            }
        }
Exemplo n.º 28
0
        public void fullShiftRightTest()
        {
            Oid id;
            int ct = 0;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                BTreeSet <int> bTree = new BTreeSet <int>(null, session, 9);
                session.Persist(bTree);
                id = bTree.Oid;
                for (int i = 65; i >= 0; i -= 5)
                {
                    bTree.Add(i);
                    ct++;
                }
                bTree.Remove(65);
                ct--;
                bTree.Remove(60);
                ct--;
                bTree.Remove(55);
                ct--;
                bTree.Remove(50);
                ct--;
                bTree.Add(1);
                ct++;
                bTree.Add(2);
                ct++;
                bTree.Add(3);
                ct++;
                bTree.Add(4);
                ct++;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeSet <int> bTree = (BTreeSet <int>)session.Open(id);
                int            count = 0;
                foreach (int num in bTree)
                {
                    count++;
                }
                Assert.True(ct == bTree.Count);
                Assert.True(ct == bTree.Count());
                session.Commit();
            }
        }
Exemplo n.º 29
0
        public void zeroSizeByInterface()
        {
            UInt64 id = 0;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (int i = 0; i < 100000; i++)
                {
                    var o = new EFTPOSMachineParent();
                    session.Persist(o);
                    if (i % 25000 == 0)
                    {
                        id = o.Id;
                    }
                }
                var o2 = (EFTPOSMachineParent)session.Open(id);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                var o2 = (EFTPOSMachineParent)session.Open(id);
                Assert.NotNull(o2);
                Assert.NotNull(o2.TransactionFacilitator);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                var o2 = (EFTPOSMachineParent)session.Open(id);
                Assert.NotNull(o2);
                Assert.NotNull(o2.TransactionFacilitator);
                o2.Unpersist(session);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                var o2 = (EFTPOSMachineParent)session.Open(id);
                Assert.Null(o2);
                id++;
                o2 = (EFTPOSMachineParent)session.Open(id);
                Assert.NotNull(o2);
                Assert.NotNull(o2.TransactionFacilitator);
                session.Commit();
            }
        }
Exemplo n.º 30
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.º 31
0
        public void SortedMapTest()
        {
            var client = new SessionNoServer(systemDir);

            client.BeginUpdate();
            var set = new SortedMap <string, object>();

            set.Add("test", "Test text for example.");
            set.Persist(client, set);
            client.Commit();
            client.BeginRead();
            var readSet = client.AllObjects <SortedMap <string, object> >(false, false).FirstOrDefault(rec => rec.Id == set.Id);

            Assert.IsNotNull(readSet);
            client.Commit();
        }
Exemplo n.º 32
0
 public void Transaction2()
 {
     Assert.Throws <TryingToBeginReadOnlyTransactionWhileInUpdateTransactionException>(() =>
     {
         UInt64 id;
         using (SessionNoServer session = new SessionNoServer(systemDir))
         {
             session.BeginUpdate();
             session.BeginRead();
             Man man = new Man();
             man.Persist(session, man);
             id = man.Id;
             session.Commit();
         }
     });
 }
Exemplo n.º 33
0
 public void ArrayOfWeakRefs()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         ArrayOfWeakrefs weakRefArray = new ArrayOfWeakrefs(session);
         weakRefArray.Persist(session, weakRefArray);
         session.Commit();
         using (SessionNoServer session2 = new SessionNoServer(systemDir))
         {
             session2.BeginRead();
             weakRefArray = (ArrayOfWeakrefs)session2.Open(weakRefArray.Id);
             session2.Commit();
         }
     }
 }
Exemplo n.º 34
0
        static readonly string s_systemDir = "UpdateClass"; // appended to SessionBase.BaseDatabasePath

        static int Main(string[] args)
        {
            try
            {
                Trace.Listeners.Add(new ConsoleTraceListener());
                VelocityDbSchema.Samples.UpdateClass.UpdatedClass updatedClassObject;
                int ct1 = 0;
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.SetTraceDbActivity(Schema.SchemaDB);
                    session.BeginUpdate();
                    session.UpdateClass(typeof(VelocityDbSchema.Samples.UpdateClass.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(VelocityDbSchema.Samples.UpdateClass.UpdatedClass));
                    foreach (var obj in session.AllObjects <VelocityDbSchema.Samples.UpdateClass.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 (var obj in db.AllObjects <VelocityDbSchema.Samples.UpdateClass.UpdatedClass>())
                        {
                            ct2++;
                        }
                    }
                    Debug.Assert(ct1 == ct2);
                    updatedClassObject = new VelocityDbSchema.Samples.UpdateClass.UpdatedClass();
                    session.Persist(updatedClassObject);
                    session.Commit();
                    MoveToDifferentFullClassName();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(1);
            }
            return(0);
        }
Exemplo n.º 35
0
            public void Initialize()
            {
                Console.WriteLine("\n***************Initializing...***************");

                using (var session = new SessionNoServer(SystemDir))
                {
                    session.BeginUpdate();

                    session.RegisterClass(typeof(DynamicDictionary));
                    session.RegisterClass(typeof(PersistableDynamicDictionary));
                    session.RegisterClass(typeof(TestEvent));

                    session.Commit();
                }

                Console.WriteLine("***************Complete***************");
            }
Exemplo n.º 36
0
 // POST api/graph
 public void Post(string path, int id, [FromBody]string json)
 {
   using (SessionNoServer session = new SessionNoServer(path))
   {
     session.BeginUpdate();
     Graph graph = Graph.Open(session, id);
     if (graph == null)
       graph = new Graph(session);
     else
       graph.Clear();
     using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
     {
       graph.ImportGraphJson(ms);
       session.Commit();
     }
   }
 }
Exemplo n.º 37
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.º 38
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.º 39
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.º 40
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.º 41
0
 protected void LoginButton_Click(object sender, EventArgs e)
 {
     if (Password.Text.Length == 0)
     {
         ErrorMessage.Text = "Enter your password.";
         return;
     }
     try
     {
         using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true))
         {
             session.BeginUpdate();
             Root velocityDbroot = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false);
             if (velocityDbroot == null)
             {
                 ErrorMessage.Text = "The entered email address is not registered with this website";
                 session.Abort();
                 return;
             }
             CustomerContact lookup = new CustomerContact(Email.Text, null);
             if (!velocityDbroot.customersByEmail.TryGetKey(lookup, ref lookup))
             {
                 ErrorMessage.Text = "The entered email address is not registered with this website";
                 session.Abort();
                 return;
             }
             if (lookup.password != Password.Text)
             {
                 ErrorMessage.Text = "The entered password does not match the registered password";
                 session.Abort();
                 return;
             }
             session.Commit();
             Session["UserName"]  = lookup.UserName;
             Session["Email"]     = Email.Text;
             Session["FirstName"] = lookup.FirstName;
             Session["LastName"]  = lookup.LastName;
             FormsAuthentication.RedirectFromLoginPage(Email.Text, false);
         }
     }
     catch (System.Exception ex)
     {
         ErrorMessage.Text = ex.ToString() + ex.Message;
     }
 }
Exemplo n.º 42
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.º 43
0
 protected void LoginButton_Click(object sender, EventArgs e)
 {
   if (Password.Text.Length == 0)
   {
     ErrorMessage.Text = "Enter your password.";
     return;
   }
   try
   {
     using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true))
     {
       session.BeginUpdate();
       Root velocityDbroot = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false);
       if (velocityDbroot == null)
       {
         ErrorMessage.Text = "The entered email address is not registered with this website";
         session.Abort();
         return;
       }
       CustomerContact lookup = new CustomerContact(Email.Text, null);
       if (!velocityDbroot.customersByEmail.TryGetKey(lookup, ref lookup))
       {
         ErrorMessage.Text = "The entered email address is not registered with this website";
         session.Abort();
         return;
       }
       if (lookup.password != Password.Text)
       {
         ErrorMessage.Text = "The entered password does not match the registered password";
         session.Abort();
         return;
       }
       session.Commit();
       Session["UserName"] = lookup.UserName;
       Session["Email"] = Email.Text;
       Session["FirstName"] = lookup.FirstName;
       Session["LastName"] = lookup.LastName;
       FormsAuthentication.RedirectFromLoginPage(Email.Text, false);
     }
   }
   catch (System.Exception ex)
   {
     ErrorMessage.Text = ex.ToString() + ex.Message;
   }
 }
Exemplo n.º 44
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.º 45
0
 public void NonPersistentTest()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         Test_Persist2 persistable2 = new Test_Persist2();
         persistable2.date_time_field = DateTime.Parse("1/1/1970");
         Test_Non_Persist non_persist = new Test_Non_Persist();
         non_persist.string_field = "bbb";
         non_persist.date_field   = DateTime.Parse("1/1/1960");
         Test_Persist1 persistable1 = new Test_Persist1();
         persistable1.Field1                  = "aaaa";
         persistable1.my_test_class           = persistable2;
         persistable1.My_NonPersistable_Thing = non_persist;
         session.Persist(persistable1);
         session.Commit();
     }
 }
Exemplo n.º 46
0
 public void CreateDefaultCompareFailException()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         Man   aMan;
         Woman aWoman;
         session.BeginUpdate();
         BTreeSet <Person> bTree = new BTreeSet <Person>(null, session);
         for (int i = 0; i < 1000000; i++)
         {
             aMan   = new Man();
             aWoman = new Woman();
             bTree.Add(aMan);
             bTree.Add(aWoman);
         }
         session.Commit();
     }
 }
Exemplo n.º 47
0
 public void Dispose()
 {
     using (SessionNoServer session = new SessionNoServer(SystemDir))
     {
         session.BeginUpdate();
         DatabaseLocation defaultLocation = session.DatabaseLocations.Default();
         List <Database>  dbList          = session.OpenLocationDatabases(defaultLocation, true);
         foreach (Database db in dbList)
         {
             if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers)
             {
                 session.DeleteDatabase(db);
             }
         }
         session.DeleteLocation(defaultLocation);
         session.Commit();
     }
 }
Exemplo n.º 48
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.º 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
        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.º 51
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.º 52
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.º 53
0
 static void CreateInvertedIndex()
 {
     using (SessionNoServer session = new SessionNoServer(s_systemDir, 5000, false, false, CacheEnum.No)) // turn of page and object caching))
     {
         session.BeginUpdate();
         session.RegisterClass(typeof(Repository));
         session.RegisterClass(typeof(IndexRoot));
         session.RegisterClass(typeof(Lexicon <string>));
         Console.WriteLine(DateTime.Now.ToString() + ", start creating inverted index");
         IndexRoot           indexRoot   = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
         BTreeSet <Document> documentSet = indexRoot.Repository.DocumentSet;
         foreach (var doc in documentSet)
         {
             createDocumentInvertedIndex(indexRoot, doc);
         }
         session.Commit();
         Console.WriteLine(DateTime.Now.ToString() + ", done creating inverted index");
     }
 }
Exemplo n.º 54
0
 public void DeleteUserVertices()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
     {
         session.BeginUpdate();
         Graph      g                    = Graph.Open(session); // it takes a while to open graph fresh from databases
         VertexType userType             = g.FindVertexType("User");
         VertexType locationType         = g.FindVertexType("Location");
         EdgeType   friendEdgeType       = g.FindEdgeType("Friend");
         EdgeType   userLocationEdgeType = g.FindEdgeType("UserLocation");
         for (int i = 1; i < numberOfUserVertices; i++)
         {
             userType.RemoveVertex(new Vertex(g, userType, i));
         }
         Assert.IsTrue(friendEdgeType.GetEdges().Count() == 0);
         session.Commit();
         Validate();
     }
 }
Exemplo n.º 55
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.º 56
0
 public void ListOfStrings()
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         var l1 = new ValidNameList();
         l1.AddValidName(new ValidName("Kinga"));
         var names = new ValidNames("Mats", l1, new ValidNameList(), new ValidNameList());
         _id = session.Persist(names);
         session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.BeginRead();
         var names = session.Open <ValidNames>(_id);
         Assert.NotNull(names);
         session.Commit();
     }
 }
Exemplo n.º 57
0
        public void SortedMapTest2()
        {
            const string key    = "test";
            const string value  = "Test text for example.";
            var          client = new SessionNoServer(systemDir);

            client.BeginUpdate();
            var originalRecord = new SortedMap <string, object>();

            originalRecord.Add(key, value);
            originalRecord.Persist(client, originalRecord);
            client.Commit();
            client.BeginRead();
            var newRecord = client.AllObjects <SortedMap <string, object> >(false, false).FirstOrDefault(r => r.Id == originalRecord.Id);

            Assert.IsNotNull(newRecord);
            Assert.AreEqual(originalRecord[key], newRecord[key]);
            client.Commit();
            client.Dispose();
        }
Exemplo n.º 58
0
 public void UnpersistFileFoldersTest()
 {
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         session.NotifyBeforeCommit = NotifyBeforeCommit;
         session.BeginUpdate();
         Assert.Less(10, session.AllObjects <Folder>().Count);
         Assert.Less(10, session.AllObjects <FileInDb>().Count);
         DirectoryInfo dirInfo = new DirectoryInfo(s_sampleFolder);
         Folder        folder  = (from f in session.AllObjects <Folder>(false) where f.Name == dirInfo.Name && f.ParentFolder == null select f).FirstOrDefault();
         folder.Unpersist(session);
         session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(s_systemDir))
     {
         session.BeginRead();
         Assert.AreEqual(0, session.AllObjects <Folder>().Count);
         Assert.AreEqual(0, session.AllObjects <FileInDb>().Count);
         session.Commit();
     }
 }
Exemplo n.º 59
0
 // POST api/graph
 public void Post(string path, int id, [FromBody] string json)
 {
     using (SessionNoServer session = new SessionNoServer(path))
     {
         session.BeginUpdate();
         Graph graph = Graph.Open(session, id);
         if (graph == null)
         {
             graph = new Graph(session);
         }
         else
         {
             graph.Clear();
         }
         using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
         {
             graph.ImportGraphJson(ms);
             session.Commit();
         }
     }
 }
Exemplo n.º 60
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();
            }
        }