Пример #1
0
        public override void CommitAndRestartTx()
        {
            /*
             * This method is use by the Cypher runtime to cater for PERIODIC COMMIT, which allows a single query to
             * periodically, after x number of rows, to commit a transaction and spawn a new one.
             *
             * To still keep track of the running stream after switching transactions, we need to open the new transaction
             * before closing the old one. This way, a query will not disappear and appear when switching transactions.
             *
             * Since our transactions are thread bound, we must first unbind the old transaction from the thread before
             * creating a new one. And then we need to do that thread switching again to close the old transaction.
             */

            CheckNotTerminated();

            CollectTransactionExecutionStatistic();

            // (1) Unbind current transaction
            QueryRegistryOperations oldQueryRegistryOperations = _statement.queryRegistration();
            Statement           oldStatement   = _statement;
            InternalTransaction oldTransaction = _transaction;
            KernelTransaction   oldKernelTx    = _txBridge.getKernelTransactionBoundToThisThread(true);

            _txBridge.unbindTransactionFromCurrentThread();

            // (2) Create, bind, register, and unbind new transaction
            _transaction       = _graph.beginTransaction(TransactionType, SecurityContextConflict);
            _kernelTransaction = _txBridge.getKernelTransactionBoundToThisThread(true);
            _statement         = _kernelTransaction.acquireStatement();
            _statement.queryRegistration().registerExecutingQuery(_executingQuery);
            _txBridge.unbindTransactionFromCurrentThread();

            // (3) Rebind old transaction just to commit and close it (and unregister as a side effect of that)
            _txBridge.bindTransactionToCurrentThread(oldKernelTx);
            oldQueryRegistryOperations.UnregisterExecutingQuery(_executingQuery);
            try
            {
                oldStatement.Close();
                oldTransaction.Success();
                oldTransaction.Close();
            }
            catch (Exception t)
            {
                // Corner case: The old transaction might have been terminated by the user. Now we also need to
                // terminate the new transaction.
                _txBridge.bindTransactionToCurrentThread(_kernelTransaction);
                _transaction.failure();
                _transaction.close();
                _txBridge.unbindTransactionFromCurrentThread();
                throw t;
            }

            // (4) Unbind the now closed old transaction and rebind the new transaction for continued execution
            _txBridge.unbindTransactionFromCurrentThread();
            _txBridge.bindTransactionToCurrentThread(_kernelTransaction);
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _procs.registerComponent(typeof(KernelTransaction), ctx => ctx.get(KERNEL_TRANSACTION), false);
            _procs.registerComponent(typeof(DependencyResolver), ctx => ctx.get(_dependencyResolver), false);
            _procs.registerComponent(typeof(GraphDatabaseAPI), ctx => ctx.get(_graphdatabaseapi), false);
            _procs.registerComponent(typeof(SecurityContext), ctx => ctx.get(SECURITY_CONTEXT), true);

            _procs.registerComponent(typeof(Log), ctx => ctx.get(_log), false);
            _procs.registerType(typeof(Node), NTNode);
            _procs.registerType(typeof(Relationship), NTRelationship);
            _procs.registerType(typeof(Path), NTPath);

            (new SpecialBuiltInProcedures("1.3.37", Edition.enterprise.ToString())).accept(_procs);
            _procs.registerProcedure(typeof(BuiltInProcedures));
            _procs.registerProcedure(typeof(BuiltInDbmsProcedures));

            when(_tx.acquireStatement()).thenReturn(_statement);
            when(_tx.tokenRead()).thenReturn(_tokens);
            when(_tx.dataRead()).thenReturn(_read);
            when(_tx.schemaRead()).thenReturn(_schemaRead);
            when(_schemaRead.snapshot()).thenReturn(_schemaReadCore);

            when(_tokens.propertyKeyGetAllTokens()).thenAnswer(AsTokens(_propKeys));
            when(_tokens.labelsGetAllTokens()).thenAnswer(AsTokens(_labels));
            when(_tokens.relationshipTypesGetAllTokens()).thenAnswer(AsTokens(_relTypes));
            when(_schemaReadCore.indexesGetAll()).thenAnswer(i => Iterators.concat(_indexes.GetEnumerator(), _uniqueIndexes.GetEnumerator()));
            when(_schemaReadCore.index(any(typeof(SchemaDescriptor)))).thenAnswer((Answer <IndexReference>)invocationOnMock =>
            {
                SchemaDescriptor schema = invocationOnMock.getArgument(0);
                int label = Schema.keyId();
                int prop  = Schema.PropertyId;
                return(GetIndexReference(label, prop));
            });
            when(_schemaReadCore.constraintsGetAll()).thenAnswer(i => _constraints.GetEnumerator());

            when(_tokens.propertyKeyName(anyInt())).thenAnswer(invocation => _propKeys[invocation.getArgument(0)]);
            when(_tokens.nodeLabelName(anyInt())).thenAnswer(invocation => _labels[invocation.getArgument(0)]);
            when(_tokens.relationshipTypeName(anyInt())).thenAnswer(invocation => _relTypes[invocation.getArgument(0)]);

            when(_indexingService.getIndexId(any(typeof(SchemaDescriptor)))).thenReturn(42L);

            when(_schemaReadCore.constraintsGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
            when(_schemaReadCore.indexesGetForLabel(anyInt())).thenReturn(emptyIterator());
            when(_schemaReadCore.indexesGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
            when(_schemaReadCore.constraintsGetForLabel(anyInt())).thenReturn(emptyIterator());
            when(_read.countsForNode(anyInt())).thenReturn(1L);
            when(_read.countsForRelationship(anyInt(), anyInt(), anyInt())).thenReturn(1L);
            when(_schemaReadCore.indexGetState(any(typeof(IndexReference)))).thenReturn(InternalIndexState.ONLINE);
        }
Пример #3
0
 public override Statement AcquireStatement()
 {
     return(Internal.acquireStatement());
 }