private KernelTransaction NewKernelTransaction(long lastTransactionTimestampWhenStarted) { KernelTransaction txToTerminate = mock(typeof(KernelTransaction)); when(txToTerminate.LastTransactionTimestampWhenStarted()).thenReturn(lastTransactionTimestampWhenStarted); return(txToTerminate); }
public static TransactionStateChecker Create(TransitionalPeriodTransactionMessContainer container) { KernelTransaction topLevelTransactionBoundToThisThread = container.Bridge.getKernelTransactionBoundToThisThread(true); KernelStatement kernelStatement = ( KernelStatement )topLevelTransactionBoundToThisThread.AcquireStatement(); return(new TransactionStateChecker(kernelStatement, nodeId => kernelStatement.HasTxStateWithChanges() && kernelStatement.TxState().nodeIsDeletedInThisTx(nodeId), relId => kernelStatement.HasTxStateWithChanges() && kernelStatement.TxState().relationshipIsDeletedInThisTx(relId))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void visitsRelationshipTypeIds() public virtual void VisitsRelationshipTypeIds() { // GIVEN DbStructureVisitor visitor = mock(typeof(DbStructureVisitor)); Node lhs = _graph.createNode(); Node rhs = _graph.createNode(); lhs.CreateRelationshipTo(rhs, withName("KNOWS")); lhs.CreateRelationshipTo(rhs, withName("LOVES")); lhs.CreateRelationshipTo(rhs, withName("FAWNS_AT")); int knowsId; int lovesId; int fawnsAtId; KernelTransaction ktx = ktx(); TokenRead tokenRead = ktx.TokenRead(); knowsId = tokenRead.RelationshipType("KNOWS"); lovesId = tokenRead.RelationshipType("LOVES"); fawnsAtId = tokenRead.RelationshipType("FAWNS_AT"); // WHEN Accept(visitor); // THEN verify(visitor).visitRelationshipType(knowsId, "KNOWS"); verify(visitor).visitRelationshipType(lovesId, "LOVES"); verify(visitor).visitRelationshipType(fawnsAtId, "FAWNS_AT"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTerminateOutdatedTransactions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTerminateOutdatedTransactions() { // given long safeZone = 10; int txCount = 3; long firstCommitTimestamp = 10; long commitTimestampInterval = 2; TransactionBatchCommitter committer = NewBatchCommitter(safeZone); TransactionChain chain = CreateTxChain(txCount, firstCommitTimestamp, commitTimestampInterval); long timestampOutsideSafeZone = chain.Last.transactionRepresentation().LatestCommittedTxWhenStarted - safeZone - 1; KernelTransaction txToTerminate = NewKernelTransaction(timestampOutsideSafeZone); KernelTransaction tx = NewKernelTransaction(firstCommitTimestamp - 1); when(_kernelTransactions.activeTransactions()).thenReturn(Iterators.asSet(NewHandle(txToTerminate), NewHandle(tx))); // when committer.Apply(chain.First, chain.Last); // then verify(txToTerminate).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Outdated); verify(tx, never()).markForTermination(any()); _logProvider.formattedMessageMatcher().assertContains("Marking transaction for termination"); _logProvider.formattedMessageMatcher().assertContains("lastCommittedTxId:" + (BASE_TX_ID + txCount - 1)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void visitsLabelIds() public virtual void VisitsLabelIds() { // GIVEN DbStructureVisitor visitor = mock(typeof(DbStructureVisitor)); _graph.createNode(label("Person")); _graph.createNode(label("Party")); _graph.createNode(label("Animal")); int personLabelId; int partyLabelId; int animalLabelId; KernelTransaction ktx = ktx(); TokenRead tokenRead = ktx.TokenRead(); personLabelId = tokenRead.NodeLabel("Person"); partyLabelId = tokenRead.NodeLabel("Party"); animalLabelId = tokenRead.NodeLabel("Animal"); // WHEN Accept(visitor); // THEN verify(visitor).visitLabel(personLabelId, "Person"); verify(visitor).visitLabel(partyLabelId, "Party"); verify(visitor).visitLabel(animalLabelId, "Animal"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void createCompositeIndex(org.neo4j.graphdb.GraphDatabaseService graphDb, String label, String... properties) throws Exception protected internal override void CreateCompositeIndex(GraphDatabaseService graphDb, string label, params string[] properties) { GraphDatabaseAPI @internal = ( GraphDatabaseAPI )graphDb; KernelTransaction ktx = @internal.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true); SchemaWrite schemaWrite = ktx.SchemaWrite(); TokenWrite token = ktx.TokenWrite(); schemaWrite.IndexCreate(SchemaDescriptorFactory.forLabel(token.LabelGetOrCreateForName("Person"), token.PropertyKeyGetOrCreateForName("firstname"), token.PropertyKeyGetOrCreateForName("surname"))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private long createLabeledNode(int labelId) throws Exception private long CreateLabeledNode(int labelId) { KernelTransaction ktx = ktx(); long nodeId = ktx.DataWrite().nodeCreate(); ktx.DataWrite().nodeAddLabel(nodeId, labelId); return(nodeId); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private String getOrCreateSchemaState(String key, final String maybeSetThisState) private string GetOrCreateSchemaState(string key, string maybeSetThisState) { using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = StatementContextSupplier.getKernelTransactionBoundToThisThread(true); string state = ktx.SchemaRead().schemaStateGetOrCreate(key, s => maybeSetThisState); tx.Success(); return(state); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void closeStatementOnClose() public virtual void CloseStatementOnClose() { KernelTransaction kernelTransaction = mock(typeof(KernelTransaction)); Statement statement = mock(typeof(Statement)); when(kernelTransaction.AcquireStatement()).thenReturn(statement); //noinspection EmptyTryBlock using (IndexProcedures ignored = new IndexProcedures(kernelTransaction, null)) { } verify(statement).close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static org.neo4j.storageengine.api.schema.IndexDescriptor createAnIndex(HighlyAvailableGraphDatabase db, org.neo4j.graphdb.Label label, String propertyName) throws org.neo4j.internal.kernel.api.exceptions.KernelException private static IndexDescriptor CreateAnIndex(HighlyAvailableGraphDatabase db, Label label, string propertyName) { using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = KernelTransaction(db); int labelId = ktx.TokenWrite().labelGetOrCreateForName(label.Name()); int propertyKeyId = ktx.TokenWrite().propertyKeyGetOrCreateForName(propertyName); IndexReference index = ktx.SchemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)); tx.Success(); return(( IndexDescriptor )index); } }
private static void AssertOnNodeCounts(int expectedTotalNodes, int expectedLabelledNodes, Label label, HighlyAvailableGraphDatabase db) { using (Transaction ignored = Db.beginTx()) { KernelTransaction transaction = KernelTransaction(db); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int labelId = transaction.tokenRead().nodeLabel(label.name()); int labelId = transaction.TokenRead().nodeLabel(label.Name()); assertEquals(expectedTotalNodes, transaction.DataRead().countsForNode(-1)); assertEquals(expectedLabelledNodes, transaction.DataRead().countsForNode(labelId)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() public virtual void Setup() { KernelTransaction transaction = mock(typeof(KernelTransaction)); _tokenRead = mock(typeof(TokenRead)); _schemaRead = mock(typeof(SchemaRead)); _procedure = new IndexProcedures(transaction, null); when(transaction.TokenRead()).thenReturn(_tokenRead); when(transaction.SchemaRead()).thenReturn(_schemaRead); _indexingService = mock(typeof(IndexingService)); _procedure = new IndexProcedures(transaction, _indexingService); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void before() public virtual void Before() { ThreadToStatementContextBridge bridge = mock(typeof(ThreadToStatementContextBridge)); Statement statement = mock(typeof(Statement)); when(bridge.Get()).thenReturn(statement); _kernelTransaction = spy(typeof(KernelTransaction)); _locks = mock(typeof(Locks)); when(_kernelTransaction.locks()).thenReturn(_locks); _placeboTx = new PlaceboTransaction(_kernelTransaction); _resource = mock(typeof(Node)); when(_resource.Id).thenReturn(1L); }
/// <param name="start"> the label of the start node of relationships to get the number of, or {@code null} for "any". </param> /// <param name="type"> the type of the relationships to get the number of, or {@code null} for "any". </param> /// <param name="end"> the label of the end node of relationships to get the number of, or {@code null} for "any". </param> private long CountsForRelationship(Label start, RelationshipType type, Label end) { KernelTransaction ktx = _ktxSupplier.get(); using (Statement ignore = ktx.AcquireStatement()) { TokenRead tokenRead = ktx.TokenRead(); int startId; int typeId; int endId; // start if (start == null) { startId = [email protected]_Fields.ANY_LABEL; } else { if ([email protected]_Fields.NO_TOKEN == (startId = tokenRead.NodeLabel(start.Name()))) { return(0); } } // type if (type == null) { typeId = [email protected]_Fields.ANY_RELATIONSHIP_TYPE; } else { if ([email protected]_Fields.NO_TOKEN == (typeId = tokenRead.RelationshipType(type.Name()))) { return(0); } } // end if (end == null) { endId = [email protected]_Fields.ANY_LABEL; } else { if ([email protected]_Fields.NO_TOKEN == (endId = tokenRead.NodeLabel(end.Name()))) { return(0); } } return(ktx.DataRead().countsForRelationship(startId, typeId, endId)); } }
public override KernelTransaction BeginTransaction(KernelTransaction.Type type, LoginContext ignored, long timeout) { try { _availability.assertDatabaseAvailable(); KernelTransaction kernelTx = _sourceModule.kernelAPI.get().beginTransaction(type, this._securityContext, timeout); kernelTx.RegisterCloseListener(txId => _threadToTransactionBridge.unbindTransactionFromCurrentThread()); _threadToTransactionBridge.bindTransactionToCurrentThread(kernelTx); return(kernelTx); } catch (TransactionFailureException e) { throw new Org.Neo4j.Graphdb.TransactionFailureException(e.Message, e); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnTerminationReason() public virtual void ShouldReturnTerminationReason() { KernelTransaction kernelTransaction = mock(typeof(KernelTransaction)); when(kernelTransaction.ReasonIfTerminated).thenReturn(null).thenReturn(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Interrupted); PlaceboTransaction tx = new PlaceboTransaction(kernelTransaction); Optional <Status> terminationReason1 = tx.TerminationReason(); Optional <Status> terminationReason2 = tx.TerminationReason(); assertFalse(terminationReason1.Present); assertTrue(terminationReason2.Present); assertEquals(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Interrupted, terminationReason2.get()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void lockNodeUsingUniqueIndexSeek(org.neo4j.kernel.internal.GraphDatabaseAPI database, org.neo4j.graphdb.Label label, String nameProperty) throws org.neo4j.internal.kernel.api.exceptions.KernelException private static void LockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, Label label, string nameProperty) { using (Transaction transaction = database.BeginTx()) { ThreadToStatementContextBridge contextBridge = database.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)); KernelTransaction kernelTransaction = contextBridge.GetKernelTransactionBoundToThisThread(true); TokenRead tokenRead = kernelTransaction.TokenRead(); Read dataRead = kernelTransaction.DataRead(); int labelId = tokenRead.NodeLabel(label.Name()); int propertyId = tokenRead.PropertyKey(nameProperty); IndexReference indexReference = kernelTransaction.SchemaRead().index(labelId, propertyId); dataRead.LockingNodeUniqueIndexSeek(indexReference, IndexQuery.ExactPredicate.exact(propertyId, "value")); transaction.Success(); } }
private bool SchemaStateContains(string key) { using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = StatementContextSupplier.getKernelTransactionBoundToThisThread(true); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean result = new java.util.concurrent.atomic.AtomicBoolean(true); AtomicBoolean result = new AtomicBoolean(true); ktx.SchemaRead().schemaStateGetOrCreate(key, s => { result.set(false); return(null); }); tx.Success(); return(result.get()); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.graphdb.GraphDatabaseService apply(org.neo4j.kernel.api.proc.Context context) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException public override GraphDatabaseService Apply(Context context) { KernelTransaction tx = context.GetOrElse(Org.Neo4j.Kernel.api.proc.Context_Fields.KernelTransaction, null); SecurityContext securityContext; if (tx != null) { securityContext = tx.SecurityContext(); } else { securityContext = context.Get(Org.Neo4j.Kernel.api.proc.Context_Fields.SecurityContext); } GraphDatabaseFacade facade = new GraphDatabaseFacade(); ProcedureGDBFacadeSPI procedureGDBFacadeSPI = new ProcedureGDBFacadeSPI(_dataSource, _dataSource.neoStoreDataSource.DependencyResolver, _availability, _urlValidator, securityContext, _bridge); facade.Init(procedureGDBFacadeSPI, _bridge, _platform.config, _tokenHolders); return(facade); }
/// <param name="label"> the label to get the number of nodes of, or {@code null} to get the total number of nodes. </param> private long CountsForNode(Label label) { KernelTransaction transaction = _transactionSupplier.get(); Read read = transaction.DataRead(); int labelId; if (label == null) { labelId = StatementConstants.ANY_LABEL; } else { if ([email protected]_Fields.NO_TOKEN == (labelId = transaction.TokenRead().nodeLabel(label.Name()))) { return(0); } } return(read.CountsForNode(labelId)); }
public override IndexHits <Relationship> Query(object queryOrQueryObjectOrNull, Node startNodeOrNull, Node endNodeOrNull) { KernelTransaction ktx = TxBridge.get(); try { using (Statement ignore = ktx.AcquireStatement()) { RelationshipExplicitIndexCursor cursor = ktx.Cursors().allocateRelationshipExplicitIndexCursor(); long source = startNodeOrNull == null ? NO_SUCH_NODE : startNodeOrNull.Id; long target = endNodeOrNull == null ? NO_SUCH_NODE : endNodeOrNull.Id; ktx.IndexRead().relationshipExplicitIndexQuery(cursor, NameConflict, queryOrQueryObjectOrNull, source, target); return(new CursorWrappingRelationshipIndexHits(cursor, GraphDatabase, ktx, NameConflict)); } } catch (ExplicitIndexNotFoundKernelException) { throw new NotFoundException(Type + " index '" + NameConflict + "' doesn't exist"); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void mixingBeansApiWithKernelAPI() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MixingBeansApiWithKernelAPI() { // 1: Start your transactions through the Beans API Transaction transaction = Db.beginTx(); // 2: Get a hold of a KernelAPI transaction this way: KernelTransaction ktx = StatementContextSupplier.getKernelTransactionBoundToThisThread(true); // 3: Now you can interact through both the statement context and the kernel API to manipulate the // same transaction. Node node = Db.createNode(); int labelId = ktx.TokenWrite().labelGetOrCreateForName("labello"); ktx.DataWrite().nodeAddLabel(node.Id, labelId); // 4: Commit through the beans API transaction.Success(); transaction.Close(); }
private void SetUpMocks() { _database = mock(typeof(Database)); _databaseFacade = mock(typeof(GraphDatabaseFacade)); _resolver = mock(typeof(DependencyResolver)); _executionEngine = mock(typeof(ExecutionEngine)); _statementBridge = mock(typeof(ThreadToStatementContextBridge)); _databaseQueryService = mock(typeof(GraphDatabaseQueryService)); _kernelTransaction = mock(typeof(KernelTransaction)); _statement = mock(typeof(Statement)); _request = mock(typeof(HttpServletRequest)); InternalTransaction transaction = new TopLevelTransaction(_kernelTransaction); LoginContext loginContext = AUTH_DISABLED; KernelTransaction.Type type = KernelTransaction.Type.@implicit; QueryRegistryOperations registryOperations = mock(typeof(QueryRegistryOperations)); when(_statement.queryRegistration()).thenReturn(registryOperations); when(_statementBridge.get()).thenReturn(_statement); when(_kernelTransaction.securityContext()).thenReturn(loginContext.Authorize(s => - 1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME)); when(_kernelTransaction.transactionType()).thenReturn(type); when(_database.Graph).thenReturn(_databaseFacade); when(_databaseFacade.DependencyResolver).thenReturn(_resolver); when(_resolver.resolveDependency(typeof(QueryExecutionEngine))).thenReturn(_executionEngine); when(_resolver.resolveDependency(typeof(ThreadToStatementContextBridge))).thenReturn(_statementBridge); when(_resolver.resolveDependency(typeof(GraphDatabaseQueryService))).thenReturn(_databaseQueryService); when(_databaseQueryService.beginTransaction(type, loginContext)).thenReturn(transaction); when(_databaseQueryService.beginTransaction(type, loginContext, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(transaction); when(_databaseQueryService.DependencyResolver).thenReturn(_resolver); when(_request.Scheme).thenReturn("http"); when(_request.RemoteAddr).thenReturn("127.0.0.1"); when(_request.RemotePort).thenReturn(5678); when(_request.ServerName).thenReturn("127.0.0.1"); when(_request.ServerPort).thenReturn(7474); when(_request.RequestURI).thenReturn("/"); }
public virtual void Begin() { Db.beginTx(); GraphDbTx = Bridge.getKernelTransactionBoundToThisThread(false); }
private KernelTransactionHandle NewHandle(KernelTransaction tx) { return(new TestKernelTransactionHandle(tx)); }
internal ProcedureTransactionImpl(KernelTransaction ktx) { this.Ktx = ktx; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.procedure.ProcedureTransaction apply(org.neo4j.kernel.api.proc.Context ctx) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException public override ProcedureTransaction Apply(Context ctx) { KernelTransaction ktx = ctx.Get(KERNEL_TRANSACTION); return(new ProcedureTransactionImpl(ktx)); }
public virtual void Suspend() { GraphDbTx = Bridge.getKernelTransactionBoundToThisThread(true); Bridge.unbindTransactionFromCurrentThread(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.procedure.TerminationGuard apply(org.neo4j.kernel.api.proc.Context ctx) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException public override TerminationGuard Apply(Context ctx) { KernelTransaction ktx = ctx.Get(KERNEL_TRANSACTION); return(new TransactionTerminationGuard(this, ktx)); }
internal TransactionTerminationGuard(TerminationGuardProvider outerInstance, KernelTransaction ktx) { this._outerInstance = outerInstance; this.Ktx = ktx; }