public AbstractBTreeNode() { this.btree = null; this.degree = -1; this.maxNbKeys = -1; this.maxNbChildren = -1; keys = null; values = null; nbKeys = 0; nbChildren = 0; }
private void BasicInit(NeoDatis.Btree.IBTree btree) { this.btree = btree; this.degree = btree.GetDegree(); this.maxNbKeys = 2 * degree - 1; this.maxNbChildren = 2 * degree; keys = new System.IComparable[maxNbKeys]; values = new object[maxNbKeys]; nbKeys = 0; nbChildren = 0; Init(); }
// println(new BTreeDisplay().build(btree)); // assertEquals("70", btree.getRoot().getKeyAndValueAt(0).getValue()); // assertEquals("71", btree.getRoot().getKeyAndValueAt(1).getValue()); /// <exception cref="System.Exception"></exception> public virtual void TestDelete10_3() { NeoDatis.Btree.IBTree btree = GetBTree(3); int size = 10; for (int i = 0; i < size; i++) { btree.Insert(i, "value " + i); } AssertEquals(size, btree.GetSize()); for (int i = size - 1; i >= 0; i--) { AssertEquals("value " + i, btree.Delete(i, "value " + i)); } AssertEquals(0, btree.GetSize()); AssertEquals(1, btree.GetHeight()); AssertEquals(0, btree.GetRoot().GetNbKeys()); AssertEquals(0, btree.GetRoot().GetNbChildren()); }
public virtual NeoDatis.Odb.OID SaveBTree(NeoDatis.Btree.IBTree treeToSave) { nbSaveTree++; try { NeoDatis.Odb.OID oid = (NeoDatis.Odb.OID)treeToSave.GetId(); if (oid == null) { // first get the oid. -2 : it could be any value oid = engine.GetObjectWriter().GetIdManager().GetNextObjectId(-2); treeToSave.SetId(oid); oid = engine.Store(oid, treeToSave); if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Saved btree " + treeToSave.GetId() + " with id " + oid + " and root " + treeToSave.GetRoot()); } if (this.tree == null) { this.tree = treeToSave; } oids.Add(oid, treeToSave); } else { oids.Add(oid, treeToSave); AddModifiedOid(oid); } return(oid); } catch (System.Exception e) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Btree.BTreeError.InternalError , e); } }
public virtual void SetBTree(NeoDatis.Btree.IBTree btree) { this.btree = btree; }
public AbstractBTreeNode(NeoDatis.Btree.IBTree btree) { BasicInit(btree); }
public virtual void AddIndexOn(string className, string indexName, string[] indexFields , bool verbose, bool acceptMultipleValuesForSameKey) { NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo = GetMetaModel().GetClassInfo (className, true); if (classInfo.HasIndex(indexName)) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexAlreadyExist .AddParameter(indexName).AddParameter(className)); } NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex cii = classInfo.AddIndexOn(indexName , indexFields, acceptMultipleValuesForSameKey); NeoDatis.Btree.IBTree btree = null; if (acceptMultipleValuesForSameKey) { btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeMultiple(className, NeoDatis.Odb.OdbConfiguration .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister (this)); } else { btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeSingle(className, NeoDatis.Odb.OdbConfiguration .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister (this)); } cii.SetBTree(btree); Store(cii); // Now The index must be updated with all existing objects. if (classInfo.GetNumberOfObjects() == 0) { // There are no objects. Nothing to do return; } if (verbose) { NeoDatis.Tool.DLogger.Info("Creating index " + indexName + " on class " + className + " - Class has already " + classInfo.GetNumberOfObjects() + " Objects. Updating index" ); } if (verbose) { NeoDatis.Tool.DLogger.Info(indexName + " : loading " + classInfo.GetNumberOfObjects () + " objects from database"); } // We must load all objects and insert them in the index! NeoDatis.Odb.Objects <object> objects = GetObjectInfos <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (className), false, -1, -1, false); if (verbose) { NeoDatis.Tool.DLogger.Info(indexName + " : " + classInfo.GetNumberOfObjects() + " objects loaded" ); } NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = null; int i = 0; bool monitorMemory = NeoDatis.Odb.OdbConfiguration.IsMonitoringMemory(); while (objects.HasNext()) { nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)objects.Next(); btree.Insert(cii.ComputeKey(nnoi), nnoi.GetOid()); if (verbose && i % 1000 == 0) { if (monitorMemory) { NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("Index " + indexName + " " + i + " objects inserted", true); } } i++; } if (verbose) { NeoDatis.Tool.DLogger.Info(indexName + " created!"); } }
public virtual void SetBTree(NeoDatis.Btree.IBTree tree) { }
public BTreeNodeMultipleValuesPerKey(NeoDatis.Btree.IBTree btree) : base(btree) { }
private NeoDatis.Btree.IBTreeNodeOneValuePerKey GetBTreeNode(NeoDatis.Btree.IBTree tree, string name) { return(new NeoDatis.Test.Btree.Impl.Singlevalue.MockBTreeNodeSingleValue(tree, name )); }
public InMemoryBTreeNodeSingleValuePerkey(NeoDatis.Btree.IBTree btree) : base(btree ) { id = nextId++; }
/// <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>()); }
public InMemoryBTreeNodeMultipleValuesPerKey(NeoDatis.Btree.IBTree btree) : base( btree) { id = nextId++; }
/// <param name="tree"></param> /// <param name="orderByType"></param> public BTreeIteratorMultipleValuesPerKey(NeoDatis.Btree.IBTree tree, NeoDatis.Odb.Core.OrderByConstants orderByType) : base(tree, orderByType) { currenListIndex = 0; currentValue = null; }
public virtual void SetBTree(NeoDatis.Btree.IBTree tree) { this.tree = tree; }
public virtual void TestDelete27() { NeoDatis.Btree.IBTree tree = GetBTree(3); tree.Insert("P", "P"); NeoDatis.Btree.IBTreeNodeOneValuePerKey PNode = (NeoDatis.Btree.IBTreeNodeOneValuePerKey )tree.GetRoot(); NeoDatis.Btree.IBTreeNodeOneValuePerKey CGMNode = GetBTreeNode(tree, "cgm"); CGMNode.InsertKeyAndValue("C", "C"); CGMNode.InsertKeyAndValue("G", "G"); CGMNode.InsertKeyAndValue("M", "M"); NeoDatis.Btree.IBTreeNodeOneValuePerKey TXNode = GetBTreeNode(tree, "tx"); TXNode.InsertKeyAndValue("T", "T"); TXNode.InsertKeyAndValue("X", "X"); PNode.SetChildAt(CGMNode, 0); PNode.SetChildAt(TXNode, 1); PNode.SetNbChildren(2); NeoDatis.Btree.IBTreeNodeOneValuePerKey ABNode = GetBTreeNode(tree, "ab"); ABNode.InsertKeyAndValue("A", "A"); ABNode.InsertKeyAndValue("B", "B"); NeoDatis.Btree.IBTreeNodeOneValuePerKey DEFode = GetBTreeNode(tree, "def"); DEFode.InsertKeyAndValue("D", "D"); DEFode.InsertKeyAndValue("E", "E"); DEFode.InsertKeyAndValue("F", "F"); NeoDatis.Btree.IBTreeNodeOneValuePerKey JKLNode = GetBTreeNode(tree, "jkl"); JKLNode.InsertKeyAndValue("J", "J"); JKLNode.InsertKeyAndValue("K", "K"); JKLNode.InsertKeyAndValue("L", "L"); NeoDatis.Btree.IBTreeNodeOneValuePerKey NONode = GetBTreeNode(tree, "no"); NONode.InsertKeyAndValue("N", "N"); NONode.InsertKeyAndValue("O", "O"); CGMNode.SetChildAt(ABNode, 0); CGMNode.SetChildAt(DEFode, 1); CGMNode.SetChildAt(JKLNode, 2); CGMNode.SetChildAt(NONode, 3); CGMNode.SetNbChildren(4); NeoDatis.Btree.IBTreeNodeOneValuePerKey QRSNode = GetBTreeNode(tree, "qrs"); QRSNode.InsertKeyAndValue("Q", "Q"); QRSNode.InsertKeyAndValue("R", "R"); QRSNode.InsertKeyAndValue("S", "S"); NeoDatis.Btree.IBTreeNodeOneValuePerKey UVNode = GetBTreeNode(tree, "uv"); UVNode.InsertKeyAndValue("U", "U"); UVNode.InsertKeyAndValue("V", "V"); NeoDatis.Btree.IBTreeNodeOneValuePerKey YZNode = GetBTreeNode(tree, "yz"); YZNode.InsertKeyAndValue("Y", "Y"); YZNode.InsertKeyAndValue("Z", "Z"); TXNode.SetChildAt(QRSNode, 0); TXNode.SetChildAt(UVNode, 1); TXNode.SetChildAt(YZNode, 2); TXNode.SetNbChildren(3); string s1 = "h=1:[P]" + "h=2:[C,G,M][T,X]" + "h=3:[A,B][D,E,F][J,K,L][N,O][Q,R,S][U,V][Y,Z]"; // case 1 string s2AfterDeleteingF = "h=1:[P]" + "h=2:[C,G,M][T,X]" + "h=3:[A,B][D,E][J,K,L][N,O][Q,R,S][U,V][Y,Z]"; object F = tree.Delete("F", "F"); AssertEquals("F", F); string s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false) .ToString(); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty); AssertEquals(s2AfterDeleteingF, s); // case 2a string s2AfterDeleteingM = "h=1:[P]" + "h=2:[C,G,L][T,X]" + "h=3:[A,B][D,E][J,K][N,O][Q,R,S][U,V][Y,Z]"; object M = tree.Delete("M", "M"); AssertEquals("M", M); s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString (); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty); AssertEquals(s2AfterDeleteingM, s); // case 2c string s2AfterDeleteingG = "h=1:[P]" + "h=2:[C,L][T,X]" + "h=3:[A,B][D,E,J,K][N,O][Q,R,S][U,V][Y,Z]"; object G = tree.Delete("G", "G"); AssertEquals("G", G); s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString (); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty); AssertEquals(s2AfterDeleteingG, s); // case 3b string s2AfterDeleteingD = "h=1:[C,L,P,T,X]" + "h=2:[A,B][E,J,K][N,O][Q,R,S][U,V][Y,Z]"; object D = tree.Delete("D", "D"); // assertEquals(2, tree.getHeight()); AssertEquals("D", D); s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString (); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "h=3:", string.Empty); AssertEquals(s2AfterDeleteingD, s); // case 3a string s2AfterDeleteingB = "h=1:[E,L,P,T,X]" + "h=2:[A,C][J,K][N,O][Q,R,S][U,V][Y,Z]"; object B = tree.Delete("B", "B"); AssertEquals("B", B); s = new NeoDatis.Btree.Tool.BTreeDisplay().Build(tree.GetRoot(), 3, false).ToString (); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, " ", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "\n", string.Empty); s = NeoDatis.Tool.Wrappers.OdbString.ReplaceToken(s, "h=3:", string.Empty); AssertEquals(s2AfterDeleteingB, s); }
public BTreeNodeSingleValuePerKey(NeoDatis.Btree.IBTree btree) : base(btree) { }
public MockBTreeNodeSingleValue(NeoDatis.Btree.IBTree btree, string name) : base( btree) { this.name = name; }
public virtual NeoDatis.Btree.IBTree LoadBTree(object id) { nbLoadTree++; NeoDatis.Odb.OID oid = (NeoDatis.Odb.OID)id; try { if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Loading btree with id " + oid); } if (oid == NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.StorageEngineConstant.NullObjectId) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Btree.BTreeError.InvalidIdForBtree .AddParameter(NeoDatis.Odb.Impl.Core.Layers.Layer3.Engine.StorageEngineConstant. NullObjectId)); } tree = (NeoDatis.Btree.IBTree)engine.GetObjectFromOid(oid); tree.SetId(oid); tree.SetPersister(this); NeoDatis.Btree.IBTreeNode root = tree.GetRoot(); root.SetBTree(tree); return tree; } catch (System.Exception e) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Btree.BTreeError.InternalError , e); } }
public ODBBTreeNodeSingle(NeoDatis.Btree.IBTree btree) : base(btree) { }
public virtual NeoDatis.Odb.OID SaveBTree(NeoDatis.Btree.IBTree treeToSave) { nbSaveTree++; try { NeoDatis.Odb.OID oid = (NeoDatis.Odb.OID)treeToSave.GetId(); if (oid == null) { // first get the oid. -2 : it could be any value oid = engine.GetObjectWriter().GetIdManager().GetNextObjectId(-2); treeToSave.SetId(oid); oid = engine.Store(oid, treeToSave); if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId)) { NeoDatis.Tool.DLogger.Debug("Saved btree " + treeToSave.GetId() + " with id " + oid + " and root " + treeToSave.GetRoot()); } if (this.tree == null) { this.tree = treeToSave; } oids.Add(oid, treeToSave); } else { oids.Add(oid, treeToSave); AddModifiedOid(oid); } return oid; } catch (System.Exception e) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Btree.BTreeError.InternalError , e); } }
public virtual NeoDatis.Odb.OID SaveBTree(NeoDatis.Btree.IBTree tree) { // TODO Auto-generated method stub return(null); }
public BTreeIteratorSingleValuePerKey(NeoDatis.Btree.IBTree tree, NeoDatis.Odb.Core.OrderByConstants orderByType) : base(tree, orderByType) { }
public ODBBTreeNodeMultiple(NeoDatis.Btree.IBTree btree) : base(btree) { }