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); } }
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); }
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; }
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(); }
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; }
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); }
public override InternalTransaction BeginTransaction(KernelTransaction.Type type, LoginContext loginContext, long timeout, TimeUnit unit) { return(GraphDatabaseAPI.beginTransaction(type, loginContext, timeout, unit)); }
public override InternalTransaction BeginTransaction(KernelTransaction.Type type, LoginContext loginContext) { return(GraphDatabaseAPI.beginTransaction(type, loginContext)); }
//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); } }
//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); }
public abstract InternalTransaction BeginLocalTransactionAsUser(S subject, KernelTransaction.Type txType);
//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)); }
internal virtual string[] ExecuteEarly(ThreadingRule threading, S subject, KernelTransaction.Type txType, params string[] queries) { return(DoExecute(threading, subject, txType, true, queries)); }
internal virtual string ExecuteEarly(ThreadingRule threading, S subject, KernelTransaction.Type txType, string query) { return(DoExecute(threading, subject, txType, true, query)[0]); }