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);
}
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("/");
}
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);
}
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);
}
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;
}
}
Aggregations