public void UnloadVirtualEndPoint_Collection_ChangedInParent_ButNotInSubTx() { var order = DomainObjectIDs.Order1.GetObject <Order> (); var orderItems = order.OrderItems; orderItems.EnsureDataComplete(); Assert.That(orderItems.Count, Is.EqualTo(2)); orderItems.Add(OrderItem.NewObject()); Assert.That(orderItems.Count, Is.EqualTo(3)); _subTransaction.Commit(); Assert.That(order.State, Is.EqualTo(StateType.Unchanged)); Assert.That(order.TransactionContext[_subTransaction.ParentTransaction].State, Is.EqualTo(StateType.Changed)); try { UnloadService.UnloadVirtualEndPoint(_subTransaction, orderItems.AssociatedEndPointID); Assert.Fail("Expected InvalidOperationException"); } catch (InvalidOperationException ex) { Assert.That(ex.Message, Is.EqualTo( "The end point with ID " + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems' " + "has been changed. Changed end points cannot be unloaded.")); } CheckVirtualEndPoint(_subTransaction, order, "OrderItems", true); CheckVirtualEndPoint(_subTransaction.ParentTransaction, order, "OrderItems", true); Assert.That(orderItems.Count, Is.EqualTo(3)); }
public void CommitAndRollbackOnScope() { ClientTransaction transaction = ClientTransaction.CreateRootTransaction(); var eventCounter = new TransactionEventCounter(transaction); using (ClientTransactionScope scope = transaction.EnterNonDiscardingScope()) { Assert.That(eventCounter.Commits, Is.EqualTo(0)); Assert.That(eventCounter.Rollbacks, Is.EqualTo(0)); scope.Commit(); Assert.That(eventCounter.Commits, Is.EqualTo(1)); Assert.That(eventCounter.Rollbacks, Is.EqualTo(0)); scope.Rollback(); Assert.That(eventCounter.Commits, Is.EqualTo(1)); Assert.That(eventCounter.Rollbacks, Is.EqualTo(1)); transaction.Commit(); Assert.That(eventCounter.Commits, Is.EqualTo(2)); Assert.That(eventCounter.Rollbacks, Is.EqualTo(1)); transaction.Rollback(); Assert.That(eventCounter.Commits, Is.EqualTo(2)); Assert.That(eventCounter.Rollbacks, Is.EqualTo(2)); } }
public void TransactionMethodsCanBeOverridden() { using (MixinConfiguration.BuildFromActive().ForClass(typeof(ClientTransaction)).Clear().AddMixins(typeof(InvertingClientTransactionMixin)).EnterScope()) { ClientTransaction invertedTransaction = ClientTransaction.CreateRootTransaction(); bool committed = false; bool rolledBack = false; invertedTransaction.Committed += delegate { committed = true; }; invertedTransaction.RolledBack += delegate { rolledBack = true; }; Assert.That(rolledBack, Is.False); Assert.That(committed, Is.False); invertedTransaction.Commit(); Assert.That(rolledBack, Is.True); Assert.That(committed, Is.False); rolledBack = false; invertedTransaction.Rollback(); Assert.That(rolledBack, Is.False); Assert.That(committed, Is.True); } }
private void buttonAdd_Click(object sender, EventArgs e) { // Add a new Order in a child transaction scope. // Rolling back the child transaction will not roll back the parent transaction. using (var tran2 = new ClientTransaction(_transaction)) { var order = new Order(); using (tran2.Scope()) { _cache.ObjectContext.AddObject("Orders", order); } var window = new OrderForm(order, tran2); if (window.ShowDialog() == DialogResult.OK) { // Add the order to the Customer.Orders in the child transaction scope and commit the transaction. using (tran2.Scope()) { Customer.Orders.Add(order); tran2.Commit(); } } } // The child transaction will be rolled back automatically if it is not committed. }
public int Run() { try { ServiceLocator.SetLocatorProvider(() => null); var assemblyLoader = new FilteringAssemblyLoader(ApplicationAssemblyLoaderFilter.Instance); var rootAssemblyFinder = new FixedRootAssemblyFinder(new RootAssembly(typeof(BaseSecurityManagerObject).Assembly, true)); var assemblyFinder = new CachingAssemblyFinderDecorator(new AssemblyFinder(rootAssemblyFinder, assemblyLoader)); ITypeDiscoveryService typeDiscoveryService = new AssemblyFinderTypeDiscoveryService(assemblyFinder); MappingConfiguration.SetCurrent( new MappingConfiguration( new MappingReflector( typeDiscoveryService, new ClassIDProvider(), new ReflectionBasedMemberInformationNameResolver(), new PropertyMetadataReflector(), new DomainModelConstraintProvider(), MappingReflector.CreateDomainObjectCreator()), new PersistenceModelLoader(new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage)))); ClientTransaction transaction = ClientTransaction.CreateRootTransaction(); if (_arguments.ImportMetadata) { ImportMetadata(transaction); } transaction.Commit(); if (_arguments.ImportLocalization) { ImportLocalization(transaction); } transaction.Commit(); return(0); } catch (Exception e) { HandleException(e); return(1); } }
public void GetObjects_Invalid_Throws() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ().Delete(); subTransaction.Commit(); LifetimeService.GetObjects <ClassWithAllDataTypes> (subTransaction, DomainObjectIDs.ClassWithAllDataTypes1); } }
private void SetInt32Property(int value, ClientTransaction clientTransaction) { using (clientTransaction.EnterDiscardingScope()) { SampleObject objectWithAllDataTypes = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <SampleObject> (); objectWithAllDataTypes.Int32Property = value; clientTransaction.Commit(); } }
public void DomainObjects_CreatedInSubTransaction_CommitMakesValidInParent() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var instance = ClassWithAllDataTypes.NewObject(); Assert.That(instance.TransactionContext[subTransaction].State, Is.EqualTo(StateType.New)); Assert.That(instance.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.Invalid)); subTransaction.Commit(); Assert.That(instance.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.New)); } }
public void SubTransactionCanContinueToBeUsedAfterCommit() { _subTransaction.Commit(); Assert.That(_subTransaction.IsDiscarded, Is.False); using (_subTransaction.EnterDiscardingScope()) { Order order = Order.NewObject(); Assert.That(order, Is.Not.Null); } }
private void addOrder(object sender, RoutedEventArgs e) { // Add a new Order in a child transaction scope. // Rolling back the child transaction will not roll back the parent transaction. using (var tran2 = new ClientTransaction(_transaction)) // Create a child transaction. { var order = new Order(); var window = new OrderWindow(order, tran2); if (window.ShowDialog() == true) { // Add the order in the child transaction scope and commit the transaction. using (tran2.Scope()) { Customer.Orders.Add(order); tran2.Commit(); } } } // The child transaction will be rolled back automatically if it is not committed. }
private void editOrder(object sender, RoutedEventArgs e) { // Edit the currently selected order in a child transaction. var order = ordersGrid.SelectedItem as OrderInfo; if (order == null) { return; } // Create a child transaciton and edit the order in the child transaction scope. using (var tran2 = new ClientTransaction(_transaction)) { var window = new OrderWindow(order.GetOrder(), tran2); if (window.ShowDialog() == true) { tran2.Commit(); } } // The child transaction will be rolled back automatically if it is not committed. }
private void buttonEdit_Click(object sender, EventArgs e) { var row = BindingContext[_ordersView].Current as C1.LiveLinq.LiveViews.ViewRow; if (row == null) { return; } var order = ((OrderInfo)row.Value).GetOrder(); // Edit the order in a child transaction scope. // Rolling back the child transaction will not roll back the parent transaction. using (var tran2 = new ClientTransaction(_transaction)) { var window = new OrderForm(order, tran2); if (window.ShowDialog() == DialogResult.OK) { tran2.Commit(); } } // The child transaction will be rolled back automatically if it is not committed. }
private void close_Click(object sender, RoutedEventArgs e) { if (_transaction.HasChanges) { // Ask the user whether they will save or cancel the changes made by this control. switch (MessageBox.Show("Do you want to save changes?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)) { case MessageBoxResult.Yes: _transaction.Commit(); break; case MessageBoxResult.No: _transaction.Rollback(); break; case MessageBoxResult.Cancel: return; } } // Raise the CloseRequested event, so MainWindow removes the tab page with this control. CloseRequested(this, EventArgs.Empty); }
public void CommitIndependentTransactions() { ClientTransaction clientTransaction1 = ClientTransaction.CreateRootTransaction(); ClientTransaction clientTransaction2 = ClientTransaction.CreateRootTransaction(); Order order1; using (clientTransaction1.EnterNonDiscardingScope()) { order1 = DomainObjectIDs.Order1.GetObject <Order> (); order1.OrderNumber = 50; } Order order3; using (clientTransaction2.EnterNonDiscardingScope()) { order3 = DomainObjectIDs.Order3.GetObject <Order> (); order3.OrderNumber = 60; } clientTransaction1.Commit(); clientTransaction2.Commit(); ClientTransaction clientTransaction3 = ClientTransaction.CreateRootTransaction(); using (clientTransaction3.EnterNonDiscardingScope()) { Order changedOrder1 = DomainObjectIDs.Order1.GetObject <Order> (); Order changedOrder2 = DomainObjectIDs.Order3.GetObject <Order> (); Assert.That(ReferenceEquals(order1, changedOrder1), Is.False); Assert.That(ReferenceEquals(order3, changedOrder2), Is.False); Assert.That(changedOrder1.OrderNumber, Is.EqualTo(50)); Assert.That(changedOrder2.OrderNumber, Is.EqualTo(60)); } }
/// <summary> Commits the transaction. </summary> public virtual void Commit() { _wrappedInstance.Commit(); }