Search in sources :

Example 61 with InternalTransaction

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

the class ReadTracingIT method tracePageCacheAccessOnNodeCount.

@Test
void tracePageCacheAccessOnNodeCount() {
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var kernelTransaction = transaction.kernelTransaction();
        var cursorContext = kernelTransaction.cursorContext();
        var dataRead = kernelTransaction.dataRead();
        assertZeroCursor(cursorContext);
        assertEquals(0, dataRead.nodesGetCount());
        assertOneCursor(cursorContext);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 62 with InternalTransaction

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

the class EmbeddedInteraction method executeQuery.

@Override
public String executeQuery(EnterpriseSecurityContext subject, String call, Map<String, Object> params, Consumer<ResourceIterator<Map<String, Object>>> resultConsumer) {
    try (InternalTransaction tx = db.beginTransaction(KernelTransaction.Type.implicit, subject)) {
        Map<String, Object> p = (params == null) ? Collections.emptyMap() : params;
        resultConsumer.accept(db.execute(call, p));
        tx.success();
        return "";
    } catch (Exception e) {
        return e.getMessage();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 63 with InternalTransaction

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

the class ServerGroupsIT method getServerGroups.

private List<List<String>> getServerGroups(CoreGraphDatabase db) {
    List<List<String>> serverGroups = new ArrayList<>();
    try (InternalTransaction tx = db.beginTransaction(KernelTransaction.Type.explicit, EnterpriseSecurityContext.AUTH_DISABLED)) {
        try (Result result = db.execute(tx, "CALL dbms.cluster.overview", emptyMap())) {
            while (result.hasNext()) {
                @SuppressWarnings("unchecked") List<String> groups = (List<String>) result.next().get("groups");
                serverGroups.add(groups);
            }
        }
    }
    return serverGroups;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result)

Example 64 with InternalTransaction

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

the class TransactionStateMachineSPI method executeQuery.

@Override
public BoltResultHandle executeQuery(BoltQuerySource querySource, SecurityContext securityContext, String statement, Map<String, Object> params, ThrowingAction<KernelException> onFail) throws QueryExecutionKernelException {
    InternalTransaction internalTransaction = queryService.beginTransaction(implicit, securityContext);
    ClientConnectionInfo sourceDetails = new BoltConnectionInfo(querySource.principalName, querySource.clientName, querySource.connectionDescriptor.clientAddress, querySource.connectionDescriptor.serverAddress);
    TransactionalContext transactionalContext = contextFactory.newContext(sourceDetails, internalTransaction, statement, params);
    return new BoltResultHandle() {

        @Override
        public BoltResult start() throws KernelException {
            try {
                Result run = queryExecutionEngine.executeQuery(statement, params, transactionalContext);
                return new CypherAdapterStream(run, clock);
            } catch (KernelException e) {
                onFail.apply();
                throw new QueryExecutionKernelException(e);
            } catch (Throwable e) {
                onFail.apply();
                throw e;
            }
        }

        @Override
        public void terminate() {
            transactionalContext.terminate();
        }
    };
}
Also used : ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) BoltConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.BoltConnectionInfo) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) BoltResultHandle(org.neo4j.bolt.v1.runtime.TransactionStateMachine.BoltResultHandle) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) BoltResult(org.neo4j.bolt.v1.runtime.spi.BoltResult) Result(org.neo4j.graphdb.Result)

Example 65 with InternalTransaction

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

the class ThreadedTransaction method doExecute.

private String[] doExecute(ThreadingRule threading, S subject, KernelTransaction.Type txType, boolean startEarly, String... queries) {
    NamedFunction<S, Throwable> startTransaction = new NamedFunction<S, Throwable>("threaded-transaction-" + Arrays.hashCode(queries)) {

        @Override
        public Throwable apply(S subject) {
            try (InternalTransaction tx = neo.beginLocalTransactionAsUser(subject, txType)) {
                Result result = null;
                try {
                    if (startEarly) {
                        latch.start();
                    }
                    for (String query : queries) {
                        if (result != null) {
                            result.close();
                        }
                        result = neo.getLocalGraph().execute(query);
                    }
                    if (!startEarly) {
                        latch.startAndWaitForAllToStart();
                    }
                } finally {
                    if (!startEarly) {
                        latch.start();
                    }
                    latch.finishAndWaitForAllToFinish();
                }
                result.close();
                tx.success();
                return null;
            } catch (Throwable t) {
                return t;
            }
        }
    };
    done = threading.execute(startTransaction, subject);
    return queries;
}
Also used : NamedFunction(org.neo4j.test.NamedFunction) Matchers.containsString(org.hamcrest.Matchers.containsString) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result)

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