Example #1
0
        /// <summary>
        /// Delete existing index
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public void DeleteIndex(string name)
        {
            if (IndexSpace != null)
            {
                IndexSpace.DeleteIndex(DEFS.PrepareFullIndexName(this.Name, name));
            }
            else
            {
                VSIndex x = this.get_index(name);
                if (x == null)
                {
                    throw new VSException(DEFS.E0052_DELETE_INDEX_ERROR_CODE, "- index is not found - '" + name + "'");
                }

                // Remove all references
                VSIndex ref_x = get_index(DEFS.PrepareFullIndexName(DEFS.ParseIndexSpace(name), DEFS.INDEX_CROSS_REFERENCES));
                x.Reset();
                while (x.Next())
                {
                    long[] refs = x.CurrentRefs;
                    for (int i = 0; i < refs.Length; i++)
                    {
                        byte[] key = VSLib.ConvertLongToByte(refs[i]);
                        ref_x.delete_node(key, x.CurrentAvlNode.ID);
                    }
                }

                index_list.Remove(x);
                index_list_full.Remove(x);
                x.purge();
            }
        }
Example #2
0
        /// <summary>
        /// Create index
        /// </summary>
        /// <param name="name"></param>
        public VSIndex CreateIndex(string name, bool unique)
        {
            string nm = name.Trim().ToLower();

            if (nm.IndexOf(DEFS.INDEX_CROSS_REFERENCES) >= 0)
            {
                throw new VSException(DEFS.E0050_CREATE_INDEX_ERROR_CODE, "- invalid index name: '" + nm + "'");
            }


            if (IndexSpace != null)
            {
                return(IndexSpace.CreateIndex(DEFS.PrepareFullIndexName(this.Name, name), unique));
            }
            else
            {
                if (index_exists(nm))
                {
                    throw new VSException(DEFS.E0050_CREATE_INDEX_ERROR_CODE, "- index already exists: '" + nm + "'");
                }

                VSIndex ix = new VSIndex(this, nm, unique);

                index_list.Add(ix);

                index_list_full.Add(ix);

                set_ref_index(ix);

                return(ix);
            }
        }
Example #3
0
        /// <summary>
        /// Remove all related indexes for object by ID
        /// ONLY for objects and indexes located in THIS space
        /// </summary>
        /// <param name="a"></param>
        private void remove_all_indexes(string space_name, long id)
        {
            VSIndex ref_index = this.get_index(DEFS.PrepareFullIndexName(space_name, DEFS.INDEX_CROSS_REFERENCES));

            if (ref_index != null)
            {
                byte[] key = VSLib.ConvertLongToByteReverse(id);

                long[] ref_nodes = ref_index.FindAll(key, false);         // Get all avl node ids for obj id

                ref_index.delete_node(key, -1);                           // Remove reference record

                for (int i = 0; i < ref_nodes.Length; i++)
                {
                    this.get_index(this.GetAllocation(ref_nodes[i]).ReadLong(VSAvlNode.INDEX_POS)).delete_avl_node(ref_nodes[i], id);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Add/Create reference
        /// </summary>
        /// <param name="index"></param>
        private void set_ref_index(VSIndex index)
        {
            string[] parsed_name = new string [2];
            parsed_name[0] = DEFS.ParseIndexSpace(index.Name);
            parsed_name[1] = DEFS.ParseIndexName(index.Name);

            string ref_name = DEFS.PrepareFullIndexName(parsed_name[0], DEFS.INDEX_CROSS_REFERENCES);

            if (this.index_exists(ref_name))
            {
                index.XRefs = this.get_index(ref_name);
            }
            else
            {
                VSIndex ref_index = new VSIndex(this, ref_name, false);
                index.XRefs = ref_index;
                index_list_full.Add(ref_index);
            }
        }
Example #5
0
        ////////////////////////////////////////////////////////////////////////////
        //////////////////////  COMMON METHODS   ///////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Attach new address space. Return 0 - successful; -1 - error
        /// </summary>
        /// <param name="_path"></param>
        /// <param name="_cat_file"></param>
        /// <param name="idx"></param>
        /// <returns></returns>
        internal string Attach(VSCatalogDescriptor desc, VSVirtualMemoryManager vmm, VSTransaction ta, bool imo)
        {
            DESCRIPTOR = desc;
            vm         = vmm;
            vs_imo     = imo;

            // Check if restore is not completed
            long l = vm.ReadLong(DEFS.SYSTEM_STATUS_ADDRESS);

            if (l != 0)
            {
                return(VSException.GetMessage(DEFS.E0009_RESTORE_NOT_COMPLETED_CODE) + " Space: " + Name);
            }


            // Build index list
            index_list      = new List <VSIndex>();
            index_list_full = new List <VSIndex>();
            long addr = GetRootAddress(DEFS.POOL_INDEX);            // Get 1st ADSC addredd

            while (addr > 0)
            {
                VSIndex xd = new VSIndex(this, addr);
                index_list_full.Add(xd);
                if (xd.Name.IndexOf(DEFS.INDEX_CROSS_REFERENCES) < 0)
                {
                    index_list.Add(xd);
                }

                addr = xd.NEXT;
            }

            // Set ref indexes
            for (int i = 0; i < index_list.Count; i++)
            {
                set_ref_index(index_list[i]);
            }

            return("");
        }
Example #6
0
 public VSAvlNode(VSIndex x)
 {
     ix = x;
     sp = x.sp;
 }