Ejemplo n.º 1
0
        /// <summary>
        /// Add a new collection. Check if name the not exists. Create only in transaction page - will update header only in commit
        /// </summary>
        private void Add(string name, ref CollectionPage collectionPage)
        {
            if (Encoding.UTF8.GetByteCount(name) > _header.GetAvaiableCollectionSpace())
            {
                throw LiteException.InvalidCollectionName(name, "There is no space in header for more collections");
            }
            if (!name.IsWord())
            {
                throw LiteException.InvalidCollectionName(name, "Use only [a-Z$_]");
            }
            if (name.StartsWith("$"))
            {
                throw LiteException.InvalidCollectionName(name, "Collection can't starts with `$` (reserved for system collections)");
            }

            // create new collection page
            collectionPage = _snapshot.NewPage <CollectionPage>();
            var pageID = collectionPage.PageID;

            // insert collection name/pageID in header only in commit operation
            _transPages.Commit += (h) => h.InsertCollection(name, pageID);

            // create first index (_id pk) (must pass collectionPage because snapshot contains null in CollectionPage prop)
            var indexer = new IndexService(_snapshot);

            indexer.CreateIndex("_id", "$._id", true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Check collection name if is valid (and fit on header)
 /// Throw correct message error if not valid name or not fit on header page
 /// </summary>
 public static void CheckName(string name, HeaderPage header)
 {
     if (Encoding.UTF8.GetByteCount(name) > header.GetAvaiableCollectionSpace())
     {
         throw LiteException.InvalidCollectionName(name, "There is no space in header this collection name");
     }
     if (!name.IsWord())
     {
         throw LiteException.InvalidCollectionName(name, "Use only [a-Z$_]");
     }
     if (name.StartsWith("$"))
     {
         throw LiteException.InvalidCollectionName(name, "Collection can't starts with `$` (reserved for system collections)");
     }
 }