Пример #1
0
 public virtual void Testsearch10()
 {
     NeoDatis.Btree.IBTreeSingleValuePerKey btree = GetBTree(3);
     for (int i = 0; i < 10; i++)
     {
         btree.Insert(i, "key " + i);
     }
     AssertEquals(10, btree.GetSize());
     AssertEquals("key 1", btree.Search(1));
     AssertEquals("key 9", btree.Search(9));
     NeoDatis.Btree.IBTreeNodeOneValuePerKey child3 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                       )btree.GetRoot().GetChildAt(2, false);
     AssertEquals(4, child3.GetNbKeys());
     AssertEquals(6, child3.GetKeyAt(0));
     AssertEquals(7, child3.GetKeyAt(1));
     AssertEquals(8, child3.GetKeyAt(2));
     AssertEquals(9, child3.GetKeyAt(3));
     AssertEquals(null, child3.GetKeyAt(4));
 }
Пример #2
0
        public virtual void TestDelete100000Alpha_2()
        {
            NeoDatis.Btree.IBTreeSingleValuePerKey btree = GetBTree(2);
            int size = 100000;

            for (int i = 0; i < size; i++)
            {
                btree.Insert("key" + i, "value " + i);
            }
            object o = btree.Search("key71");

            AssertEquals(size, btree.GetSize());
            for (int i = size - 1; i >= 0; i--)
            {
                // println(new BTreeDisplay().build(btree));
                AssertEquals("value " + i, btree.Delete("key" + i, "value " + i));
            }
            AssertEquals(0, btree.GetSize());
            AssertEquals(1, btree.GetHeight());
            AssertEquals(0, btree.GetRoot().GetNbKeys());
            AssertEquals(0, btree.GetRoot().GetNbChildren());
        }
Пример #3
0
 public virtual void TestInsert3()
 {
     NeoDatis.Btree.IBTreeSingleValuePerKey btree = GetBTree(3);
     btree.Insert(1, "key 1");
     btree.Insert(2, "key 2");
     btree.Insert(3, "key 3");
     btree.Insert(4, "key 4");
     btree.Insert(5, "key 5");
     btree.Insert(6, "key 6");
     AssertEquals(6, btree.GetSize());
     AssertEquals("key 1", btree.Search(1));
     AssertEquals("key 2", btree.Search(2));
     AssertEquals("key 3", btree.Search(3));
     AssertEquals("key 4", btree.Search(4));
     AssertEquals("key 5", btree.Search(5));
     AssertEquals("key 6", btree.Search(6));
     AssertEquals(2, btree.GetRoot().GetNbChildren());
     // child 1 should be [1,2]
     NeoDatis.Btree.IBTreeNodeOneValuePerKey child1 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                       )btree.GetRoot().GetChildAt(0, false);
     AssertEquals(2, child1.GetNbKeys());
     AssertEquals(0, child1.GetNbChildren());
     AssertEquals("key 1", child1.GetKeyAndValueAt(0).GetValue());
     AssertEquals(1, child1.GetKeyAndValueAt(0).GetKey());
     // child 2 should be [4,5,6]
     NeoDatis.Btree.IBTreeNodeOneValuePerKey child2 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                       )btree.GetRoot().GetChildAt(1, false);
     AssertEquals(3, child2.GetNbKeys());
     AssertEquals(0, child2.GetNbChildren());
     AssertEquals("key 4", child2.GetKeyAndValueAt(0).GetValue());
     AssertEquals("key 5", child2.GetKeyAndValueAt(1).GetValue());
     AssertEquals("key 6", child2.GetKeyAndValueAt(2).GetValue());
     // child 2 should be null
     NeoDatis.Btree.IBTreeNodeOneValuePerKey child3 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                       )btree.GetRoot().GetChildAt(2, false);
     AssertEquals(null, child3);
 }
Пример #4
0
        /// <summary>Execute query using index</summary>
        /// <param name="index"></param>
        /// <param name="inMemory"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <param name="returnObjects"></param>
        /// <returns></returns>
        /// <exception cref="System.Exception">System.Exception</exception>
        private NeoDatis.Odb.Objects <T> ExecuteUsingIndex <T>(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex
                                                               index, bool inMemory, int startIndex, int endIndex, bool returnObjects, NeoDatis.Odb.Core.Query.Execution.IMatchingObjectAction
                                                               queryResultAction)
        {
            // Index that have not been used yet do not have persister!
            if (index.GetBTree().GetPersister() == null)
            {
                index.GetBTree().SetPersister(new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                  (storageEngine));
            }
            bool objectMatches = false;
            long nbObjects     = classInfo.GetNumberOfObjects();
            long btreeSize     = index.GetBTree().GetSize();

            // the two values should be equal
            if (nbObjects != btreeSize)
            {
                NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = storageEngine.GetSession(true
                                                                                             ).GetMetaModel().GetClassInfoFromId(index.GetClassInfoId());
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexIsCorrupted
                                                           .AddParameter(index.GetName()).AddParameter(ci.GetFullClassName()).AddParameter(
                                                               nbObjects).AddParameter(btreeSize));
            }
            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("loading " + nbObjects + " instance(s) of " + classInfo
                                            .GetFullClassName());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.Start();
            }
            PrepareQuery();
            if (query != null)
            {
                queryHasOrderBy = query.HasOrderBy();
            }
            NeoDatis.Btree.IBTree tree = index.GetBTree();
            bool isUnique = index.IsUnique();

            // Iterator iterator = new BTreeIterator(tree,
            // OrderByConstants.ORDER_BY_ASC);
            System.IComparable       key  = ComputeIndexKey(classInfo, index);
            System.Collections.IList list = null;
            // If index is unique, get the object
            if (isUnique)
            {
                NeoDatis.Btree.IBTreeSingleValuePerKey treeSingle = (NeoDatis.Btree.IBTreeSingleValuePerKey
                                                                     )tree;
                object o = treeSingle.Search(key);
                if (o != null)
                {
                    list = new System.Collections.ArrayList();
                    list.Add(o);
                }
            }
            else
            {
                NeoDatis.Btree.IBTreeMultipleValuesPerKey treeMultiple = (NeoDatis.Btree.IBTreeMultipleValuesPerKey
                                                                          )tree;
                list = treeMultiple.Search(key);
            }
            if (list != null)
            {
                System.Collections.IEnumerator iterator = list.GetEnumerator();
                while (iterator.MoveNext())
                {
                    NeoDatis.Odb.OID oid = (NeoDatis.Odb.OID)iterator.Current;
                    // FIXME Why calling this method
                    long position = objectReader.GetObjectPositionFromItsOid(oid, true, true);
                    orderByKey    = null;
                    objectMatches = MatchObjectWithOid(oid, returnObjects, inMemory);
                    if (objectMatches)
                    {
                        queryResultAction.ObjectMatch(oid, GetCurrentObjectMetaRepresentation(), orderByKey
                                                      );
                    }
                }
                queryResultAction.End();
                return(queryResultAction.GetObjects <T>());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.End();
            }
            return(queryResultAction.GetObjects <T>());
        }