예제 #1
0
        public override void Commit(bool forceCommit)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Committing the data store (or adding to batch for later)."))
            {
                // Only commit if there's no batch running
                if (forceCommit || !BatchState.IsRunning)
                {
                    LogWriter.Debug("No batch running. Committing immediately.");

                    if (ObjectContainer != null)
                    {
                        if (!ObjectContainer.Ext().IsClosed())
                        {
                            LogWriter.Debug("Committing.");

                            ObjectContainer.Commit();
                            RaiseCommitted();
                        }
                        else
                        {
                            LogWriter.Debug("Can't commit. The data store is closed.");
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("ObjectContainer == null");
                    }
                }
                // If a batch is running then the commit should be skipped. It'll be commit once the batch is complete.
                else
                {
                    LogWriter.Debug("Batch running. Adding data source to batch. It will be committed when the batch is over.");

                    BatchState.Handle(this);
                }
            }
        }