Search in sources :

Example 66 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class TransitionalPeriodTransactionMessContainer method create.

public TransactionalContext create(HttpServletRequest request, GraphDatabaseQueryService service, Type type, SecurityContext securityContext, String query, Map<String, Object> queryParameters) {
    TransactionalContextFactory contextFactory = Neo4jTransactionalContextFactory.create(service, locker);
    ClientConnectionInfo clientConnection = HttpConnectionInfoFactory.create(request);
    InternalTransaction transaction = service.beginTransaction(type, securityContext);
    return contextFactory.newContext(clientConnection, transaction, query, queryParameters);
}
Also used : ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory)

Example 67 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class CypherExecutorTest method setUpMocks.

private void setUpMocks() {
    database = mock(Database.class);
    databaseFacade = mock(GraphDatabaseFacade.class);
    resolver = mock(DependencyResolver.class);
    executionEngine = mock(ExecutionEngine.class);
    statementBridge = mock(ThreadToStatementContextBridge.class);
    databaseQueryService = mock(GraphDatabaseQueryService.class);
    kernelTransaction = mock(KernelTransaction.class);
    statement = mock(Statement.class);
    request = mock(HttpServletRequest.class);
    InternalTransaction transaction = new TopLevelTransaction(kernelTransaction, () -> statement);
    SecurityContext securityContext = AUTH_DISABLED;
    KernelTransaction.Type type = KernelTransaction.Type.implicit;
    QueryRegistryOperations registryOperations = mock(QueryRegistryOperations.class);
    when(statement.queryRegistration()).thenReturn(registryOperations);
    when(statementBridge.get()).thenReturn(statement);
    when(kernelTransaction.securityContext()).thenReturn(securityContext);
    when(kernelTransaction.transactionType()).thenReturn(type);
    when(database.getGraph()).thenReturn(databaseFacade);
    when(databaseFacade.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(QueryExecutionEngine.class)).thenReturn(executionEngine);
    when(resolver.resolveDependency(ThreadToStatementContextBridge.class)).thenReturn(statementBridge);
    when(resolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(databaseQueryService);
    when(databaseQueryService.beginTransaction(type, securityContext)).thenReturn(transaction);
    when(databaseQueryService.beginTransaction(type, securityContext, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(transaction);
    when(databaseQueryService.getDependencyResolver()).thenReturn(resolver);
    when(request.getScheme()).thenReturn("http");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getRemotePort()).thenReturn(5678);
    when(request.getServerName()).thenReturn("127.0.0.1");
    when(request.getServerPort()).thenReturn(7474);
    when(request.getRequestURI()).thenReturn("/");
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Statement(org.neo4j.kernel.api.Statement) QueryRegistryOperations(org.neo4j.kernel.api.QueryRegistryOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) ExecutionEngine(org.neo4j.cypher.internal.javacompat.ExecutionEngine) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Example 68 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class GraphDatabaseFacadeTest method executeQueryStartDefaultTransaction.

@Test
public void executeQueryStartDefaultTransaction() {
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    InternalTransaction transaction = new TopLevelTransaction(kernelTransaction, null);
    when(queryService.beginTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED)).thenReturn(transaction);
    graphDatabaseFacade.execute("create (n)");
    graphDatabaseFacade.execute("create (n)", new HashMap<>());
    long timeout = Config.embeddedDefaults().get(GraphDatabaseSettings.transaction_timeout);
    verify(spi, times(2)).beginTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED, timeout);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 69 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class Neo4jTransactionalContextTest method checkKernelStatementOnCheck.

@Test
public void checkKernelStatementOnCheck() throws Exception {
    InternalTransaction initialTransaction = mock(InternalTransaction.class, new ReturnsDeepStubs());
    Neo4jTransactionalContext transactionalContext = new Neo4jTransactionalContext(null, null, guard, null, null, initialTransaction, initialStatement, null);
    transactionalContext.check();
    verify(guard).check(initialStatement);
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ReturnsDeepStubs(org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs) Test(org.junit.Test)

Example 70 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method countIndexedNodes.

private static int countIndexedNodes(GraphDatabaseAPI db, Label label, String... keys) throws Exception {
    try (InternalTransaction tx = (InternalTransaction) db.beginTx()) {
        KernelTransaction ktx = tx.kernelTransaction();
        TokenRead tokenRead = ktx.tokenRead();
        int labelId = tokenRead.nodeLabel(label.name());
        int[] propertyKeyIds = new int[keys.length];
        for (int i = 0; i < propertyKeyIds.length; i++) {
            propertyKeyIds[i] = tokenRead.propertyKey(keys[i]);
        }
        PropertyIndexQuery[] predicates = new PropertyIndexQuery[propertyKeyIds.length];
        for (int i = 0; i < propertyKeyIds.length; i++) {
            predicates[i] = PropertyIndexQuery.exists(propertyKeyIds[i]);
        }
        IndexDescriptor index = single(ktx.schemaRead().index(SchemaDescriptor.forLabel(labelId, propertyKeyIds)));
        IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
        int count = 0;
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), predicates);
            while (cursor.next()) {
                count++;
            }
        }
        tx.commit();
        return count;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Aggregations

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5