public ClassEntry Search(uint cid) { //time consuming operations, that's the reason for cache if (m_cid_cache.ContainsKey(cid)) { ClassEntry t = (ClassEntry)m_cid_cache[cid]; t.BreakLinks(); t.BuildLinks(m_LRU, m_LRU.Next); return(t); } else { //do the sequential search, :( OOD.Imp.Storage.BTree.BTEnumerator bt = m_tree.GetEnumerator(); while (bt.MoveNext()) { KCatalog key = (KCatalog)bt.Current; Debug.Assert(key != null); if (key.ClassInfo != null && key.ClassInfo.CId == cid) { //found _put_in_cache(cid, key.ClassName, key.ClassInfo.FieldNames, key.ClassInfo.TopNodeSId); return((ClassEntry)m_cid_cache[cid]); } } return(null); } }
public bool Insert(string className, string[] fields, uint topNodeSId, ref uint assignedCId) { if (m_name_cache.ContainsKey(className)) { return(false); } //no duplicates allowed. if (Search(className) != null) { return(false); } assignedCId = m_next_cid++; KCatalog key = new KCatalog(className); DCatalog data = new DCatalog(assignedCId, fields, topNodeSId); key.ClassInfo = data; bool succeed = m_tree.Insert(key); if (succeed) { _put_in_cache(assignedCId, className, fields, topNodeSId); } return(succeed); }
public ClassEntry Search(string className) { if (m_name_cache.ContainsKey(className)) { ClassEntry result = (ClassEntry)m_name_cache[className]; result.BreakLinks(); result.BuildLinks(m_LRU, m_LRU.Next); return(result); } else { //not in cache, get it from disk KCatalog target = new KCatalog(className); KCatalog t = (KCatalog)m_tree.Search(target); if (t != null) { _put_in_cache(t.ClassInfo.CId, className, t.ClassInfo.FieldNames, t.ClassInfo.TopNodeSId); return((ClassEntry)m_cid_cache[t.ClassInfo.CId]); } else { return(null); } } }
public IKey Deserialize(byte[] bytes, int offset, int count) { int pos = offset; KCatalog result = new KCatalog(); short len = OOD.Utility.Bytes.Unpack2(bytes, pos); pos += 2; result.m_className = System.Text.ASCIIEncoding.ASCII.GetString(bytes, pos, len); pos += len; if (count > len + 2) { DCatalog catFactory = new DCatalog(); result.m_info = (DCatalog)catFactory.Deserialize(bytes, pos, count - len - 2); } return(result); }
public bool Insert(string className, string[] fields, uint topNodeSId, ref uint assignedCId) { if (m_name_cache.ContainsKey(className)) return false; //no duplicates allowed. if (Search(className) != null) return false; assignedCId = m_next_cid++; KCatalog key = new KCatalog(className); DCatalog data = new DCatalog(assignedCId, fields, topNodeSId); key.ClassInfo = data; bool succeed = m_tree.Insert(key); if (succeed) _put_in_cache(assignedCId, className, fields, topNodeSId); return succeed; }
public ClassEntry Search(string className) { if (m_name_cache.ContainsKey(className)) { ClassEntry result = (ClassEntry)m_name_cache[className]; result.BreakLinks(); result.BuildLinks(m_LRU, m_LRU.Next); return result; } else { //not in cache, get it from disk KCatalog target = new KCatalog(className); KCatalog t = (KCatalog)m_tree.Search(target); if (t != null) { _put_in_cache(t.ClassInfo.CId, className, t.ClassInfo.FieldNames, t.ClassInfo.TopNodeSId); return (ClassEntry)m_cid_cache[t.ClassInfo.CId]; } else return null; } }
public bool UpdateTopNodeSId(string className, uint newTopNodeSId) { ClassEntry oldValue = Search(className); if (oldValue != null) { //update cache ((ClassEntry)m_cid_cache[oldValue.CId]).SetTopNodeSId(newTopNodeSId); //update the b-tree file KCatalog newKey = new KCatalog(className); newKey.ClassInfo = new DCatalog(oldValue.CId, oldValue.FieldNames, newTopNodeSId); if (m_tree.UpdateData(newKey) == false) { throw new OOD.Exception.ProgramLogicError( this, "Update operation failed for class info b-tree."); } return(true); } else { return(false); } }
public int CompareTo(IKey B) { KCatalog kb = (KCatalog)B; return(string.Compare(this.m_className, kb.m_className, false, System.Globalization.CultureInfo.InvariantCulture)); }
public IKey Deserialize(byte[] bytes, int offset, int count) { int pos = offset; KCatalog result = new KCatalog(); short len = OOD.Utility.Bytes.Unpack2(bytes, pos); pos += 2; result.m_className = System.Text.ASCIIEncoding.ASCII.GetString(bytes, pos, len); pos += len; if (count > len + 2) { DCatalog catFactory = new DCatalog(); result.m_info = (DCatalog)catFactory.Deserialize(bytes, pos, count - len - 2); } return result; }
public bool UpdateTopNodeSId(string className, uint newTopNodeSId) { ClassEntry oldValue = Search(className); if (oldValue != null) { //update cache ((ClassEntry)m_cid_cache[oldValue.CId]).SetTopNodeSId(newTopNodeSId); //update the b-tree file KCatalog newKey = new KCatalog(className); newKey.ClassInfo = new DCatalog(oldValue.CId, oldValue.FieldNames, newTopNodeSId); if (m_tree.UpdateData(newKey) == false) throw new OOD.Exception.ProgramLogicError( this, "Update operation failed for class info b-tree."); return true; } else return false; }