private CypherResult doExecuteQuery(String query, boolean canProfile) { long time = System.currentTimeMillis(); Transaction tx = gdb.beginTx(); javax.transaction.Transaction resumeTx; try { resumeTx = suspendTx(query); ExecutionResult result = canProfile ? executionEngine.profile(query) : executionEngine.execute(query); final Collection<Map<String, Object>> data = IteratorUtil.asCollection(result); time = System.currentTimeMillis() - time; resumeTransaction(resumeTx); CypherResult cypherResult = new CypherResult( result.columns(), data, result.getQueryStatistics(), time, canProfile ? result.executionPlanDescription() : null, prettify(query)); tx.success(); return cypherResult; } finally { tx.close(); } }
private javax.transaction.Transaction suspendTx(String query) { if (!executionEngine.isPeriodicCommitQuery(query)) return null; try { return transactionManager.suspend(); } catch (SystemException e) { throw new RuntimeException("Error suspending Transaction", e); } }
@Override protected ExecutionResult getResult(String query, Map<String, Object> parameters) throws ShellException, RemoteException, SystemException { GraphDatabaseAPI graphDatabaseAPI = getServer().getDb(); ServerExecutionEngine engine = getEngine(); if (engine.isPeriodicCommitQuery(query)) { TransactionManager manager = graphDatabaseAPI.getDependencyResolver().resolveDependency(TransactionManager.class); Transaction tx = manager.suspend(); try { return super.getResult(query, parameters); } finally { manager.resume(tx); } } else { return super.getResult(query, parameters); } }
@Override protected ExtendedExecutionResult getResult(String query, Map<String, Object> parameters) throws ShellException, RemoteException { GraphDatabaseAPI graphDatabaseAPI = getServer().getDb(); ServerExecutionEngine engine = getEngine(); if (engine.isPeriodicCommit(query)) { ThreadToStatementContextBridge manager = graphDatabaseAPI .getDependencyResolver() .resolveDependency(ThreadToStatementContextBridge.class); TopLevelTransaction tx = manager.getTopLevelTransactionBoundToThisThread(true); manager.unbindTransactionFromCurrentThread(); try { return super.getResult(query, parameters); } finally { manager.bindTransactionToCurrentThread(tx); } } else { return super.getResult(query, parameters); } }
public String prettify(String query) { return executionEngine.prettify(query).replaceAll("\n", "\n "); }