use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j-apoc-procedures by neo4j-contrib.
the class SchemaIndex method getLuceneIndexReader.
private SimpleIndexReader getLuceneIndexReader(String label, String key) throws SchemaRuleNotFoundException, IndexNotFoundKernelException, DuplicateSchemaRuleException {
try (KernelStatement stmt = (KernelStatement) tx.acquireStatement()) {
ReadOperations reads = stmt.readOperations();
LabelSchemaDescriptor labelSchemaDescriptor = new LabelSchemaDescriptor(reads.labelGetForName(label), reads.propertyKeyGetForName(key));
IndexDescriptor descriptor = reads.indexGetForSchema(labelSchemaDescriptor);
IndexReader indexReader = stmt.getStoreStatement().getIndexReader(descriptor);
if (indexReader.getClass().getName().endsWith("FusionIndexReader")) {
try {
Field field = indexReader.getClass().getDeclaredField("luceneReader");
field.setAccessible(true);
return (SimpleIndexReader) field.get(indexReader);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException("Error accessing index reader", e);
}
}
return (SimpleIndexReader) indexReader;
}
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class Neo4jTransactionalContext method commitAndRestartTx.
@Override
public long commitAndRestartTx() {
/*
* This method is use by the Cypher runtime to cater for PERIODIC COMMIT, which allows a single query to
* periodically, after x number of rows, to commit a transaction and spawn a new one.
*
* To still keep track of the running stream after switching transactions, we need to open the new transaction
* before closing the old one. This way, a query will not disappear and appear when switching transactions.
*
* Since our transactions are thread bound, we must first unbind the old transaction from the thread before
* creating a new one. And then we need to do that thread switching again to close the old transaction.
*/
checkNotTerminated();
collectTransactionExecutionStatistic();
// (1) Remember old statement
QueryRegistry oldQueryRegistry = statement.queryRegistration();
Statement oldStatement = statement;
KernelTransaction oldKernelTx = transaction.kernelTransaction();
// (2) Create and register new transaction
kernelTransaction = transactionFactory.beginKernelTransaction(transactionType, securityContext, clientInfo);
statement = (KernelStatement) kernelTransaction.acquireStatement();
statement.queryRegistration().registerExecutingQuery(executingQuery);
transaction.setTransaction(kernelTransaction);
// (3) Commit and close old transaction (and unregister as a side effect of that)
oldQueryRegistry.unregisterExecutingQuery(executingQuery);
try {
oldStatement.close();
return oldKernelTx.commit();
} catch (Throwable t) {
// Corner case: The old transaction might have been terminated by the user. Now we also need to
// terminate the new transaction.
transaction.rollback();
throw new RuntimeException(t);
}
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class Neo4jTransactionalContextFactory method newContextForQuery.
@Override
public TransactionalContext newContextForQuery(InternalTransaction tx, ExecutingQuery executingQuery) {
KernelStatement initialStatement = (KernelStatement) tx.kernelTransaction().acquireStatement();
initialStatement.queryRegistration().startQueryExecution(executingQuery);
return contextCreator.create(tx, initialStatement, executingQuery);
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class Neo4jTransactionalContextFactory method newContext.
@Override
public final Neo4jTransactionalContext newContext(InternalTransaction tx, String queryText, MapValue queryParameters) {
KernelStatement initialStatement = (KernelStatement) tx.kernelTransaction().acquireStatement();
var executingQuery = initialStatement.queryRegistration().startQueryExecution(queryText, queryParameters);
return contextCreator.create(tx, initialStatement, executingQuery);
}
Aggregations