java - Using ExecutionEngine#execute(String) outside of a Transaction? -


I have just discovered 10 minutes to work against the testing database to test my unit to end the simple question Took about 25 seconds. The reason for this was that, obviously, I forgot to wrap a call in the execution eagin # execution (string) in transaction . I did not know that was supposed to be possible. Hmm

My code looked like this:

  ... @ before public zero () {db = New TestGraphDatabaseFactory () NewImpermanentDatabase (); / * Create all test nodes and after public zero after relay * () {db.shutdown (); } @Test Public Zero Testing All Titles () {/ * Create Cipher Query / Attributes & lt; Maps & lt; String, Object & gt; & Gt; Results = Engine. Exept (cipher); / * Inserts all the things ...  

The deceptive part here is that execute () comes back once and executes the following statements is done. But before successfully ending, test stalls for about 25 seconds.

Changing the statement without any intervals as expected:

  ... try (transaction transaction = db.beginTx ()) {intereabel & lt; Maps & lt; String, Object & gt; & Gt; Results = Engine. Exept (cipher); } ...  

What is actually happening here? Why is it possible to do this?

I suspect that you Iterator to execution result Back to ExecutionEngine # execute () . If you do this, the test will end in a transaction quickly without the need to wrap execute () .

Here is what I think is happening, although I have not republished it in Debugger.

ExecutionEngine # execute () creates its own transaction, so it should not be necessary to make it your own, although all transactions must be closed. In this case, the transaction state is documented in its own way by the execution result . If you partially use the result Ethernet , the transaction is left in an open state.

When you call GraphDatabaseService # shutdown () , wait for it to complete the open transaction and complete them before closing them. The stall that you see in your test is likely to end that time, of course, in this case it is not possible to stop during waiting for the transaction because it is organized by the same thread which is shutting down the database. is.

Because the transactions are connected to threads, in theory, for GraphDatabaseService , search the case and close the transaction without waiting for it, though it may be in the output code It is rare that one thread is executing the transaction and controlling the database, so additional complexity will not be suitable.

The easiest way to handle this is to always ensure that you return results by returning Iterators who are returned by ExecutionEngine .


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -