/// <summary>
        /// Creates a transaction Committer with the Business Object added.
        /// </summary>
        /// <returns>Returns the transaction object</returns>
        protected virtual ITransactionCommitter CreateSaveTransaction()
        {
            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(_bo);
            return(committer);
        }
Exemple #2
0
        /// <summary>
        /// Interface to add the number generator to a transaction via the transaction committer.
        /// </summary>
        /// <param name="transactionCommitter"></param>
        public void AddToTransaction(ITransactionCommitter transactionCommitter)
        {
            BusinessObject busObject = GetTransactionalBO();

            busObject.UpdateObjectBeforePersisting(transactionCommitter);
            transactionCommitter.AddBusinessObject(busObject);
        }
Exemple #3
0
        public void Test_SavingToMultipleSources()
        {
            //---------------Set up test pack-------------------
            DataStoreInMemory dataStore1 = new DataStoreInMemory();
            DataStoreInMemory dataStore2 = new DataStoreInMemory();

            DataAccessorInMemory dataAccessorInMemory1 = new DataAccessorInMemory(dataStore1);
            DataAccessorInMemory dataAccessorInMemory2 = new DataAccessorInMemory(dataStore2);

            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());

            dataAccessor.AddDataAccessor(typeof(MyBO), dataAccessorInMemory1);
            dataAccessor.AddDataAccessor(typeof(MyRelatedBo), dataAccessorInMemory2);
            MyBO.LoadDefaultClassDef();
            MyRelatedBo.LoadClassDef();
            var bo1 = new MyBO();
            var bo2 = new MyRelatedBo();
            //---------------Execute Test ----------------------
            ITransactionCommitter committer1 = dataAccessor.CreateTransactionCommitter();

            committer1.AddBusinessObject(bo1);
            committer1.CommitTransaction();

            ITransactionCommitter committer2 = dataAccessor.CreateTransactionCommitter();

            committer2.AddBusinessObject(bo2);
            committer2.CommitTransaction();

            //---------------Test Result -----------------------
            Assert.IsNotNull(dataStore1.Find <MyBO>(bo1.ID));
            Assert.IsNotNull(dataStore2.Find <MyRelatedBo>(bo2.ID));
            //---------------Tear down -------------------------
        }
Exemple #4
0
        /// <summary>
        /// Commits to the database all the business objects that are either
        /// new or have been altered since the last committal
        /// </summary>
        public override void SaveAll()
        {
            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            foreach (TBusinessObject bo in _removedBusinessObjects)
            {
                committer.AddBusinessObject(bo);
            }
            SaveAllInTransaction(committer);
            _removedBusinessObjects.Clear();
        }
        public void TestCompareThroughRelationship()
        {
            //---------------Set up test pack-------------------
            Car car1 = new Car();

            car1.CarRegNo = "5";
            Car car2 = new Car();

            car2.CarRegNo = "2";

            Engine engine1 = new Engine();

            engine1.CarID    = car1.CarID;
            engine1.EngineNo = "20";

            Engine engine2 = new Engine();

            engine2.CarID    = car2.CarID;
            engine2.EngineNo = "50";

            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(car1);
            committer.AddBusinessObject(car2);
            committer.AddBusinessObject(engine1);
            committer.AddBusinessObject(engine2);
            committer.CommitTransaction();

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            PropertyComparer <Engine, string> comparer = new PropertyComparer <Engine, string>("CarRegNo");

            comparer.Source = new Source("Car");
            int comparisonResult = comparer.Compare(engine1, engine2);

            //---------------Test Result -----------------------
            Assert.Greater(comparisonResult, 0, "engine1 should be greater as its car's regno is greater");
            //---------------Tear Down -------------------------
        }
Exemple #6
0
        public void TestField_Compare_ThroughRelationship()
        {
            //---------------Set up test pack-------------------
            Car car1 = new Car();

            car1.CarRegNo = "5";
            Car car2 = new Car();

            car2.CarRegNo = "2";

            Engine engine1 = new Engine();

            engine1.CarID    = car1.CarID;
            engine1.EngineNo = "20";

            Engine engine2 = new Engine();

            engine2.CarID    = car2.CarID;
            engine2.EngineNo = "50";

            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(car1);
            committer.AddBusinessObject(car2);
            committer.AddBusinessObject(engine1);
            committer.AddBusinessObject(engine2);
            committer.CommitTransaction();

            OrderCriteriaField orderCriteriaField = OrderCriteriaField.FromString("Engine.Car.CarRegNo");

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            int comparisonResult = orderCriteriaField.Compare(engine1, engine2);

            //---------------Test Result -----------------------
            Assert.Greater(comparisonResult, 0, "engine1 should be greater as its car's regno is greater");
            //---------------Tear Down -------------------------
        }
Exemple #7
0
        public void TestCompare_ThroughRelationship()
        {
            //---------------Set up test pack-------------------
            Car car1 = new Car();

            car1.CarRegNo = "2";
            Car car2 = new Car();

            car2.CarRegNo = "2";

            Engine engine1 = new Engine();

            engine1.CarID    = car1.CarID;
            engine1.EngineNo = "20";

            Engine engine2 = new Engine();

            engine2.CarID    = car2.CarID;
            engine2.EngineNo = "50";

            ITransactionCommitter committer = BORegistry.DataAccessor.CreateTransactionCommitter();

            committer.AddBusinessObject(car1);
            committer.AddBusinessObject(car2);
            committer.AddBusinessObject(engine1);
            committer.AddBusinessObject(engine2);
            committer.CommitTransaction();

            IOrderCriteria orderCriteria = QueryBuilder.CreateOrderCriteria(engine1.ClassDef, "Car.CarRegNo, EngineNo");

            //---------------Assert PreConditions---------------
            //---------------Execute Test ----------------------
            int comparisonResult = orderCriteria.Compare(engine1, engine2);

            //---------------Test Result -----------------------
            Assert.Less(comparisonResult, 0, "engine1 should be less as the car regnos are equal and its engine no is less");
            //---------------Tear Down -------------------------
        }
 ///<summary>
 /// Add an object of type business object to the transaction.
 /// The DBTransactionCommiter wraps this Business Object in the
 /// appropriate Transactional Business Object
 ///</summary>
 ///<param name="businessObject"></param>
 public void AddBusinessObject(IBusinessObject businessObject)
 {
     if (_myDataAccessor == null)
     {
         _myDataAccessor       = GetDataAccessorForType(businessObject.GetType());
         _transactionCommitter = _myDataAccessor.CreateTransactionCommitter();
     }
     else
     {
         IDataAccessor dataAccessorToUseForType = GetDataAccessorForType(businessObject.GetType());
         if (dataAccessorToUseForType != _myDataAccessor)
         {
             throw new HabaneroDeveloperException("A problem occurred while trying to save, please see log for details", string.Format("A BusinessObject of type {0} was added to a TransactionCommitterMultiSource which has been set up with a different source to this type.", businessObject.GetType().FullName));
         }
     }
     _transactionCommitter.AddBusinessObject(businessObject);
 }
Exemple #9
0
        public void Test_UsingDefaultBusinessObjectLoader()
        {
            //---------------Set up test pack-------------------
            DataAccessorMultiSource dataAccessor = new DataAccessorMultiSource(new DataAccessorInMemory());
            ITransactionCommitter   committer    = dataAccessor.CreateTransactionCommitter();

            MyBO.LoadDefaultClassDef();
            var bo1 = new MyBO();

            committer.AddBusinessObject(bo1);
            committer.CommitTransaction();
            //---------------Execute Test ----------------------
            var loadedBo1 = dataAccessor.BusinessObjectLoader.GetBusinessObject <MyBO>(bo1.ID);

            //---------------Test Result -----------------------
            Assert.AreSame(loadedBo1, bo1);
            //---------------Tear down -------------------------
        }
 /// <summary>
 /// Steps to carry out before the Save() command is run. You can add objects to the current
 /// transaction using this method, such as a database number generator.  No validity checks are
 /// made to the BusinessObject after this step, so be careful not to invalidate the object.
 /// </summary>
 /// <param name="transactionCommitter">The current transaction committer - any objects added to this will
 /// be committed in the same transaction as this one.</param>
 protected internal override void UpdateObjectBeforePersisting(ITransactionCommitter transactionCommitter)
 {
     transactionCommitter.AddBusinessObject(new FakeBOWithUpdateBeforePersisting());
 }
		/// <summary>
		/// Adds the sequence number change to the persistence transaction
		/// </summary>
		/// <param name="transactionCommitter">The transaction committer suitable
		/// for the persistence environment</param>
		public void AddToTransaction(ITransactionCommitter transactionCommitter)
		{
			var busObject = this.GetBOSequenceNumberLocking();
			transactionCommitter.AddBusinessObject(busObject);
		}
 /// <summary>
 /// Steps to carry out before the Save() command is run. You can add objects to the current
 /// transaction using this method, such as a database number generator.  No validity checks are 
 /// made to the BusinessObject after this step, so be careful not to invalidate the object.
 /// </summary>
 /// <param name="transactionCommitter">The current transaction committer - any objects added to this will
 /// be committed in the same transaction as this one.</param>
 protected internal override void UpdateObjectBeforePersisting(ITransactionCommitter transactionCommitter)
 {
     transactionCommitter.AddBusinessObject(new FakeBOWithUpdateBeforePersisting());
 }
 /// <summary>
 /// Interface to add the number generator to a transaction via the transaction committer.
 /// </summary>
 /// <param name="transactionCommitter"></param>
 public void AddToTransaction(ITransactionCommitter transactionCommitter)
 {
     BusinessObject busObject = GetTransactionalBO();
     busObject.UpdateObjectBeforePersisting(transactionCommitter);
     transactionCommitter.AddBusinessObject(busObject);
 }
Exemple #14
0
        /// <summary>
        /// Adds the sequence number change to the persistence transaction
        /// </summary>
        /// <param name="transactionCommitter">The transaction committer suitable
        /// for the persistence environment</param>
        public void AddToTransaction(ITransactionCommitter transactionCommitter)
        {
            var busObject = this.GetBOSequenceNumberLocking();

            transactionCommitter.AddBusinessObject(busObject);
        }