Implements the Neo4j HTTP transaction for multiple HTTP requests
Inheritance: INeo4jTransaction
コード例 #1
0
        private void Enlist(Transaction transaction)
        {
            if (transaction == null)
            {
                // no enlistment as we are not in a TransactionScope
                return;
            }

            // try to enlist as a PSPE
            if (!transaction.EnlistPromotableSinglePhase(this))
            {
                // our enlistmente fail so we need to enlist ourselves as durable.

                // we create a transaction directly instead of using BeginTransaction that GraphClient
                // doesn't store it in its stack of scopes.
                var localTransaction = new Neo4jTransaction(_client);
                localTransaction.ForceKeepAlive();
                _transactionId = localTransaction.Id;
                var resourceManager  = GetResourceManager();
                var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
                var transactionExecutionEnvironment = new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
                {
                    TransactionId           = localTransaction.Id,
                    TransactionBaseEndpoint = _client.TransactionEndpoint
                };
                resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
                localTransaction.Cancel();
            }

            _enlistedInTransactions.Add(transaction);
        }
コード例 #2
0
        public byte[] Promote()
        {
            // we have been promoted to MSTDC, so we have to clean the local resources
            if (_transaction == null)
            {
                _transaction = new Neo4jTransaction(_client);
            }

            // do a keep alive in case the promotion takes too long or in case we don't have an ID
            _transaction.ForceKeepAlive();
            _transactionId = _transaction.Id;
            _transaction.Cancel();
            _transaction = null;

            if (_transactionId == 0)
            {
                throw new InvalidOperationException("For some reason we don't have a TransactionContext ID");
            }

            var resourceManager = GetResourceManager();

            return(resourceManager.Promote(new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
            {
                TransactionId = _transactionId,
                TransactionBaseEndpoint = _client.TransactionEndpoint
            }));
        }
コード例 #3
0
        public byte[] Promote()
        {
            // we have been promoted to MSTDC, so we have to clean the local resources
            if (_transaction == null)
            {
                _transaction = new Neo4jTransaction(_client);
            }

            // do a keep alive in case the promotion takes too long or in case we don't have an ID
            _transaction.ForceKeepAlive();
            _transactionId = _transaction.Id;
            _transaction.Cancel();
            _transaction = null;

            if (_transactionId == 0)
            {
                throw new InvalidOperationException("For some reason we don't have a TransactionContext ID");
            }

            var resourceManager = GetResourceManager();
            return resourceManager.Promote(new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
            {
                TransactionId = _transactionId,
                TransactionBaseEndpoint = _client.TransactionEndpoint
            });
        }
コード例 #4
0
        private void Enlist(Transaction transaction)
        {
            if (transaction == null)
            {
                // no enlistment as we are not in a TransactionScope
                return;
            }

            // try to enlist as a PSPE
            if (!transaction.EnlistPromotableSinglePhase(this))
            {
                // our enlistmente fail so we need to enlist ourselves as durable.

                // we create a transaction directly instead of using BeginTransaction that GraphClient
                // doesn't store it in its stack of scopes.
                 var localTransaction = new Neo4jTransaction(_client);
                localTransaction.ForceKeepAlive();
                _transactionId = localTransaction.Id;
                var resourceManager = GetResourceManager();
                var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
                var transactionExecutionEnvironment = new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
                {
                    TransactionId =  localTransaction.Id,
                    TransactionBaseEndpoint = _client.TransactionEndpoint
                };
                resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
                localTransaction.Cancel();
            }

            _enlistedInTransactions.Add(transaction);
        }
コード例 #5
0
 public void Initialize()
 {
     // enlistment has completed successfully.
     // For now we can use local transactions
     // we create it directly instead of using BeginTransaction that GraphClient
     // doesn't store it in its stack of scopes.
     _transaction = new Neo4jTransaction(_client);
 }
コード例 #6
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     try
     {
         Neo4jTransaction.DoCommit(_transactionExecutionEnvironment);
         singlePhaseEnlistment.Committed();
     }
     finally
     {
         singlePhaseEnlistment.Aborted();
     }
 }
コード例 #7
0
 public void Rollback(Enlistment enlistment)
 {
     try
     {
         Neo4jTransaction.DoRollback(_transactionExecutionEnvironment);
     }
     finally
     {
         // always have to call Done() or we clog the resources
         enlistment.Done();
     }
 }
コード例 #8
0
        public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
        {
            // we receive a commit message
            // if we own a local transaction, then commit that transaction
            if (_transaction != null)
            {
                _transaction.Rollback();
                _transaction = null;
            }
            else if (_transactionId > 0)
            {
                GetResourceManager().RollbackTransaction(_transactionId);
            }
            singlePhaseEnlistment.Aborted();

            _enlistedInTransactions.Remove(Transaction.Current);
        }
コード例 #9
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     Neo4jTransaction.DoKeepAlive(_transactionExecutionEnvironment);
     preparingEnlistment.Done();
 }
コード例 #10
0
 public void ShouldNotBeAbleToRollbackAfterCommit()
 {
     var transaction = new Neo4jTransaction(new GraphClient(new Uri("http://foo/db/data")));
     transaction.Commit();
     transaction.Rollback();
 }
コード例 #11
0
 public void ShouldNotBeAbleToCommitTwice()
 {
     var transaction = new Neo4jTransaction(new GraphClient(new Uri("http://foo/db/data")));
     transaction.Commit();
     transaction.Commit();
 }
コード例 #12
0
 public void Initialize()
 {
     // enlistment has completed successfully.
     // For now we can use local transactions
     // we create it directly instead of using BeginTransaction that GraphClient
     // doesn't store it in its stack of scopes.
     _transaction = new Neo4jTransaction(_client);
 }
コード例 #13
0
        public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
        {
            // we receive a commit message
            // if we own a local transaction, then commit that transaction
            if (_transaction != null)
            {
                _transaction.Rollback();
                _transaction = null;
            }
            else if (_transactionId > 0)
            {
                GetResourceManager().RollbackTransaction(_transactionId);
            }
            singlePhaseEnlistment.Aborted();

            _enlistedInTransactions.Remove(Transaction.Current);
        }
コード例 #14
0
 public void ShouldNotBeAbleToRollbackTwice()
 {
     var transaction = new Neo4jTransaction(new GraphClient(new Uri("http://foo/db/data")));
     transaction.Rollback();
     Assert.That(() => transaction.Rollback(), Throws.TypeOf<ClosedTransactionException>());
 }