Пример #1
0
        public virtual TransactionalContext Create(HttpServletRequest request, GraphDatabaseQueryService service, Transaction_Type type, LoginContext loginContext, string query, IDictionary <string, object> queryParameters)
        {
            TransactionalContextFactory contextFactory   = Neo4jTransactionalContextFactory.create(service, _locker);
            ClientConnectionInfo        clientConnection = HttpConnectionInfoFactory.create(request);
            InternalTransaction         transaction      = service.BeginTransaction(type, loginContext);

            return(contextFactory.NewContext(clientConnection, transaction, query, ValueUtils.asMapValue(queryParameters)));
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<LockOperationRecord> traceQueryLocks(String query, LockOperationListener... listeners) throws org.neo4j.kernel.impl.query.QueryExecutionKernelException
        private IList <LockOperationRecord> TraceQueryLocks(string query, params LockOperationListener[] listeners)
        {
            GraphDatabaseQueryService graph           = DatabaseRule.resolveDependency(typeof(GraphDatabaseQueryService));
            QueryExecutionEngine      executionEngine = DatabaseRule.resolveDependency(typeof(QueryExecutionEngine));

            using (InternalTransaction tx = graph.BeginTransaction(KernelTransaction.Type.@implicit, LoginContext.AUTH_DISABLED))
            {
                TransactionalContextWrapper context = new TransactionalContextWrapper(CreateTransactionContext(graph, tx, query), listeners);
                executionEngine.ExecuteQuery(query, VirtualValues.emptyMap(), context);
                return(new List <LockOperationRecord>(context.RecordingLocks.LockOperationRecords));
            }
        }
Пример #3
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);
            }
        }