Inheritance: OptimizedPersistable
Ejemplo n.º 1
0
 public Person(string firstName, string lastName, ushort age, Person bestFriend = null)
 {
   this.firstName = firstName;
   this.lastName = lastName;
   this.age = age;
   this.bestFriend = bestFriend;
   friends = new SortedSetAny<Person>();
 }
Ejemplo n.º 2
0
 public Person(string firstName, string lastName, ushort age, Person bestFriend = null)
 {
   m_firstName = firstName;
   m_lastName = lastName;
   m_age = age;
   m_bestFriend = bestFriend;
   m_friends = new SortedSetAny<Person>();
 }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
   }
 }
Ejemplo n.º 5
0
 public AllSupported(Int32 arraySize)
 {
   enum16list = new List<Int16Enum>(arraySize);
   aSnake = new PersistenceByInterfaceSnake("Curly", 1, true, 58);
   jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 };
   jaggedArray[1] = new int[] { 0, 2, 4, 6 };
   jaggedArray[2] = new int[] { 11, 22 };
   nullabledateTime = null;
   m_nullableByte = null;
   m_enumByte = ByteEnum.b;
   m_enumInt16 = Int16Enum.c;
   m_enumInt32 = Int32Enum.f;
   m_enumInt64 = Int64Enum.ff;
   byteArray = new byte[arraySize];
   charArray = new char[arraySize];
   uint16Array = new UInt16[arraySize];
   uint32Array = new UInt32[arraySize];
   uint64Array = new UInt64[arraySize];
   int16Array = new Int16[arraySize];
   int32Array = new Int32[arraySize];
   int64Array = new Int64[arraySize];
   floatArray = new float[arraySize];
   doubleArray = new double[arraySize];
   dateTimeArray = new DateTime[arraySize];
   oidArray = new Oid[arraySize];
   nullablebyteArray = new byte?[arraySize];
   nullablecharArray = new char?[arraySize];
   nullableuint16Array = new UInt16?[arraySize];
   nullableuint32Array = new UInt32?[arraySize];
   nullableuint64Array = new UInt64?[arraySize];
   nullableint16Array = new Int16?[arraySize];
   nullableint32Array = new Int32?[arraySize];
   nullableint64Array = new Int64?[arraySize];
   nullablefloatArray = new float?[arraySize];
   nullabledoubleArray = new double?[arraySize];
   nullableDateTimeArray = new DateTime?[arraySize];
   nullableDecimalArray = new Decimal?[arraySize];
   nullableGuidArray = new Guid?[arraySize];
   nullableOidArray = new Oid?[arraySize];
   listByte = new List<byte>(arraySize); // just samples of what Key can be
   personList = new List<Person>(arraySize);
   petListOidShort = new List<Pet>(arraySize);
   petListLongOid = new List<Pet>(arraySize);
   petList2 = new ArrayList(arraySize);
   int32List = new List<Int32>(arraySize);
   uint32List = new List<UInt32>(arraySize);
   uint64List = new List<ulong>(arraySize);
   oidList = new List<Oid>(arraySize);
   nullableoidList = new List<Oid?>(arraySize);
   personHashSet = new VelocityDbHashSet<Person>();
   person = new Person();
   timeSpan = new TimeSpan(1, 0, 0);
   personArrayOidShort = new Person[arraySize];
   if (arraySize > 1)
     personArrayOidShort[1] = new Person();
   personArrayOidShort[0] = null;
   personListShort = new List<Person>(arraySize);
   personListShort.Add(null);
   personListShort.Add(null);
   personListShort.Add(new Person());
   aPet = new Cat("Boze", 5);
   petListOidShort.Add(aPet);
   petListOidShort.Add(null);
   petListLongOid.Add(aPet);
   petList2.Add(aPet);
   uint32List.Add(5555);
   int32List.Add(-66666);
   uint64List.Add(8989898988989);
   doubleArray[0] = 0.2323232323232;
   aSlot = new Slot();
   aSlot.value = new Person();
   m_slots = new Slot[5];
   enum16list.Add(m_enumInt16);
   nullableoidList.Add(new Oid((ulong)4444));
   nullableoidList.Add(null);
   nullableoidList.Add(new Oid((ulong)8888));
   if (arraySize > 0)
   {
     oidArray[0] = new Oid((ulong)99999);
     nullableOidArray[0] = new Oid((ulong)99999);
     nullableint32Array[0] = 5;
   }
   if (arraySize > 2)
   {
     oidArray[2] = new Oid((ulong)66666);
     nullableOidArray[2] = new Oid((ulong)66666);
     nullableint32Array[2] = 6;
   }
   for (int i = 0; i < 5; i++)
   {
     m_slots[i].hashCode = i;
     m_slots[i].value = new Person();
     m_slots[i].next = i + 1;
   }
 }
Ejemplo n.º 6
0
 public AllSuportedSub2(Int32 arraySize)
 {
   personArrayOidShort = new Person[arraySize];
   personArrayOidShort[1] = new Person();
   personArrayOidShort[0] = null;
 }
Ejemplo n.º 7
0
    static readonly string s_systemDir = "SortedObjects"; // appended to SessionBase.BaseDatabasePath for a full path

    static void Main(string[] args)
    {
      try
      {
        Oid bTreeId;
        bool createOnly = args.Length > 0;
        UInt64 someRandomPersonsIdNumber = 0;
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
          const UInt32 numberOfPersons = 1000000;
          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();
          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();
            if (i % 1000 == 0)
              someRandomPersonsIdNumber = person.IdNumber;
            bTree.AddFast(person);
          }
          bTreeId = bTree.Oid;
          session.Commit();
        }
        if (!createOnly)
          using (SessionNoServer session = new SessionNoServer(s_systemDir))
          {
            session.BeginRead();
            BTreeSet<Person> bTree = (BTreeSet<Person>)session.Open(bTreeId);
            foreach (Person person in (IEnumerable<Person>)bTree)
            {
              if (person.IdNumber > 196988888791402)
              {
                Console.WriteLine(person);
                break;
              }
            }
            session.Commit();
            session.BeginRead();
            Person lookupPerson = new Person(someRandomPersonsIdNumber);
            UInt64 id = bTree.GetKeyId(lookupPerson); // lookup without opening object having the key field value of someRandomPersonsIdNumber
            Person lookedUpPerson = null;
            bTree.TryGetKey(lookupPerson, ref lookedUpPerson);
            if (id != lookedUpPerson.Id)
              throw new UnexpectedException("Should match");
            // 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();
          }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }