/// <summary>
        /// Persists several execution contexts.
        /// </summary>
        /// <param name="serializedContexts">a dictionary associating the id of a job or step with its context execution</param>
        /// <param name="query">the query to use for persisting the execution contexts in the database</param>
        private void PersistSerializedContexts(IDictionary <long?, byte[]> serializedContexts, string query)
        {
            var parameterSourceProvider = new ExecutionContextParameterSourceProvider(serializedContexts);

            DbOperator.BatchUpdate(InsertTablePrefix(query),
                                   serializedContexts.Select(p => parameterSourceProvider.CreateParameterSource(p.Key)).ToList());
        }
예제 #2
0
        /// <summary>
        /// Writes the items in the database
        /// </summary>
        /// <param name="items">the items to write</param>
        public void Write(IList <T> items)
        {
            _logger.Debug("Executing batch database writer with {0} items.", items.Count);

            if (items.Count == 0)
            {
                _logger.Warn("Executing batch database writer : empty list of items has been given.");
                return;
            }


            var parameterSources = items.Select(i => DbParameterSourceProvider.CreateParameterSource(i)).ToList();
            var updateCounts     = _dbOperator.BatchUpdate(Query, parameterSources);

            if (AssertUpdates)
            {
                for (var i = 0; i < updateCounts.Length; i++)
                {
                    if (updateCounts[i] == 0)
                    {
                        throw new EmptyUpdateException(string.Format("Item {0} of {1} did not update any rows: [{2}]",
                                                                     i, updateCounts.Length, items[i]));
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Persists the step executions in a collection. The step executions must not have been persisted yet.
        /// </summary>
        /// <param name="stepExecutions">a collection of step executions to persists</param>
        public void SaveStepExecutions(ICollection <StepExecution> stepExecutions)
        {
            Assert.NotNull(stepExecutions, "Attempt to save a null collection of step executions");

            using (var scope = new TransactionScope(TransactionScopeOption.Required, TransactionOptions))
            {
                if (stepExecutions.Count > 0)
                {
                    var parameters = stepExecutions.Select(BuildStepExecutionParameters).ToList();
                    DbOperator.BatchUpdate(InsertTablePrefix(SaveStepExecutionQuery), parameters);
                }
                scope.Complete();
            }
        }