Search in sources :

Example 1 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class NeoStoreIndexStoreViewTest method getOrCreateIds.

private void getOrCreateIds() throws KernelException {
    try (Transaction tx = graphDb.beginTx()) {
        ThreadToStatementContextBridge bridge = graphDb.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = bridge.get()) {
            labelId = statement.tokenWriteOperations().labelGetOrCreateForName("Person");
            propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("name");
        }
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 2 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class ExecutionResultTest method activeTransaction.

private TopLevelTransaction activeTransaction() {
    ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
    KernelTransaction kernelTransaction = bridge.getTopLevelTransactionBoundToThisThread(false);
    return kernelTransaction == null ? null : new TopLevelTransaction(kernelTransaction, null);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction)

Example 3 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class IndexRecoveryIT method createSomeBananas.

private Set<IndexEntryUpdate> createSomeBananas(Label label) {
    Set<IndexEntryUpdate> updates = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctxSupplier = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = ctxSupplier.get()) {
            int labelId = statement.readOperations().labelGetForName(label.name());
            int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
            LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
            for (int number : new int[] { 4, 10 }) {
                Node node = db.createNode(label);
                node.setProperty(key, number);
                updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, number));
            }
        }
        tx.success();
        return updates;
    }
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) HashSet(java.util.HashSet)

Example 4 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class Neo4jTransactionalContextFactory method create.

@Deprecated
public static TransactionalContextFactory create(GraphDatabaseQueryService queryService, PropertyContainerLocker locker) {
    DependencyResolver resolver = queryService.getDependencyResolver();
    ThreadToStatementContextBridge txBridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
    Guard guard = resolver.resolveDependency(Guard.class);
    Neo4jTransactionalContext.Creator contextCreator = (Supplier<Statement> statementSupplier, InternalTransaction tx, Statement initialStatement, ExecutingQuery executingQuery) -> new Neo4jTransactionalContext(queryService, statementSupplier, guard, txBridge, locker, tx, initialStatement, executingQuery);
    return new Neo4jTransactionalContextFactory(txBridge, contextCreator);
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Guard(org.neo4j.kernel.guard.Guard) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 5 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class Neo4jTransactionalContextTest method neverStopsExecutingQueryDuringCommitAndRestartTx.

@SuppressWarnings("ConstantConditions")
@Test
public void neverStopsExecutingQueryDuringCommitAndRestartTx() {
    // Given
    KernelTransaction initialKTX = mock(KernelTransaction.class);
    InternalTransaction initialTransaction = mock(InternalTransaction.class, new ReturnsDeepStubs());
    KernelTransaction.Type transactionType = KernelTransaction.Type.implicit;
    SecurityContext securityContext = SecurityContext.AUTH_DISABLED;
    when(initialTransaction.transactionType()).thenReturn(transactionType);
    when(initialTransaction.securityContext()).thenReturn(securityContext);
    QueryRegistryOperations initialQueryRegistry = mock(QueryRegistryOperations.class);
    ExecutingQuery executingQuery = mock(ExecutingQuery.class);
    PropertyContainerLocker locker = null;
    ThreadToStatementContextBridge txBridge = mock(ThreadToStatementContextBridge.class);
    KernelTransaction secondKTX = mock(KernelTransaction.class);
    InternalTransaction secondTransaction = mock(InternalTransaction.class);
    Statement secondStatement = mock(Statement.class);
    QueryRegistryOperations secondQueryRegistry = mock(QueryRegistryOperations.class);
    when(executingQuery.queryText()).thenReturn("X");
    when(executingQuery.queryParameters()).thenReturn(Collections.emptyMap());
    when(initialStatement.queryRegistration()).thenReturn(initialQueryRegistry);
    when(queryService.beginTransaction(transactionType, securityContext)).thenReturn(secondTransaction);
    when(txBridge.getKernelTransactionBoundToThisThread(true)).thenReturn(initialKTX, secondKTX);
    when(txBridge.get()).thenReturn(secondStatement);
    when(secondStatement.queryRegistration()).thenReturn(secondQueryRegistry);
    Neo4jTransactionalContext context = new Neo4jTransactionalContext(queryService, null, guard, txBridge, locker, initialTransaction, initialStatement, executingQuery);
    // When
    context.commitAndRestartTx();
    // Then
    Object[] mocks = { txBridge, initialTransaction, initialQueryRegistry, initialKTX, secondQueryRegistry, secondKTX };
    InOrder order = Mockito.inOrder(mocks);
    // (0) Constructor
    order.verify(initialTransaction).transactionType();
    order.verify(initialTransaction).securityContext();
    // (1) Unbind old
    order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
    order.verify(txBridge).unbindTransactionFromCurrentThread();
    // (2) Register and unbind new
    order.verify(txBridge).get();
    order.verify(secondQueryRegistry).registerExecutingQuery(executingQuery);
    order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
    order.verify(txBridge).unbindTransactionFromCurrentThread();
    // (3) 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();
    // (4) Rebind new
    order.verify(txBridge).bindTransactionToCurrentThread(secondKTX);
    verifyNoMoreInteractions(mocks);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InOrder(org.mockito.InOrder) Statement(org.neo4j.kernel.api.Statement) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) QueryRegistryOperations(org.neo4j.kernel.api.QueryRegistryOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) PropertyContainerLocker(org.neo4j.kernel.impl.coreapi.PropertyContainerLocker) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) ReturnsDeepStubs(org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs) Test(org.junit.Test)

Aggregations

ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)29 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)15 Statement (org.neo4j.kernel.api.Statement)14 Test (org.junit.Test)8 Transaction (org.neo4j.graphdb.Transaction)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 Node (org.neo4j.graphdb.Node)4 Guard (org.neo4j.kernel.guard.Guard)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)3 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3 RemoteException (java.rmi.RemoteException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Before (org.junit.Before)2