當前位置: 首頁>>代碼示例>>C#>>正文


C# Transaction.AddTree方法代碼示例

本文整理匯總了C#中Voron.Impl.Transaction.AddTree方法的典型用法代碼示例。如果您正苦於以下問題:C# Transaction.AddTree方法的具體用法?C# Transaction.AddTree怎麽用?C# Transaction.AddTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Voron.Impl.Transaction的用法示例。


在下文中一共展示了Transaction.AddTree方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateTree

        public unsafe Tree CreateTree(Transaction tx, string name, bool keysPrefixing = false)
        {
            if (tx.Flags == (TransactionFlags.ReadWrite) == false)
                throw new ArgumentException("Cannot create a new tree with a read only transaction");

            Tree tree = tx.ReadTree(name);
            if (tree != null)
                return tree;


	        if (name.Equals(Constants.RootTreeName, StringComparison.InvariantCultureIgnoreCase) ||
	            name.Equals(Constants.FreeSpaceTreeName, StringComparison.InvariantCultureIgnoreCase))
		        throw new InvalidOperationException("Cannot create a tree with reserved name: " + name);


            Slice key = (Slice)name;

            // we are in a write transaction, no need to handle locks
            var header = (TreeRootHeader*)tx.State.Root.DirectRead(key);
            if (header != null)
            {
                tree = Tree.Open(tx, header);
                tree.Name = name;
                tx.AddTree(name, tree);
                return tree;
            }

            tree = Tree.Create(tx, keysPrefixing);
            tree.Name = name;
            var space = tx.State.Root.DirectAdd(key, sizeof(TreeRootHeader));

            tree.State.CopyTo((TreeRootHeader*)space);
            tree.State.IsModified = true;
            tx.AddTree(name, tree);

			if(IsDebugRecording)
				DebugJournal.RecordWriteAction(DebugActionType.CreateTree, tx, Slice.Empty,name,Stream.Null);

            return tree;
        }
開發者ID:VPashkov,項目名稱:ravendb,代碼行數:40,代碼來源:StorageEnvironment.cs

示例2: CreateTree

        public unsafe Tree CreateTree(Transaction tx, string name, bool keysPrefixing = false)
        {
            Tree tree = tx.ReadTree(name);
            if (tree != null)
                return tree;

            if (name.Equals(Constants.RootTreeName, StringComparison.InvariantCultureIgnoreCase))
                return tx.Root;
            if (name.Equals(Constants.FreeSpaceTreeName, StringComparison.InvariantCultureIgnoreCase))
                return tx.FreeSpaceRoot;

            if (tx.Flags == (TransactionFlags.ReadWrite) == false)
                throw new InvalidOperationException("No such tree: " + name + " and cannot create trees in read transactions");

            Slice key = name;

            tree = Tree.Create(tx, keysPrefixing);
            tree.Name = name;
            var space = tx.Root.DirectAdd(key, sizeof(TreeRootHeader));

            tree.State.CopyTo((TreeRootHeader*)space);
            tree.State.IsModified = true;
            tx.AddTree(name, tree);

            if(IsDebugRecording)
                DebugJournal.RecordWriteAction(DebugActionType.CreateTree, tx, Slice.Empty,name,Stream.Null);

            return tree;
        }
開發者ID:j2jensen,項目名稱:ravendb,代碼行數:29,代碼來源:StorageEnvironment.cs

示例3: RenameTree

	    public unsafe void RenameTree(Transaction tx, string fromName, string toName)
	    {
			if (tx.Flags == (TransactionFlags.ReadWrite) == false)
				throw new ArgumentException("Cannot rename a new tree with a read only transaction");

			if (toName.Equals(Constants.RootTreeName, StringComparison.InvariantCultureIgnoreCase) ||
				toName.Equals(Constants.FreeSpaceTreeName, StringComparison.InvariantCultureIgnoreCase))
				throw new InvalidOperationException("Cannot create a tree with reserved name: " + toName);

		    if (tx.ReadTree(toName) != null)
			    throw new ArgumentException("Cannot rename a tree with the name of an existing tree: " + toName);

		    Tree fromTree = tx.ReadTree(fromName);
		    if (fromTree == null)
			    throw new ArgumentException("Tree " + fromName + " does not exists");

            Slice key = (Slice)toName;

	        tx.State.Root.Delete((Slice)fromName);
			var ptr = tx.State.Root.DirectAdd(key, sizeof(TreeRootHeader));
		    fromTree.State.CopyTo((TreeRootHeader*) ptr);
		    fromTree.Name = toName;
		    fromTree.State.IsModified = true;
		    
			tx.RemoveTree(fromName);
			tx.RemoveTree(toName);

			tx.AddTree(toName, fromTree);

			if (IsDebugRecording)
                DebugJournal.RecordWriteAction(DebugActionType.RenameTree, tx, (Slice)toName, fromName, Stream.Null);
	    }
開發者ID:VPashkov,項目名稱:ravendb,代碼行數:32,代碼來源:StorageEnvironment.cs

示例4: CreateTree

        public unsafe Tree CreateTree(Transaction tx, string name)
        {
            if (tx.Flags == (TransactionFlags.ReadWrite) == false)
                throw new ArgumentException("Cannot create a new tree with a read only transaction");

            Tree tree = tx.ReadTree(name);
            if (tree != null)
                return tree;

            Slice key = name;

            // we are in a write transaction, no need to handle locks
            var header = (TreeRootHeader*)tx.State.Root.DirectRead(key);
            if (header != null)
            {
                tree = Tree.Open(tx, _sliceComparer, header);
                tree.Name = name;
                tx.AddTree(name, tree);
                return tree;
            }

            tree = Tree.Create(tx, _sliceComparer);
            tree.Name = name;
            var space = tx.State.Root.DirectAdd(key, sizeof(TreeRootHeader));

            tree.State.CopyTo((TreeRootHeader*)space);
            tree.State.IsModified = true;
            tx.AddTree(name, tree);

			if(IsDebugRecording)
				DebugJournal.RecordAction(DebugActionType.CreateTree, Slice.Empty,name,Stream.Null);

            return tree;
        }
開發者ID:WimVergouwe,項目名稱:ravendb,代碼行數:34,代碼來源:StorageEnvironment.cs


注:本文中的Voron.Impl.Transaction.AddTree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。