Skip to content

Commit 1529eb2

Browse files
committed
Formalize contract for run
1 parent c71f92e commit 1529eb2

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

driver/src/main/java/org/neo4j/driver/internal/InternalResultCursor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ public RecordAccessor peek()
203203
return new PeekingRecordAccessor();
204204
}
205205

206-
public List<Record> recordsAsList()
206+
@Override
207+
public List<Record> list()
207208
{
208209
return list( recordAsIs() );
209210
}

driver/src/main/java/org/neo4j/driver/v1/StatementRunner.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ public interface StatementRunner
3636
* dangerous cypher injection attacks and improves database performance as
3737
* Neo4j can re-use query plans more often.
3838
*
39+
* <h2>Important notes about guarantees</h2>
40+
* When you invoke this method, there are no guarantees that your statement will be
41+
* immediately ran. This allows highly efficient execution when you run multiple
42+
* statements in a row.
43+
*
44+
* There are two ways to ensure a statement has been ran:
45+
*
46+
* <h3>Observe the result</h3>
47+
*
48+
* Once you start reading the result, the statement must execute. If you do not care about
49+
* the contents of the result and only want to ensure it is ran, you may simply
50+
* {@link ResultCursor#close() close} it.
51+
*
52+
* <h3>Observe the result of a later statement</h3>
53+
*
54+
* Every statement you run is logically ordered to happen after every statement you've ran
55+
* before it. This means that if you read the result of one statement, every statement
56+
* ran before is forced to execute.
57+
*
58+
* Thus, both statements are guaranteed to have executed successfully if this code
59+
* exits without error, because we close the result of the second statement.
60+
*
61+
* <pre class="doctest:StatementRunnerDocIT#orderedObserveResult">
62+
* {@code
63+
* session.run( "CREATE (:FirstNode)" );
64+
* session.run( "CREATE (:SecondNode)" ).close();
65+
* }
66+
* </pre>
67+
*
68+
* <h3>Closing resources</h3>
69+
*
70+
* Finally, all statements ran in a {@link StatementRunner} are guaranteed to have executed
71+
* when you close a {@link Transaction} associated with the {@link StatementRunner}, likewise
72+
* when you close the {@link Session} or the {@link Driver}.
73+
*
3974
* <h2>Example</h2>
4075
* <pre class="doctest:StatementRunnerDocIT#parameterTest">
4176
* {@code

driver/src/test/java/org/neo4j/driver/v1/StatementRunnerDocIT.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static org.hamcrest.CoreMatchers.notNullValue;
2929
import static org.hamcrest.MatcherAssert.assertThat;
30+
import static org.junit.Assert.assertTrue;
3031

3132
@RunWith( DocTestRunner.class )
3233
public class StatementRunnerDocIT
@@ -46,6 +47,20 @@ public void parameterTest( DocSnippet snippet )
4647
assertThat( snippet.get( "cursor" ), notNullValue() );
4748
}
4849

50+
public void orderedObserveResult( DocSnippet snippet )
51+
{
52+
// given
53+
snippet.set( "session", session );
54+
55+
// when
56+
snippet.run();
57+
58+
// then
59+
assertTrue( session.run( "OPTIONAL MATCH (a:FirstNode)" +
60+
"OPTIONAL MATCH (b:SecondNode)" +
61+
"RETURN a is not null and b is not null" ).peek().get( 0 ).isTrue() );
62+
}
63+
4964
public void statementObjectTest( DocSnippet snippet )
5065
{
5166
// given
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.neo4j.driver.v1;
2+
3+
import org.junit.Test;
4+
5+
public class TypePlayTest
6+
{
7+
@Test
8+
public void asd() throws Throwable
9+
{
10+
Driver driver = GraphDatabase.driver( ".." );
11+
12+
Session session = driver.session();
13+
14+
session.run( "CREATE (n)" ).close();
15+
16+
}
17+
18+
static class StaticTypeSystem
19+
{
20+
public static Type FLOAT() {
21+
return null;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)