Inheritance: OptimizedPersistable
 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();
   }
 }
Beispiel #2
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();
            }
        }
    static void UpdaterThread()
    {
      using (ServerClientSession session = new ServerClientSession(s_systemDir))
      {
        session.BeginUpdate();
        Person Mats = new Person("Mats", "Persson", 22, 1234, null, null);
        session.Persist(Mats);
        Woman Kinga = new Woman("Kinga", "Persson", 56, 234, null, Mats);
        foreach (Person p in session.AllObjects<Person>(true))
        {
          p.Age = (ushort) (p.Age + 1); 
        }
        session.Persist(Kinga);
        session.Commit();
// 5 events
        Thread.Sleep(5000);

        session.BeginUpdate();
        Woman Lidia = new Woman("Lidia", "Persson", 22, 1234, null, null);
        session.Persist(Lidia);
        session.Commit();
// 0 events 
        Thread.Sleep(500);

        session.BeginUpdate();
        Woman Margareta = new Woman("Margareta", "Persson", 98, 1234, null, null);
        session.Persist(Margareta);
        session.Commit();
// 1 event
        Thread.Sleep(500);

        session.BeginUpdate();
        Woman Oliwia = new Woman("Oliwia", "Persson", 50, 1234, null, null);
        session.Persist(Oliwia);
        session.Commit();
// 0 events
        Thread.Sleep(500);

        session.BeginUpdate();
        foreach (Woman p in session.AllObjects<Woman>())
        {
          p.Age = (ushort) (p.Age + 1); 
        }
        session.Commit();
// 3 events
        session.BeginUpdate();
        foreach (Woman p in session.AllObjects<Woman>())
        {
          p.Age = (ushort)(p.Age + 1);
        }
        session.Commit();
// 3 events
      }
    }
 public ArrayOfWeakrefs(SessionBase session)
 {
   anArrayOfWeakRefs = new WeakIOptimizedPersistableReference<Person>[10];
   Person p = new Person();
   p.Persist(session, p);
   anArrayOfWeakRefs[0] = new  WeakIOptimizedPersistableReference<Person>(p);
   p = new Person();
   p.Persist(session, p);
   anArrayOfWeakRefs[1] = new  WeakIOptimizedPersistableReference<Person>(p);
   p = new Person();
   p.Persist(session, p);
   anArrayOfWeakRefs[2] = new  WeakIOptimizedPersistableReference<Person>(p);
   p = new Person();
   p.Persist(session, p);
   anArrayOfWeakRefs[3] = new  WeakIOptimizedPersistableReference<Person>(p);
 }
 static void Main(string[] args)
 {
   using (ServerClientSession session = new ServerClientSession(s_systemDir))
   {
     session.BeginUpdate();
     File.Copy(s_licenseDbFile, Path.Combine(s_systemDir, "4.odb"), true);
     session.RegisterClass(typeof(Woman));
     session.RegisterClass(typeof(Man));
     session.SubscribeToChanges(typeof(Person));
     session.SubscribeToChanges(typeof(Woman), "OlderThan50");
     Person robinHood = new Person("Robin", "Hood", 30, 1234, null, null);
     session.Persist(robinHood);
     Person billGates = new Person("Bill", "Gates", 56, 234, robinHood, null);
     session.Persist(billGates);
     Person steveJobs = new Person("Steve", "Jobs", 56, 456, billGates, null);
     session.Persist(steveJobs);
     session.Commit();
     Thread t = new Thread(UpdaterThread);
     t.Start();
     Thread.Sleep(600);
     
     for (int i = 0; i < 50; i++)
     {
       List<Oid> changes = session.BeginReadWithEvents();
       if (changes.Count == 0)
       {
         Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff"));
         Thread.Sleep(250);
       }
       foreach (Oid id in changes)
       {
         object obj = session.Open(id);
         Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff"));;
         //session.UnsubscribeToChanges(typeof(Person));
       }
       Console.WriteLine();
       session.Commit();
     }       
     t.Join();
   }
 }
Beispiel #6
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();
   }
 }
Beispiel #7
0
        public void Simple()
        {
            UInt64 id;

            // UInt64 autoIncrement = 0;
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                VelocityDbSchema.Person person = new VelocityDbSchema.Person();
                session.Persist(person);
                //Assert.Greater(person.AutoIncrement, autoIncrement);
                UnknownSex u = new UnknownSex();
                session.Persist(u);
                //Assert.Greater(u.AutoIncrement, autoIncrement);
                UnknownSex u2 = new UnknownSex();
                session.Persist(u2);
                //Assert.Greater(u2.AutoIncrement, u.AutoIncrement);
                Man man = new Man();
                session.Persist(man);
                //Assert.AreEqual(man.AutoIncrement, autoIncrement); // Man overrides PlacementDatabaseNumber so no AutoIncrement feature
                id = man.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Man man  = session.Open <Man>(id);
                Man man2 = (Man)man.Clone();
                Assert.NotNull(man);
                Assert.IsFalse(man2.IsPersistent);
                Assert.IsNull(man2.Shape);
                Assert.AreEqual(man2.Id, 0);
                Assert.AreEqual(man2.ShortId, 0);
                Assert.True(man != man2);
                session.Commit();
            }
        }
Beispiel #8
0
 public void bCreateDefaultCompareIntKeyPersonValue(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     Placement personPlace = new Placement((UInt32)number + 1, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.BeginUpdate();
     BTreeMap<int, Person> bTree = new BTreeMap<int, Person>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     Person person;
     for (int i = 0; i < number; i++)
     {
       person = new Person();
       person.Persist(personPlace, session);
       bTree.Add(i, person);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeMap<int, Person> bTree = (BTreeMap<int, Person>)session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (KeyValuePair<int, Person> pair in bTree)
     {
       count++;
       Assert.True(pair.Key == prior++);
       Assert.True(pair.Value != null);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }
Beispiel #9
0
        public void SimpleApiServer()
        {
            long   ssn = 555555;
            UInt16 age = 1;

            VelocityDbSchema.Person mats;
            Placement place;

            using (ServerClientSession session = new ServerClientSession(systemDir))
            {
                // skip delete database since it invalidates indices

                session.BeginUpdate();
                Database db = session.OpenDatabase(10, true, false);
                if (db != null)
                {
                    session.DeleteDatabase(db);
                }
                session.Commit();
                session.BeginUpdate();
                place = new Placement(10, 2, 1, 1, 10);
                DateTime birthday = new DateTime(1960, 6, 13);
                mats = new Man("Mats", "Persson", age++, ssn++, birthday);
                mats.Persist(place, session);
                session.Commit();
                session.ClearServerCache();
            }
            UInt64 mOid1 = Oid.Encode(10, 2, 1);

            using (ServerClientSession session = new ServerClientSession(systemDir))
            {
                session.BeginUpdate();
                UInt32 dbNum = Oid.DatabaseNumber(mOid1);
                mats = (VelocityDbSchema.Person)session.Open(mOid1);
                Woman kinga = null;
                mats = new Man("Mats", "Persson", age++, ssn++, new DateTime(1960, 6, 13));
                Cat cat = new Cat("Boze", 8);
                mats.m_pets.Add(cat);
                Bird bird = new Bird("Pippi", 1);
                cat.friends.Add(bird);
                mats.Persist(place, session);
                kinga = new Woman("Kinga", "Persson", age, ssn, mats, mats);
                kinga.Persist(place, session);
                VelocityDbSchema.Person robin = new VelocityDbSchema.Person("Robin", "Persson", 13, 1, mats, null);
                robin.Persist(place, session);
                mOid1 = mats.Id;
                mats  = null;
                mats  = (VelocityDbSchema.Person)session.Open(mOid1);
                session.Commit();
                session.ClearServerCache();
            }

            using (ServerClientSession session = new ServerClientSession(systemDir))
            {
                session.BeginUpdate();
                mats = (VelocityDbSchema.Person)session.Open(mOid1);
                session.Commit();
                session.ClearServerCache();
            }

            using (ServerClientSession session = new ServerClientSession(systemDir))
            {
                session.BeginRead();
                ulong mOid2 = mats.Id;
                mats = (VelocityDbSchema.Person)session.Open(mOid2);
                session.Commit();
                session.ClearServerCache();
            }
        }
Beispiel #10
0
    public Woman(string firstName, string lastName, UInt16 age, long ssn, Person bestFriend, Person spouse)
      : base(firstName, lastName, age, ssn, bestFriend, spouse)
		{
		}
Beispiel #11
0
 public Woman(Person spouse, Person bestFriend)
   : base(spouse, bestFriend)
 {
 }
    public void SandeepGraph(bool useServerSession)
    {
      bool dirExist = Directory.Exists(systemDir);
      try
      {
        if (Directory.Exists(systemDir))
          Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
        Directory.CreateDirectory(systemDir);
        File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
      }
      catch
      {
        File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
      }
      using (SessionBase session = useServerSession ? (SessionBase)new ServerClientSession(systemDir) : (SessionBase)new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
        Graph g = new Graph(session);
        session.Persist(g);

        // SCHEMA
        VertexType userType = g.NewVertexType("User");
        // 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);
        PropertyType objectPropertyType = g.NewVertexProperty(movieType, "object", DataType.Object, PropertyKind.NotIndexed);
        PropertyType objectPropertyTypeIndexed = g.NewVertexProperty(movieType, "director", DataType.IOptimizedPersistable, PropertyKind.Indexed);

        Vertex mVickyCB = movieType.NewVertex();
        mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona");
        mVickyCB.SetProperty(movieYearType, (int)(2008));
        Person pObj = new Person();
        session.Persist(pObj);
        mVickyCB.SetProperty(objectPropertyType, pObj);
        pObj = new Person();
        Person pSave = null;
        Vertex vSave = null;
        mVickyCB.SetProperty(objectPropertyTypeIndexed, pObj);
        for (int i = 0; i < 100; i++)
        {         
          Vertex vertex =  movieType.NewVertex();
          pObj = new Person();
          vertex.SetProperty(objectPropertyTypeIndexed, pObj);
          if (i == 44)
          {
            pSave = pObj;
            vSave = vertex;
          }
        }
        Vertex lookup = objectPropertyTypeIndexed.GetPropertyVertex(pSave);
        Assert.AreEqual(lookup, vSave);
        Vertex mMatsCB = movieType.NewVertex();
        mMatsCB.SetProperty(movieTitleType, "Mats Cristina Barcelona");
        mMatsCB.SetProperty(movieYearType, (int)(2008));
        pObj = new Person();
        session.Persist(pObj);
        mMatsCB.SetProperty(objectPropertyType, pObj);
        session.Commit();
        session.BeginUpdate();
        try
        {
          mMatsCB.SetProperty(objectPropertyTypeIndexed, null);
          throw new UnexpectedException();
        }
        catch (NullObjectException)
        {

        }
        mMatsCB.Remove();
        session.Commit();
        //session.Persist(g);
        //session.Commit();
      }

      using (SessionBase session = useServerSession ? (SessionBase)new ServerClientSession(systemDir) : (SessionBase)new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        Graph g = Graph.Open(session);
        VertexType movieType = g.FindVertexType("MOVIE");
        Assert.NotNull(movieType);
      }
      Task taskB = new Task(() => WatchUser());
      taskB.Start();
      Task taskA = new Task(() => CreateUser());
      taskA.Start();
      taskB.Wait();
      taskA.Wait();
    }
Beispiel #13
0
    public Man(string firstName, string lastName, UInt16 age, long ssn, DateTime birthday, Person bestFriend = null, Person spouse = null)
      : base(firstName, lastName, age, ssn, bestFriend, spouse)
		{
      this.birthday = birthday;
    }
Beispiel #14
0
 public Man(Person spouse, Person bestFriend, DateTime birthday)
   : base(spouse, bestFriend)
 {
   this.birthday = birthday;
 }