Esempio n. 1
0
        public void Usage()
        {
            ObjectContainer db4oContainer = (ObjectContainer)Container["db4o.container"];

            Assert.IsNotNull(db4oContainer);

            Guid id = Guid.NewGuid();

            try
            {
                db4oContainer.Set(new Beer(id));
            }
            catch
            {
                db4oContainer.Rollback();
            }
            finally
            {
                db4oContainer.Commit();
            }

            ObjectSet results = db4oContainer.Get(typeof(Beer));

            Assert.AreEqual(1, results.Size());
            Beer loaded = (Beer)results.Next();

            Assert.AreEqual(id, loaded.Id);

            db4oContainer.Delete(loaded);
            db4oContainer.Commit();

            results = db4oContainer.Get(typeof(Beer));
            Assert.AreEqual(0, results.Size());
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
0
        public void Commit()
        {
            _objectContainer.Commit();

            System.Diagnostics.Debug.WriteLine("[castle][db4o facility] Resource Adapter Commit");
        }