コード例 #1
0
        public virtual KernelTransaction NewInstance(KernelTransaction.Type type, LoginContext loginContext, long timeout)
        {
            AssertCurrentThreadIsNotBlockingNewTransactions();
            SecurityContext securityContext = loginContext.Authorize(_tokenHolders.propertyKeyTokens().getOrCreateId, _currentDatabaseName);

            try
            {
                while (!_newTransactionsLock.readLock().tryLock(1, TimeUnit.SECONDS))
                {
                    AssertRunning();
                }
                try
                {
                    AssertRunning();
                    TransactionId lastCommittedTransaction = _transactionIdStore.LastCommittedTransaction;
                    KernelTransactionImplementation tx     = _localTxPool.acquire();
                    StatementLocks statementLocks          = _statementLocksFactory.newInstance();
                    tx.Initialize(lastCommittedTransaction.TransactionIdConflict(), lastCommittedTransaction.CommitTimestamp(), statementLocks, type, securityContext, timeout, _userTransactionIdCounter.incrementAndGet());
                    return(tx);
                }
                finally
                {
                    _newTransactionsLock.readLock().unlock();
                }
            }
            catch (InterruptedException ie)
            {
                Thread.interrupted();
                throw new TransactionFailureException("Fail to start new transaction.", ie);
            }
        }
コード例 #2
0
        private string[] DoExecute(ThreadingRule threading, S subject, KernelTransaction.Type txType, bool startEarly, params string[] queries)
        {
            NamedFunction <S, Exception> startTransaction = new NamedFunctionAnonymousInnerClass(this, subject, txType, startEarly, queries);

            _done = threading.Execute(startTransaction, subject);
            return(queries);
        }
コード例 #3
0
 public NamedFunctionAnonymousInnerClass(ThreadedTransaction <S> outerInstance, S subject, KernelTransaction.Type txType, bool startEarly, string[] queries) : base("threaded-transaction-" + Arrays.GetHashCode(queries))
 {
     this.outerInstance = outerInstance;
     this._subject      = subject;
     this._txType       = txType;
     this._startEarly   = startEarly;
     this._queries      = queries;
 }
コード例 #4
0
 internal TransitionalTxManagementKernelTransaction(GraphDatabaseFacade db, KernelTransaction.Type type, LoginContext loginContext, long customTransactionTimeout, ThreadToStatementContextBridge bridge)
 {
     this._db                       = db;
     this._type                     = type;
     this._loginContext             = loginContext;
     this._customTransactionTimeout = customTransactionTimeout;
     this._bridge                   = bridge;
     this._tx                       = StartTransaction();
 }
コード例 #5
0
        public Neo4jTransactionalContext(GraphDatabaseQueryService graph, ThreadToStatementContextBridge txBridge, PropertyContainerLocker locker, InternalTransaction initialTransaction, Statement initialStatement, ExecutingQuery executingQuery, Kernel kernel)
        {
            this._graph                  = graph;
            this._txBridge               = txBridge;
            this._locker                 = locker;
            this.TransactionType         = initialTransaction.TransactionType();
            this.SecurityContextConflict = initialTransaction.SecurityContext();
            this._executingQuery         = executingQuery;

            this._transaction       = initialTransaction;
            this._kernelTransaction = txBridge.GetKernelTransactionBoundToThisThread(true);
            this._statement         = initialStatement;
            this._kernel            = kernel;
        }
コード例 #6
0
        private InternalTransaction BeginTransaction(KernelTransaction.Type type, LoginContext loginContext, Duration txTimeout, IDictionary <string, object> txMetadata)
        {
            InternalTransaction tx;

            if (txTimeout == null)
            {
                tx = _db.beginTransaction(type, loginContext);
            }
            else
            {
                tx = _db.beginTransaction(type, loginContext, txTimeout.toMillis(), TimeUnit.MILLISECONDS);
            }

            if (txMetadata != null)
            {
                tx.MetaData = txMetadata;
            }
            return(tx);
        }
コード例 #7
0
ファイル: DatabaseRule.cs プロジェクト: Neo4Net/Neo4Net
 public override InternalTransaction BeginTransaction(KernelTransaction.Type type, LoginContext loginContext, long timeout, TimeUnit unit)
 {
     return(GraphDatabaseAPI.beginTransaction(type, loginContext, timeout, unit));
 }
コード例 #8
0
ファイル: DatabaseRule.cs プロジェクト: Neo4Net/Neo4Net
 public override InternalTransaction BeginTransaction(KernelTransaction.Type type, LoginContext loginContext)
 {
     return(GraphDatabaseAPI.beginTransaction(type, loginContext));
 }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("ConstantConditions") @Test public void rollsBackNewlyCreatedTransactionIfTerminationDetectedOnCloseDuringPeriodicCommit()
        public virtual void RollsBackNewlyCreatedTransactionIfTerminationDetectedOnCloseDuringPeriodicCommit()
        {
            // Given
            InternalTransaction initialTransaction = mock(typeof(InternalTransaction), new ReturnsDeepStubs());

            KernelTransaction.Type transactionType = KernelTransaction.Type.@implicit;
            SecurityContext        securityContext = SecurityContext.AUTH_DISABLED;

            when(initialTransaction.TransactionType()).thenReturn(transactionType);
            when(initialTransaction.SecurityContext()).thenReturn(securityContext);
            when(initialTransaction.TerminationReason()).thenReturn(null);

            GraphDatabaseQueryService queryService              = mock(typeof(GraphDatabaseQueryService));
            Statement                      initialStatement     = mock(typeof(Statement));
            KernelTransaction              initialKTX           = MockTransaction(initialStatement);
            QueryRegistryOperations        initialQueryRegistry = mock(typeof(QueryRegistryOperations));
            ExecutingQuery                 executingQuery       = mock(typeof(ExecutingQuery));
            PropertyContainerLocker        locker   = new PropertyContainerLocker();
            ThreadToStatementContextBridge txBridge = mock(typeof(ThreadToStatementContextBridge));

            Statement           secondStatement   = mock(typeof(Statement));
            KernelTransaction   secondKTX         = MockTransaction(secondStatement);
            InternalTransaction secondTransaction = mock(typeof(InternalTransaction));

            when(secondTransaction.TerminationReason()).thenReturn(null);
            QueryRegistryOperations secondQueryRegistry = mock(typeof(QueryRegistryOperations));

            when(executingQuery.QueryText()).thenReturn("X");
            when(executingQuery.QueryParameters()).thenReturn(EMPTY_MAP);
            Mockito.doThrow(typeof(Exception)).when(initialTransaction).close();
            when(initialStatement.QueryRegistration()).thenReturn(initialQueryRegistry);
            when(queryService.BeginTransaction(transactionType, securityContext)).thenReturn(secondTransaction);
            when(txBridge.GetKernelTransactionBoundToThisThread(true)).thenReturn(initialKTX, initialKTX, secondKTX);
            when(txBridge.Get()).thenReturn(secondStatement);
            when(secondStatement.QueryRegistration()).thenReturn(secondQueryRegistry);

            Kernel kernel = mock(typeof(Kernel));
            Neo4jTransactionalContext context = new Neo4jTransactionalContext(queryService, txBridge, locker, initialTransaction, initialStatement, executingQuery, kernel);

            // When
            try
            {
                context.CommitAndRestartTx();
                throw new AssertionError("Expected RuntimeException to be thrown");
            }
            catch (Exception)
            {
                // Then
                object[] mocks = new object[] { txBridge, initialTransaction, initialQueryRegistry, initialKTX, secondQueryRegistry, secondKTX, secondTransaction };
                InOrder  order = Mockito.inOrder(mocks);

                // (0) Constructor
                order.verify(initialTransaction).transactionType();
                order.verify(initialTransaction).securityContext();
                order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
                order.verify(initialTransaction).terminationReason();                           // not terminated check

                // (1) Collect statistics
                order.verify(initialKTX).executionStatistics();

                // (2) Unbind old
                order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
                order.verify(txBridge).unbindTransactionFromCurrentThread();

                // (3) Register and unbind new
                order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
                order.verify(secondKTX).acquireStatement();
                order.verify(secondQueryRegistry).registerExecutingQuery(executingQuery);
                order.verify(txBridge).unbindTransactionFromCurrentThread();

                // (4) Rebind, unregister, and close old
                order.verify(txBridge).bindTransactionToCurrentThread(initialKTX);
                order.verify(initialQueryRegistry).unregisterExecutingQuery(executingQuery);
                order.verify(initialTransaction).success();
                order.verify(initialTransaction).close();
                order.verify(txBridge).bindTransactionToCurrentThread(secondKTX);
                order.verify(secondTransaction).failure();
                order.verify(secondTransaction).close();
                order.verify(txBridge).unbindTransactionFromCurrentThread();

                verifyNoMoreInteractions(mocks);
            }
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("ConstantConditions") @Test public void neverStopsExecutingQueryDuringCommitAndRestartTx()
        public virtual void NeverStopsExecutingQueryDuringCommitAndRestartTx()
        {
            // Given
            KernelTransaction   initialKTX         = MockTransaction(_initialStatement);
            InternalTransaction initialTransaction = mock(typeof(InternalTransaction), new ReturnsDeepStubs());

            KernelTransaction.Type transactionType = KernelTransaction.Type.@implicit;
            SecurityContext        securityContext = SecurityContext.AUTH_DISABLED;

            when(initialTransaction.TransactionType()).thenReturn(transactionType);
            when(initialTransaction.SecurityContext()).thenReturn(securityContext);
            when(initialTransaction.TerminationReason()).thenReturn(null);
            QueryRegistryOperations        initialQueryRegistry = mock(typeof(QueryRegistryOperations));
            ExecutingQuery                 executingQuery       = mock(typeof(ExecutingQuery));
            PropertyContainerLocker        locker   = null;
            ThreadToStatementContextBridge txBridge = mock(typeof(ThreadToStatementContextBridge));

            Statement           secondStatement   = mock(typeof(Statement));
            KernelTransaction   secondKTX         = MockTransaction(secondStatement);
            InternalTransaction secondTransaction = mock(typeof(InternalTransaction));

            when(secondTransaction.TerminationReason()).thenReturn(null);
            QueryRegistryOperations secondQueryRegistry = mock(typeof(QueryRegistryOperations));

            when(executingQuery.QueryText()).thenReturn("X");
            when(executingQuery.QueryParameters()).thenReturn(EMPTY_MAP);
            when(_initialStatement.queryRegistration()).thenReturn(initialQueryRegistry);
            when(_queryService.beginTransaction(transactionType, securityContext)).thenReturn(secondTransaction);
            when(txBridge.GetKernelTransactionBoundToThisThread(true)).thenReturn(initialKTX, initialKTX, secondKTX);
            when(secondStatement.QueryRegistration()).thenReturn(secondQueryRegistry);

            Kernel kernel = mock(typeof(Kernel));
            Neo4jTransactionalContext context = new Neo4jTransactionalContext(_queryService, txBridge, locker, initialTransaction, _initialStatement, executingQuery, kernel);

            // When
            context.CommitAndRestartTx();

            // Then
            object[] mocks = new object[] { txBridge, initialTransaction, initialKTX, initialQueryRegistry, secondQueryRegistry, secondKTX };
            InOrder  order = Mockito.inOrder(mocks);

            // (0) Constructor
            order.verify(initialTransaction).transactionType();
            order.verify(initialTransaction).securityContext();
            order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
            order.verify(initialTransaction).terminationReason();                 // not terminated check

            // (1) Collect stats
            order.verify(initialKTX).executionStatistics();

            // (2) Unbind old
            order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
            order.verify(txBridge).unbindTransactionFromCurrentThread();

            // (3) Register and unbind new
            order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
            order.verify(secondKTX).acquireStatement();
            order.verify(secondQueryRegistry).registerExecutingQuery(executingQuery);
            order.verify(txBridge).unbindTransactionFromCurrentThread();

            // (4) Rebind, unregister, and close old
            order.verify(txBridge).bindTransactionToCurrentThread(initialKTX);
            order.verify(initialQueryRegistry).unregisterExecutingQuery(executingQuery);
            order.verify(initialTransaction).success();
            order.verify(initialTransaction).close();
            order.verify(txBridge).unbindTransactionFromCurrentThread();

            // (5) Rebind new
            order.verify(txBridge).bindTransactionToCurrentThread(secondKTX);
            verifyNoMoreInteractions(mocks);
        }
コード例 #11
0
 public abstract InternalTransaction BeginLocalTransactionAsUser(S subject, KernelTransaction.Type txType);
コード例 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.impl.coreapi.InternalTransaction beginLocalTransactionAsUser(RESTSubject subject, org.neo4j.kernel.api.KernelTransaction.Type txType) throws Throwable
        public override InternalTransaction BeginLocalTransactionAsUser(RESTSubject subject, KernelTransaction.Type txType)
        {
            LoginContext loginContext = _authManager.login(newBasicAuthToken(subject.Username, subject.Password));

            return(LocalGraph.beginTransaction(txType, loginContext));
        }
コード例 #13
0
 internal virtual string[] ExecuteEarly(ThreadingRule threading, S subject, KernelTransaction.Type txType, params string[] queries)
 {
     return(DoExecute(threading, subject, txType, true, queries));
 }
コード例 #14
0
 internal virtual string ExecuteEarly(ThreadingRule threading, S subject, KernelTransaction.Type txType, string query)
 {
     return(DoExecute(threading, subject, txType, true, query)[0]);
 }