示例#1
0
        /// <summary>
        /// It's fast and not a thread-safety version of ReplaceRows method.
        /// TODO: remove it after sqlite thread-safety refactoring.
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public Int64 ReplaceRowsTrans(IEnumerable <ITableRow> rows)
        {
            Int64 result = 0L;

            using (OpenCloseConnectionWrapper wrapper = this.Connection.OpenWrapper())
            {
                using (SQLiteTransaction transaction = wrapper.Connection.BeginTransaction())
                {
                    ReplaceCommand replaceCommand = new ReplaceCommand(
                        wrapper.Connection,
                        this.TableDefinition,
                        transaction
                        );

                    foreach (ITableRow row in rows)
                    {
                        replaceCommand.AddRowForReplacing(row);
                    }

                    result = replaceCommand.Execute(100);

                    transaction.Commit();
                }
            }

            return(result);
        }
示例#2
0
        public override void Run(string[] args)
        {
            options = new CmdParserOptionSet()
            {
                { "h|help", "Display this help information. To see online help, use: git help <command>", v => OfflineHelp() },
                { "f", "If an existing replace ref for the same object exists, it will be overwritten (instead of failing)", v => cmd.F = true },
                { "d", "Delete existing replace refs for the given objects", v => cmd.D = true },
                { "l=", "List replace refs for objects that match the given pattern (or all if no pattern is given)", v => cmd.L = v },
            };

            try
            {
                List <String> arguments = ParseOptions(args);
                if (arguments.Count > 0)
                {
                    cmd.Arguments = arguments;
                    cmd.Execute();
                }
                else
                {
                    OfflineHelp();
                }
            }
            catch (Exception e)
            {
                cmd.OutputStream.WriteLine(e.Message);
            }
        }
        public void When_deleting_item_in_cache_with_time_will_block_replace_operations()
        {
            Cache["foo2"] = new CachedItem();

            var stream  = new MemoryStream();
            var command = new DeleteCommand();

            command.SetContext(stream);
            command.Init("foo2", "500");

            command.FinishedExecuting += () => wait.Set();
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("DELETED\r\n", ReadAll(stream));

            wait.Reset();

            var buffer = new byte[] { 1, 2, 3, 4 };

            stream = GetStreamWithData(buffer);
            var replaceCommand = new ReplaceCommand();

            replaceCommand.SetContext(stream);
            replaceCommand.Init("foo2", "1", "6000", "4");

            replaceCommand.FinishedExecuting += () => wait.Set();
            replaceCommand.Execute();
            wait.WaitOne();

            Assert.AreEqual("NOT_STORED\r\n", ReadAll(6, stream));
        }
示例#4
0
        public void WhenOldValuePresent_ThenReplaceWithNewValue()
        {
            var sut = new ReplaceCommand("John", "Peter").SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo("Peter Smith Peter Smith"));
        }
示例#5
0
        public void WhenOldValueValueNotPresent_ThenSetSame()
        {
            var sut = new ReplaceCommand("Jill", "Peter").SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(Value));
        }
示例#6
0
        public void WhenNewValueIsNullOrEmpty_ThenReplaceWithEmpty(string newValue)
        {
            var sut = new ReplaceCommand("John", newValue).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(" Smith  Smith"));
        }
示例#7
0
        public void WhenOldValueIsNullOrEmpty_ThenSetSame(string oldValue)
        {
            var sut = new ReplaceCommand(oldValue, "Peter").SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(Value));
        }
 public void Transform()
 {
     InitNextTransform();
     var replaceIndex = _random.Next(_commands.Count);
     var replacedICommand = GetReplacedVersionOf(replaceIndex);
     var replaceCommand = new ReplaceCommand(_commands, replacedICommand, replaceIndex);
     _replaced = replaceCommand;
     replaceCommand.Execute();
 }
示例#9
0
        public void Transform()
        {
            InitNextTransform();
            var replaceIndex     = _random.Next(_commands.Count);
            var replacedICommand = GetReplacedVersionOf(replaceIndex);
            var replaceCommand   = new ReplaceCommand(_commands, replacedICommand, replaceIndex);

            _replaced = replaceCommand;
            replaceCommand.Execute();
        }
示例#10
0
        public void When_replacing_item_not_on_cache_will_reply_that_it_was_not_stored()
        {
            var          buffer  = new byte[] { 1, 2, 3, 4 };
            MemoryStream stream  = GetStreamWithData(buffer);
            var          command = new ReplaceCommand();

            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("NOT_STORED\r\n", ReadAll(6, stream));
        }
示例#11
0
        /// <summary>
        /// Replace rows
        /// </summary>
        /// <param name="rows">Rows to be replaces</param>
        public Int64 ReplaceRows(IEnumerable <ITableRow> rows)
        {
            Int64 result = 0L;

            using (this.Connection.OpenWrapper())
            {
                ReplaceCommand replaceCommand = new ReplaceCommand(
                    this.Connection,
                    this.TableDefinition
                    );

                foreach (ITableRow row in rows)
                {
                    replaceCommand.AddRowForReplacing(row);
                }

                result = replaceCommand.Execute(100);
            }

            return(result);
        }