Example #1
0
        public void NavigationThroughRecords( )
        {
            ITable testTable = m_database.GetTable("People");

            Insert_100_NewRecordsAndCheck(testTable, 100);
            IResultSet people = testTable.CreateResultSet(Id);
            int        count  = 0;

            foreach (IRecord person in people)
            {
                person.GetValue(Id);
                count++;
            }
            Assert.AreEqual(100, count);
            people.Dispose();
            people = testTable.CreateResultSet(Id);
            count  = 0;
            foreach (IRecord person in people)
            {
                person.GetValue(Id);
                count++;
            }
            Assert.AreEqual(100, count);
            people.Dispose();
        }
Example #2
0
        public bool MoveNext()
        {
            if (_baseEnumerator == null)
            {
                return(false);
            }
            while (true)
            {
                bool result;
                try
                {
                    result = _baseEnumerator.MoveNext();
                }
                catch (IOException ex)
                {
                    _ioError = true;
                    _resultSet.Dispose();
                    MyPalStorage.Storage.OnIOErrorDetected(ex);
                    return(false);
                }
                catch (BadIndexesException)
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("Bad indexes found in " + _operation);
                    return(false);
                }
                if (!result)
                {
                    return(false);
                }

                try
                {
                    LoadCurrentRecord();
                }
                catch (IOException ex)
                {
                    _ioError = true;
                    _resultSet.Dispose();
                    MyPalStorage.Storage.OnIOErrorDetected(ex);
                    return(false);
                }
                catch (BadIndexesException)
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("Bad indexes found in " + _operation);
                    continue;
                }

                return(true);
            }
        }
Example #3
0
        public void SaveAndLoad( )
        {
            ITable   testTable = m_database.GetTable("People");
            DateTime dateTime  = DateTime.Now;

            for (int i = 0; i < 100; i++)
            {
                InsertRecord(testTable, i.ToString(), i,
                             dateTime.Subtract(new TimeSpan(i, 0, 0, 0)));
            }

            IResultSet people = testTable.CreateResultSet(Id);
            int        count  = 0;

            foreach (IRecord person in people)
            {
                int id = person.GetIntValue(Id);
                Assert.IsTrue(id == count);
                string name = person.GetStringValue(Name);
                Assert.IsTrue(name == count.ToString());
                int age = person.GetIntValue(Age);
                age = age;
                DateTime receivedTime = (DateTime)person.GetValue(Birthday);
                Assert.IsTrue(receivedTime == dateTime.Subtract(new TimeSpan(count, 0, 0, 0)));
                count++;
            }
            Assert.AreEqual(100, count);
            people.Dispose();
        }
Example #4
0
        internal override IntArrayList GetMatchingResources(out bool sortedById)
        {
            bool reverseLink = (_propId < 0 && MyPalStorage.Storage.IsLinkDirected(-_propId));

            IResultSet rs = MyPalStorage.Storage.SelectLinksOfType(reverseLink ? -_propId : _propId);

            try
            {
                IntArrayList list;
                if (reverseLink)
                {
                    list = DoGetResourcesFromResultSet(rs, 1);
                    list.Sort();
                }
                else
                {
                    list = DoGetResourcesFromResultSet(rs, 0);
                    list.Sort();
                    if (!MyPalStorage.Storage.IsLinkDirected(_propId))
                    {
                        IntArrayList list2 = DoGetResourcesFromResultSet(rs, 1);
                        list2.Sort();
                        list = IntArrayList.MergeSorted(list, list2);
                    }
                }

                list.RemoveDuplicatesSorted();
                sortedById = true;
                return(list);
            }
            finally
            {
                rs.Dispose();
            }
        }
Example #5
0
        private void UpdatePropTypeRecord(string propName, IResource res)
        {
            IResultSet rs = _propTypeTable.CreateModifiableResultSet(1, propName);

            try
            {
                IEnumerator enumerator = rs.GetEnumerator();
                using ((IDisposable)enumerator)
                {
                    if (!enumerator.MoveNext())
                    {
                        throw new StorageException("Cannot find the property type to be updated");
                    }

                    IRecord rec = (IRecord)enumerator.Current;
                    if (rec.GetIntValue(2) != res.GetIntProp("DataType"))
                    {
                        throw new StorageException("Invalid attempt to change data type of property " + propName +
                                                   " from " + (PropDataType)rec.GetIntValue(2) +
                                                   " to " + (PropDataType)res.GetIntProp("DataType"));
                    }

                    rec.SetValue(3, res.GetIntProp("Flags"));
                    _storage.SafeCommitRecord(rec, "PropTypeCollection.UpdatePropTypeRecord");
                }
            }
            finally
            {
                rs.Dispose();
            }
        }
Example #6
0
 protected IntArrayList GetResourcesFromResultSet(IResultSet rs, int column)
 {
     try
     {
         return(DoGetResourcesFromResultSet(rs, column));
     }
     finally
     {
         rs.Dispose();
     }
 }
Example #7
0
        public void SortEqualAscWithNoRecords( )
        {
            IResultSet resultSet = _peopleTable.CreateModifiableResultSet(1, "300");
            int        count     = 0;

            foreach (IRecord record in resultSet)
            {
                string name = record.GetStringValue(1);
                name = name;
                count++;
            }
            Assert.AreEqual(0, count, "Count is wrong");
            resultSet.Dispose();
        }
Example #8
0
        public void SortEqualAsc( )
        {
            IResultSet resultSet = _peopleTable.CreateModifiableResultSet(1, "495");
            int        count     = 0;

            foreach (IRecord record in resultSet)
            {
                string name = record.GetStringValue(1);
                Assert.AreEqual("495", name, "Name is wrong");
                count++;
            }
            Assert.AreEqual(1, count, "Count is wrong");
            resultSet.Dispose();
        }
Example #9
0
 protected SafeRecordEnumeratorBase(IResultSet resultSet, string operation)
 {
     _resultSet = resultSet;
     _operation = operation;
     try
     {
         _baseEnumerator = resultSet.GetEnumerator();
     }
     catch (IOException ex)
     {
         _ioError = true;
         _resultSet.Dispose();
         MyPalStorage.Storage.OnIOErrorDetected(ex);
         _baseEnumerator = null;
     }
 }
Example #10
0
        public void SortOnFiled( )
        {
            IResultSet resultSet = m_testTable.CreateResultSet(Name);
            int        count     = 0;

            foreach (IRecord record in resultSet)
            {
                string name = record.GetStringValue(Name);
                name = name;
                count++;
            }
            Assert.AreEqual(10, count);
            resultSet.Dispose();

            return;
        }
Example #11
0
        public void CheckUnicodeStringReading( )
        {
            IRecord record = _peopleTable.NewRecord();
            string  str    = @"Ѓ¦–ўЏі‘ш‚ЖЏі‘шЌLЌђЃЎ8ђз–њ‰~Ћы“ь•ы–@’с‹џѓЃѓ‹ѓ}ѓKЃЎђV”N‚НЃy‚T‰­‚Xђз–њ‰~ЏШ‹’—LѓrѓWѓlѓXЃz‚Е–Ъ“I’Bђ¬6ђз–њ‰~ЏШ‹’—LЋы“ь•ы–@‚ ‚и‚Ь‚·Ѓ@-‚Uђз–њ‰~€И‰є”NЋы‚М•ы‚Й‘еЉЅЊ}‚і‚к‚Д‚ў‚Ь‚·---˜_‚ж‚иЏШ‹’‚Е‚·ЃBЃ@";

            record.SetValue(0, 888);
            record.SetValue(1, str);
            record.Commit();
            IResultSet resultSet = _peopleTable.CreateResultSet(0, 888);

            foreach (IRecord rec in resultSet)
            {
                Assert.AreEqual(str, rec.GetStringValue(1));
            }
            resultSet.Dispose();
        }
Example #12
0
        /**
         * Unregisters the specified property type and deletes all properties
         * of that type.
         */

        public void Delete(int id)
        {
            PropTypeItem item = FindPropTypeItem(id);

            if (item.DataType == PropDataType.Link)
            {
                _storage.DeleteLinksOfType(id);
            }
            else
            {
                _storage.DeletePropsOfType(id);
            }
            ResourceRestrictions.DeletePropRestrictions(id);

            IResultSet rs = _propTypeTable.CreateModifiableResultSet(0, id);

            try
            {
                SafeRecordEnumerator enumerator = new SafeRecordEnumerator(rs, "PropTypes.Delete");
                using ( enumerator )
                {
                    if (!enumerator.MoveNext())
                    {
                        MyPalStorage.Storage.OnIndexCorruptionDetected("PropTypeCollection.Delete: Attempt to delete non-existing property type " + id);
                    }
                    else
                    {
                        IRecord rec = enumerator.Current;
                        _storage.SafeDeleteRecord(rec, "PropTypes.Delete");
                    }
                }
            }
            finally
            {
                rs.Dispose();
            }

            IResource propTypeRes = _storage.FindUniqueResource("PropType", "ID", id);

            Debug.Assert(propTypeRes != null);
            propTypeRes.Delete();
        }
Example #13
0
        /**
         * Loads the property types to the cache hash table.
         */

        internal void CachePropTypes()
        {
            IResultSet rs = _propTypeTable.CreateResultSet(0);

            try
            {
                foreach (IRecord rec in rs)
                {
                    int    ID   = rec.GetIntValue(0);
                    string name = rec.GetStringValue(1);
                    AddPropTypeToCache(ID, name, (PropDataType)rec.GetIntValue(2),
                                       (PropTypeFlags)rec.GetIntValue(3));
                }
            }
            finally
            {
                rs.Dispose();
            }
            _propTypesCached = true;
        }
Example #14
0
        /**
         * Loads the resource types to the cache hash table.
         */

        internal void CacheResourceTypes()
        {
            int        count = 0;
            IResultSet rs    = _resourceTypeTable.CreateResultSet(0);

            try
            {
                foreach (IRecord rec in rs)
                {
                    int    ID   = rec.GetIntValue(0);
                    string name = rec.GetStringValue(1);

                    AddResourceTypeToCache(ID, name, "", ResourceTypeFlags.Normal);
                    count++;
                }
            }
            finally
            {
                rs.Dispose();
            }
            Debug.WriteLine("Loaded " + count + " resource types to cache");
        }
Example #15
0
        public void Search( )
        {
            m_testTable = m_database.GetTable("People");
            for (int i = 0; i < 10; i++)
            {
                IRecord record = m_testTable.NewRecord();
                Assert.AreEqual(i, record.GetID());
                record.SetValue(Name, (500 - i).ToString());
                record.Commit();
                Assert.AreEqual((i + 1), m_testTable.Count);
            }
            IResultSet resultSet = m_testTable.CreateModifiableResultSet(Name, "300");
            int        count     = 0;

            foreach (IRecord record in resultSet)
            {
                string name = record.GetStringValue(Name);
                name = name;
                count++;
            }
            Assert.AreEqual(0, count);
            resultSet.Dispose();
        }
Example #16
0
        public void CheckSaveLoadIndex( )
        {
            ITable testTable = m_database.GetTable("People");

            for (int i = 0; i < 10; i++)
            {
                IRecord record = testTable.NewRecord();
                record.SetValue(Name, i.ToString());
                record.SetValue(Birthday, DateTime.Now.Date);
                record.Commit();
                Assert.IsTrue(testTable.Count == (i + 1));
            }
            m_database.Shutdown();
            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("People");
            Assert.AreEqual(10, testTable.Count);
            IResultSet people = testTable.CreateResultSet(Id);
            int        count  = 0;

            foreach (IRecord person in people)
            {
                int id = person.GetIntValue(Id);
                Assert.AreEqual(count, id);
                string name = person.GetStringValue(Name);
                Assert.AreEqual(count.ToString(), name);
                int age = person.GetIntValue(Age);
                age = age;
                DateTime dateTime = (DateTime)person.GetValue(Birthday);
                Assert.AreEqual(DateTime.Now.Date, dateTime);
                count++;
            }
            Assert.AreEqual(10, count);
            people.Dispose();
        }
Example #17
0
 public void Dispose()
 {
     _resultSet.Dispose();
 }